Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Save XLSX file to a specified location using OpenPyXL

I'm having an issue saving my file to a certain location on my Raspberry PI (Raspbian) computer. I'm wanting the XLSX file to be saved directly to my desktop rather than the folder holding the Python Script. When I do wb.save("FileName.xlsx"), It only saves it to the location where the Python Script is located.

Here's my code:

from openpyxl import Workbook
wb = Workbook()
ws1 = wb.active
ws1.title = "1st Hour"
wb.save('FileName.xlsx')
like image 804
Dylan Avatar asked Mar 01 '16 14:03

Dylan


1 Answers

Okay for any user, you can write

from openpyxl import Workbook
import getpass
wb = Workbook()
ws1 = wb.active
ws1.title = "1st Hour"
wb.save('/home/'+getpass.getuser()+'/Desktop/FileName.xlsx')
like image 52
Jens Munk Avatar answered Sep 30 '22 10:09

Jens Munk