if not os.path.isdir("DirectoryName"):
os.makedirs("DirectoryName")
if not os.path.isfile('FileName.xlsx'):
wb = openpyxl.Workbook()
dest_filename = 'FileName.xlsx'
I have the following problem: I want to create a directory in the same directory where I have python files and to create the FileName.xlsx in the directory: DirectoryName and I haven't found out how to do that yet.¿Could you help me?
Thanks
Documentation says you can wb.save(os.path.join('DirectoryName', 'FileName.xlsx'), as_template=False)
. With dest_filename = 'FileName.xlsx'
you just assign value to variable. So try:
if not os.path.isdir("DirectoryName"):
os.makedirs("DirectoryName")
if not os.path.isfile('FileName.xlsx'):
wb = openpyxl.Workbook()
dest_filename = 'FileName.xlsx'
wb.save(os.path.join('DirectoryName', dest_filename), as_template=False)
Note that directory where you file is may not be same as you current directory related to which your path is.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With