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

**URL:** <https://forum.inductiveautomation.com/t/my-export-to-excel-button-creates-file-without-the-correct-file/57093>\
**Category:** Ignition\
**Tags:** ignition79, scripting, vision\
**Created:** [March 11, 2022, 3:23am UTC](https://forum.inductiveautomation.com/t/my-export-to-excel-button-creates-file-without-the-correct-file/57093 "2022-03-11T03:23:48Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![Cole\_Barthel](https://avatars.discourse-cdn.com/v4/letter/c/919ad9/32.png) [@Cole\_Barthel](https://forum.inductiveautomation.com/u/Cole_Barthel)\
**Post date:** [March 11, 2022, 3:23am UTC](https://forum.inductiveautomation.com/t/my-export-to-excel-button-creates-file-without-the-correct-file/57093/1 "2022-03-11T03:23:48Z")

</div>

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.

 ![exportexcelscript](https://us1.discourse-cdn.com/inductiveautomation/original/3X/8/e/8e75c7b385426c01f675479cbf50b33740fd162e.png)

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

 ![exporterror](https://us1.discourse-cdn.com/inductiveautomation/original/3X/e/0/e06aa8eb47446012db79e80efcc073bf17fdfbd7.png)

This is what excel tells me.

 ![excelerror](https://us1.discourse-cdn.com/inductiveautomation/original/3X/4/e/4e8c270e62cf6de56a7b8a1f66ef68d5fe93858b.png)

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

---

<div class="post-metadata">

**Author:** ![JordanCClark](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jordancclark/32/83362_2.png) [@JordanCClark](https://forum.inductiveautomation.com/u/JordanCClark)\
**Post date:** [March 11, 2022, 12:04pm UTC](https://forum.inductiveautomation.com/t/my-export-to-excel-button-creates-file-without-the-correct-file/57093/2 "2022-03-11T12:04:59Z")

</div>

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.

> [@Cole\_Barthel](#):
>
> How do I set up the script so I can send multiple datasets?

Did you look at [dataSetToExcel()](https://docs.inductiveautomation.com/display/DOC79/system.dataset.dataSetToExcel)?

---

<div class="post-metadata">

**Author:** ![Matrix\_Engineering](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/matrix_engineering/32/19781_2.png) [@Matrix\_Engineering](https://forum.inductiveautomation.com/u/Matrix_Engineering)\
**Post date:** [March 11, 2022, 7:55pm UTC](https://forum.inductiveautomation.com/t/my-export-to-excel-button-creates-file-without-the-correct-file/57093/3 "2022-03-11T19:55:53Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Cole\_Barthel](https://avatars.discourse-cdn.com/v4/letter/c/919ad9/32.png) [@Cole\_Barthel](https://forum.inductiveautomation.com/u/Cole_Barthel)\
**Post date:** [March 13, 2022, 8:53pm UTC](https://forum.inductiveautomation.com/t/my-export-to-excel-button-creates-file-without-the-correct-file/57093/4 "2022-03-13T20:53:39Z")

</div>

> [@JordanCClark](#):
>
> What happens if you try to open it anyway?

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

 ![openanywayserror](https://us1.discourse-cdn.com/inductiveautomation/original/3X/1/b/1b2b27f4d8f8a83133fd039f1aa7f8e468985083.png)

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](https://docs.inductiveautomation.com/display/DOC79/system.dataset.exportExcel#:~:text=start%20of%20banner-,system.dataset.exportExcel,-Skip%20to%20end)

---

<div class="post-metadata">

**Author:** ![Cole\_Barthel](https://avatars.discourse-cdn.com/v4/letter/c/919ad9/32.png) [@Cole\_Barthel](https://forum.inductiveautomation.com/u/Cole_Barthel)\
**Post date:** [March 13, 2022, 8:55pm UTC](https://forum.inductiveautomation.com/t/my-export-to-excel-button-creates-file-without-the-correct-file/57093/5 "2022-03-13T20:55:26Z")

</div>

> [@JordanCClark](#):
>
> Did you look at [dataSetToExcel()](https://docs.inductiveautomation.com/display/DOC79/system.dataset.dataSetToExcel)?

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

 ![datasettoexceltry](https://us1.discourse-cdn.com/inductiveautomation/original/3X/e/0/e0863b66e41abff051d7a5ed1bcd000d61769b07.png)

 ![datasettoexcelerror1](https://us1.discourse-cdn.com/inductiveautomation/original/3X/3/2/3225c141a8070f47405279a8ade5262986725039.png)

---

<div class="post-metadata">

**Author:** ![Cole\_Barthel](https://avatars.discourse-cdn.com/v4/letter/c/919ad9/32.png) [@Cole\_Barthel](https://forum.inductiveautomation.com/u/Cole_Barthel)\
**Post date:** [March 13, 2022, 8:57pm UTC](https://forum.inductiveautomation.com/t/my-export-to-excel-button-creates-file-without-the-correct-file/57093/6 "2022-03-13T20:57:52Z")

</div>

> [@Matrix\_Engineering](#):
>
> Yes look at the example, you don’t have the file extension and you are sending _table_ where it should be _table.data_

Is this what you mean?

 ![eportexcelscript](https://us1.discourse-cdn.com/inductiveautomation/original/3X/c/0/c0a786c033b65a4467f9a6702df1b94121e3e95a.png)

 ![eportexcelerror](https://us1.discourse-cdn.com/inductiveautomation/original/3X/2/b/2bd6110e6c5c93952a3c2f246399477e87035bf7.png)

---

<div class="post-metadata">

**Author:** ![JordanCClark](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jordancclark/32/83362_2.png) [@JordanCClark](https://forum.inductiveautomation.com/u/JordanCClark)\
**Post date:** [March 13, 2022, 9:48pm UTC](https://forum.inductiveautomation.com/t/my-export-to-excel-button-creates-file-without-the-correct-file/57093/7 "2022-03-13T21:48:29Z")

</div>

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](https://us1.discourse-cdn.com/inductiveautomation/original/3X/6/4/64dcab5cafd64449de084f539d8e473bed52780b.png)

Your script will then become something like:

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

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

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

```

---

<div class="post-metadata">

**Author:** ![Cole\_Barthel](https://avatars.discourse-cdn.com/v4/letter/c/919ad9/32.png) [@Cole\_Barthel](https://forum.inductiveautomation.com/u/Cole_Barthel)\
**Post date:** [March 13, 2022, 10:53pm UTC](https://forum.inductiveautomation.com/t/my-export-to-excel-button-creates-file-without-the-correct-file/57093/8 "2022-03-13T22:53:28Z")

</div>

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?

 ![datasettoexcelscript](https://us1.discourse-cdn.com/inductiveautomation/original/3X/7/9/79079582a6ca1bdc5f87a311f73987709196abf8.png)

Or would I edit this working script for 1 dataset.

 ![exportexcelfinal](https://us1.discourse-cdn.com/inductiveautomation/original/3X/9/1/91a3f6b5c76e8d7af31cb09db5128e6bbc680c27.png)

---

<div class="post-metadata">

**Author:** ![JordanCClark](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jordancclark/32/83362_2.png) [@JordanCClark](https://forum.inductiveautomation.com/u/JordanCClark)\
**Post date:** [March 14, 2022, 1:36pm UTC](https://forum.inductiveautomation.com/t/my-export-to-excel-button-creates-file-without-the-correct-file/57093/9 "2022-03-14T13:36:20Z")

</div>

You will need to use dataSetToExcel(). Example:

```python
# 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)

```

---

<div class="post-metadata">

**Author:** ![Cole\_Barthel](https://avatars.discourse-cdn.com/v4/letter/c/919ad9/32.png) [@Cole\_Barthel](https://forum.inductiveautomation.com/u/Cole_Barthel)\
**Post date:** [March 14, 2022, 8:45pm UTC](https://forum.inductiveautomation.com/t/my-export-to-excel-button-creates-file-without-the-correct-file/57093/10 "2022-03-14T20:45:13Z")

</div>

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