How can I save Excel file to local certain folder

def runAction(self, event):
	data = self.getSibling("Table").props.data
	#data = self.parent.parent.parent.parent.getChild("tab recipe").custom.raw
	current_date = system.date.now()
	# Get the date of the previous month
	previous_month_date = system.date.addMonths(current_date, -1)
	time = system.date.format(previous_month_date, 'yyyy_MMMM')
	filename = 'Alarm_Journal_Historical_' + time + '.xlsx'
	
	spreadsheet = system.dataset.toExcel(True, [data], True)
	system.perspective.download(filename, spreadsheet)
	system.perspective.closePopup("")

For this script the export Excel will download in the default Download folder.
How can I change the path to another local computer folder, like : (Desktop/New folder)

It's not clear what you're asking. Is this script not working the way you expect it to?

You say 'CSV' but you are calling system.dataset.toExcel and specifying .xlsx as the extension. At the risk of sounding painfully obvious, if you want an actual CSV then you'll need system.dataset.toCSV.

1 Like

Sorry ,I revise my title.
I want to ask how can I export the file to certain path
(ex: C:\Users\Desktop\Alarmlog )

Do you want the file to be downloaded to a specific hardcoded directory, or somewhere that is selected by the user?

system.perspective.download can open a prompt for the user to select download location, provided your browser is set up that way.

3 Likes

I look forward to have a save option like this picture
savepic
I can choose the specific path to save my file
I'm not sure how I can use the system.file.writeFile(file_path, spreadsheet) to do it
Or anything else method to do

Did you read my last post and/or link?

2 Likes

Yes, I read it and it can work by setting the download location on the browser.
But I have too much file for download ,it will cause a little mess in folder.
So I want to find the method how to save different file to different folder

For security reasons the browser can save files in one of two ways:

  1. When the download link is clicked save in a location specified by the browser setup options.
  2. Open the save dialog (as specified in the browser setup options) as shown in your screen grab.

A website can't specify that a file be saved in, for example, C:\Users\Desktop\Alarmlog. For a start that's Windows-only syntax and the folders might not exist.

So I can't create a folder and set the certain path in my script to save my file right?
The only way to download is setting the browser download option like this?

Correct. It's controlled by the browser, and not by Ignition.

1 Like

Thank you for helping

Just so you understand why: You are asking for behavior that can easily be exploited by malware. It is simply not safe for browsers to allow websites to specify a target folder.

1 Like