How to Create a Folder and Excel File Using Python

Here is Simple Demonstration of the python code for creating the folder and Excel file .

Please Import the Neccessary Library mentioned in the code . Else Code might Not Work

# Import the Library required for the Program
import os
import datetime
#Importing the Workbook from the Openpyxl to Work with the Excel Workbook
from openpyxl import Workbook

#Function to create a Folder & Excel file with today's date.
def DT_File_create(src_path):
    time = datetime.datetime.now()
    time = time.strftime("__%m_%d_%Y")
    des_path = os.path.join(src_path, time)
    os.mkdir(des_path)
    wb = Workbook()
    ws = wb.active
    ws.title = "titlename"
    wb.save(filename=des_path + "/" + time + ".xlsx", )

#Calling the function 
DT_File_create("Filepath")

Leave a Reply

Your email address will not be published. Required fields are marked *