Home > Software engineering >  Creating a folder and add Excelsheets in Python
Creating a folder and add Excelsheets in Python

Time:03-27

I'm learning Python and I want to create a folder where I can store my Excel sheets.

with create_dir() I'm creating a folder

def create_dir(directory):
    if not os.path.exists(directory):
        os.makedirs(directory)

with create_file() I'm creating a Excel File

def create_file():
    data = xlsxwriter.Workbook('data.xlsx')

    if not os.path.isfile(data):
        worksheet1 = data.add_worksheet("Worksheet")
        data.close()

But how can I store this Excel file in my directory and not on the current path?

Right now I can create a folder and Excel Sheet separately. But I want to create the Excel Sheet in my folder.

CodePudding user response:

Basically when you create your Workbook with your filename, your filename could be under some folder.

workbook  = xlsxwriter.Workbook(r"folder_name/filename.xlsx")
  • Related