My export to excel button creates file, without the correct file?

I am trying to export multiple datasets from a window of graphs and tables, but for starting out I am just trying for one. I have an export to excel button with actionPerformed script uploaded below. It creates an excel file but I get a sort of Null error popup, also uploaded. How do I get it to actually export the dataset?

This is the script behind the export to excel button.

This is the error popup that appears after clicked the export button.

This is what excel tells me.

Secondary question: How do I set up the script so I can send multiple datasets?

What happens if you try to open it anyway? The v7 excel functions create an xml file that can be read into a worksheet, just tagging on an .xls extension to help ensure excel opens it.

Did you look at dataSetToExcel()?

Yes look at the example, you don’t have the file extension and you are sending table where it should be table.data

This pops up after the excel file format doesn’t match error. After that is just a blank excel sheet.

This is the example I saw the most action with.
https://docs.inductiveautomation.com/display/DOC79/system.dataset.exportExcel#:~:text=start%20of%20banner-,system.dataset.exportExcel,-Skip%20to%20end

I tried this and this is what I got. Did I do it wrong?

Is this what you mean?

You can browse to the table data directly using the property browser. To the right of the script editor there is a ‘chain link’ button that opens it.

image

Your script will then become something like:

tableData = event.source.parent.parent.alarmsByCount.data 

filePath = system.dataset.exportExcel('spiral # analysis', tableData)

if filePath != None:
	system.net.openURL('file://' + filePath)

This worked! Thanks for helping me learn a little more today.
Now I just need to figure out how to do the same but with multiple datasets. If I’m not mistaken I have to use the dataset to excel function and not the export to excel function?

How would I edit this dataset to excel script?

Or would I edit this working script for 1 dataset.

You will need to use dataSetToExcel(). Example:

# Set save path
filePath = system.file.saveFile("myfile.xls")
# Process if filePath is OK'd 
if filePath is not None:
	# Set component locations. You can't just browse to the component itself,
	# so my workaround is to select the name property, 
	# then delete the .name part afterward.
	table1 = event.source.parent.parent.alarmsByCount 
	table2 = event.source.parent.parent.alarmsByDuration

	# Create spreadsheet. Note use of data property. One tab per dataset.
	spreadsheet = system.dataset.dataSetToExcel(1, [table1.data, table2.data])
	system.file.writeFile(filePath, spreadsheet)

This worked beautifully! Thank you so much!

I just had to use ‘table1, table2’ instead of ‘table1.data, table2.data’. The error that popped up said it couldn’t find the attribute “data”.

1 Like