Reputation: 11
I am trying to save an Excel workbook I created using openpyxl to a specific directory that the user inputs via a Tkinter "browse" button. I have the workbook saving at the inputted "save spot," butI am getting an error saying that it is a directory.
Within the function that is producing the workbook, I have:
wb.save(save_spot)
The "save spot" is generated via a function:
def set_save_destination():
global save_spot
save_spot = filedialog.askdirectory()
save_spot = str(save_spot)
The user gets to select the directory by the following Tkinter GUI code, within my GUI class:
monthly_browse = ttk.Button(self, text='Select Save Destination', command=set_save_destination)
The error message that I receive is an "IsADirectoryError" but I am unsure what the issue is, as is says that you can directly enter the directory into the save method. I am new to programming and completely self-taught, so any help would be great! Thank you!
Upvotes: 0
Views: 9043
Reputation: 132
you need to provide full path to the desired folder please see example below
from openpyxl import Workbook
wb = Workbook()
ws1 = wb.active
ws1.title = "1st Hour"
wb.save('/home/user/Desktop/FileName.xlsx')
so you might add additionally filename to the save_spot variable
save_spot = str(save_spot)+'/filename.xlsx'
Upvotes: 6