Contents
Strategic Partner Links
Sepasoft - MES Modules
Cirrus Link - MQTT Modules
Resources
Knowledge Base Articles
Inductive University
Forum
IA Support
SDK Documentation
SDK Examples
Exports the contents of a dataset as a CSV file, prompting the user to save the file to disk.
This scripting function has no Client Permission restrictions.
system.dataset.exportCSV(filename, showHeaders, dataset)
String filename - A suggested filename to save as.
boolean showHeaders - If true (1), the CSV file will include a header row.
Dataset dataset - The dataset to export.
String - The path to the saved file, or None if the action was canceled by the user.
Client
#This snippet would prompt the user to save the data currently displayed in a Table component to a CSV file, and would open the file (in an external program, presumably Excel) after a successful save. table = event.source.parent.getComponent("Table") filePath = system.dataset.exportCSV("data.csv", 1, table.data) if filePath != None: system.net.openURL("file:///"+filePath.replace('\\','/'))
To write silently to a file, you cannot use the dataset.export* functions. Instead, use the toCSV() function as below:
### This script DOES NOT USE the system.dataset.exportCSV() function ### # take data and silently write it in CSV format to a file # this script would be on a button with a from a table in the same container # get data data = event.source.parent.getComponent('Table').data # convert to csv CSVdata = system.dataset.toCSV(data) # write file system.file.writeFile("C:\\temp\\data.csv", CSVdata)
2 Comments
Anonymous
Is there a way to enter the File Path and bypass the user prompt?
Robert McKenzie
Yes, but to do that you would need to use the system.file.writeFile() function instead of exportCSV().