Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Changing file location
#1
How do I amend the following code so that "filename.xlsx" is created in say "D:\SomeFolder\" and not in the default project folder.

import xlsxwriter
workbook  = xlsxwriter.Workbook('filename.xlsx')
worksheet = workbook.add_worksheet()
worksheet.write(0, 0, 'Salaams')
workbook.close()
Reply
#2
Change 'filename.xlsx' to 'D:/SomeFolder/filename.xlsx'
Reply
#3
OK, that worked. Just a knock-on question. What if I want to save the file in the root D drive? I tried D:/filename.xlsx which gave an error?
Reply
#4
(Sep-27-2022, 09:49 PM)azizrasul Wrote: OK, that worked. Just a knock-on question. What if I want to save the file in the root D drive? I tried D:/filename.xlsx which gave an error?

What was the error?
Reply
#5
"D:\Power BI & Python\venv\Scripts\python.exe" "D:/Power BI & Python/Test.py" 
Traceback (most recent call last):
  File "D:\Power BI & Python\venv\lib\site-packages\xlsxwriter\workbook.py", line 324, in close
    self._store_workbook()
  File "D:\Power BI & Python\venv\lib\site-packages\xlsxwriter\workbook.py", line 659, in _store_workbook
    raise e
  File "D:\Power BI & Python\venv\lib\site-packages\xlsxwriter\workbook.py", line 656, in _store_workbook
    xlsx_file = ZipFile(self.filename, "w", compression=ZIP_DEFLATED,
  File "C:\Users\Aziz\AppData\Local\Programs\Python\Python310\lib\zipfile.py", line 1249, in __init__
    self.fp = io.open(file, filemode)
PermissionError: [Errno 13] Permission denied: 'D:/filename.xlsx'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "D:\Power BI & Python\Test.py", line 5, in <module>
    workbook.close()
  File "D:\Power BI & Python\venv\lib\site-packages\xlsxwriter\workbook.py", line 326, in close
    raise FileCreateError(e)
xlsxwriter.exceptions.FileCreateError: [Errno 13] Permission denied: 'D:/filename.xlsx'

Process finished with exit code 1
Reply
#6
You're getting a permission denied. Looks like you don't have permission to save files directly into D:. But that's outside the scope of your program. You might have to look at filesystem permissions or ACLs. Can you save a file from notepad there either?
Reply
#7
I tried to copy a text file and it came up with a dialog box with 3 buttons i.e. Continue, Skip and Cancel. The title of the dialog box was Destination Folder Accessed Denied. When I press Skip it copies the file over no problem. Similar thing happens when I then try to delete the file.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Changing the initial worksheet name in an MS Excel file azizrasul 3 948 Oct-02-2022, 07:56 PM
Last Post: azizrasul
Thumbs Up Parsing a YAML file without changing the string content..?, Flask - solved. SpongeB0B 2 2,268 Aug-05-2021, 08:02 AM
Last Post: SpongeB0B
  find the header location in a .bin file without reading the whole file at a time SANJIB 0 2,209 Mar-05-2021, 04:08 PM
Last Post: SANJIB
  Cannot copy file to another location rcmanu95 1 1,729 Jul-19-2020, 05:16 AM
Last Post: deanhystad
  Saving a file to a specific location finndude 13 5,975 Apr-23-2020, 03:07 PM
Last Post: finndude
  help with changing values in an excel sheet and saving to a new file Moneyman212 2 2,904 Nov-19-2019, 06:25 AM
Last Post: Moneyman212
  File system navigation. Changing directory GregoireLeGros 3 3,242 Mar-20-2018, 06:33 PM
Last Post: GregoireLeGros
  I cant find the location of my csv file Ummusabbar 3 4,646 Jan-04-2018, 05:18 PM
Last Post: buran

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020