How can I use the webdev module to export an excel or csv to the perspective client?
Its a common scenario. I have a perspective client with a button on it. There is a DB back end to the Ignition server. The customer wants to click a button and download an excel or csv file.
Does anybody have any examples?
As I understand. the system.perspective.download will download the file to the Ignition server and not the actual perspective client.
Give a try, your browser will prompt you to download a file.
1 Like
For what its worth this is what I did to extract the data from the database and return it as a csv file from the perspective client.
First, from a button I do a navigation to the following url
gatewayAddress:port/system/webdev/project/data/data?StartDate=2020-02-01 00:00:00&EndDate=2020-02-01 00:00:00
Using the webdev module:
#/system/webdev/IRCTS/Data/Data
L = system.util.getLogger("Webdev: Data/Data")
L.info("start")
startDate = request['params']['StartDate']
endDate = request['params']['EndDate']
params = {"startTime":startDate, "endTime":endDate}
dataSet = system.db.runNamedQuery('Project', 'ReportPath', params)
csv = system.dataset.toCSV(dataSet)
filePath = r"C:\Users\Public\Documents\Ignition\data.csv"
system.file.writeFile(filePath, csv)
bytes = system.file.readFileAsBytes(filePath)
L.info("end")
return {'bytes': bytes}
Once I press the button in the perspective client the browser ask where I want to download the csv file.