Perspective table help exporting to excel

How do I use button to export this data to excel?

I didn’t understand the details of the what the help page says perhaps.
I tried to mimic it.
https://docs.inductiveautomation.com/display/DOC81/Exporting+and+Importing+a+CSV
https://docs.inductiveautomation.com/display/DOC81/system.dataset.exportCSV

It said event.source so I thought I better.
Mine said .props.data so I thought mine should.

component= event.source.parent.getChild("StopsData").getChild("Table")
csv = system.dataset.toCSV(component.props.data)
system.file.saveFile("myExport.csv", "csv", "Comma Separated Values")
if filePath:
  system.file.writeFile(filePath, csv)	

This export is not working.


Then I also want to know where I would put the CSS code to change the color of some of data.
I saw a few posts on this, but I think I am again missing some details of how to do the change.

Where do I put code to change the color of a cell?

Where do I put code to eliminate the bottom horizontal scroll bar from showing up?

component= event.source.parent.getChild("StopsData").getChild("Table")
csv = system.dataset.toCSV(component.props.data)
system.file.saveFile("myExport.csv", "csv", "Comma Separated Values")
if filePath:
  system.file.writeFile(filePath, csv)

system.file.saveFile is not available in a Perspective session.

Use system.perspective.download: system.perspective.download - Ignition User Manual 8.1 - Ignition Documentation

So your new script would look like this:

component= event.source.parent.getChild("StopsData").getChild("Table")
csv = system.dataset.toCSV(component.props.data)
system.perspective.download("myExport.csv",csv)

To change the color of a cell specifically you need to add a transform on the data so that on the column that you want to change the cell color on is a dict object with a value and a style: Color perspective table cell depending on value in another column - #2 by ynejati
or
Cell Color in Perspective Table

Doing this will probably impact your first question though.

What I do for almost 100% of all tables is have a custom property on the view that is a dataset/json that holds the data that I want. Then on the table I do a transform. That way if I need to export the data out I have an un-spoiled copy of the data that I can do something with.

1 Like

@zacharyw.larson just for future, the manual states the scope for each function.

Example, system.file.saveFile - Ignition User Manual 8.0 - Ignition Documentation,
shows vision client only.

1 Like
component= self.parent.getChild("StopsData").getChild("Table").props.data
csv = system.dataset.toCSV(component)
system.perspective.download("myExport.csv",csv)

Downloads the file to the downloads folder.

today = system.date.now()
fileSuffix=system.date.format(today, "yyyyMMddHHmm")
component= self.parent.getChild("StopsData").getChild("Table").props.data
csv = system.dataset.toCSV(component)
system.perspective.download("Stops"+fileSuffix+".csv",csv)

I got fancy and set the date of the save into the file name accurate to the minute.
I might later append the dropdown of which machines to the file prefix of the file’s name.
Thanks again for the help.

How do I have this open a dialogue box to set the location to save the file?
Or is downloading to the downloads more acceptable?

Yep it will download the file to the default directory for the browser downloads. I don’t know of a way to popup a dialog box to allow the end user to select the save to location.

You have to tell your your browser to ask every time. Perspective has no control once the download is handed off to the browser.

2 Likes