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?

1 Like
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.

4 Likes

@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.

1 Like

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

3 Likes

How do I get it to ask for file location?

You tell your browser to ask. Most browsers default to your Downloads folder. You have to tell the browser not to do that. Perspective can't do that for your users.

Not to be ignorant but vision was my bread and butter up to 4 months ago and I had it working there but in Perspective I have no idea where to disable this so it asks.

In your browser's "Options" or "Preferences" or "Settings" menu. Just like you do for downloads from any other website.

It will help you adjust to Perspective if you treat your client's machine as entirely off-limits. Your users just have a view into your operation through their browser.

1 Like

I thought you were talking about something in Perspective. Thanks Phil

Off limits, see?

I did find however that script may be used to alter the download folder for Chrome.

Are you going to share how?
Can we request a folder creation?

Is it related to this:

Sign in - Google Accounts

and

"If anyone is still having trouble and the above solutions didn't work, I found adding a following slash ('') to my download path.

Mine looked like this:"

 if browser == 'chrome':
        options = webdriver.ChromeOptions()
        options.add_argument("--start-maximized")
        prefs = {"profile.default_content_settings.popups": 0,
                 "download.default_directory": r"C:\Users\user_dir\Desktop\\", # IMPORTANT - ENDING SLASH V IMPORTANT
                 "directory_upgrade": True}
        options.add_experimental_option("prefs", prefs)
        return webdriver.Chrome(executable_path=Base.chromedriver_dir, chrome_options=options)

from

Selenium Webdriver in Python - files download directory change in Chrome preferences - Stack Overflow

Or are those webdrivers not compatible with Ignition?

Not for stock Chrome. The user needs to install something that permits this kind of security bypass.

1 Like

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

Thanks 'bschroeder' this worked just fine for me minus the change to table data location.

1 Like

Howdy. Was using this thread for a few things, but just FYI, if you use Perspective Workstation instead of an OS browser, it will automatically prompt the user to choose a save location. That method helps so users don't need to modify their browser settings to make it ask for a file location.

1 Like

Unfortunately there are permission issues and whether or not the user has admin rights to allow Ignition to access folder on that persons computer. Using what I did takes all that out of the picture, but you may be doing something else.