# Table Excel export with button in Ignition Perspective

**URL:** <https://forum.inductiveautomation.com/t/table-excel-export-with-button-in-ignition-perspective/89514>\
**Category:** Ignition\
**Tags:** perspective\
**Created:** [April 26, 2024, 9:29am UTC](https://forum.inductiveautomation.com/t/table-excel-export-with-button-in-ignition-perspective/89514 "2024-04-26T09:29:19Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![Alejandro\_Alaco](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/alejandro_alaco/32/59849_2.png) [@Alejandro\_Alaco](https://forum.inductiveautomation.com/u/Alejandro_Alaco)\
**Post date:** [April 26, 2024, 9:29am UTC](https://forum.inductiveautomation.com/t/table-excel-export-with-button-in-ignition-perspective/89514/1 "2024-04-26T09:29:19Z")

</div>

Hello!

I´ve got a button and I would like to export the content of a table "tblSummary" when I click on it.

```python

  
    filePath = system.file.getTempFile("csv")
    with open(filePath, "w") as file:
        for row in data:
            file.write(",".join(str(item) for item in row) + "\n")
    system.perspective.download(filename, File(filePath))

table = self.getSibling("tblSummary")
data = table.props.data

csv_data = [[col for col in row.values()] for row in data]

# Write to a CSV file and trigger download
write_csv(csv_data, "exported_data.csv")

```

I using this code on the button Script´s configuration

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/0/f/0fe323a5e27ccf061c79587d10092bd584957fd6.png)

---

<div class="post-metadata">

**Author:** ![Transistor](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/transistor/32/3380_2.png) [@Transistor](https://forum.inductiveautomation.com/u/Transistor)\
**Post date:** [April 26, 2024, 9:50am UTC](https://forum.inductiveautomation.com/t/table-excel-export-with-button-in-ignition-perspective/89514/2 "2024-04-26T09:50:07Z")

</div>

> [@Alejandro\_Alaco](#):
>
> I using this code on the button Script´s configuration

And what is the problem?

---

<div class="post-metadata">

**Author:** ![Alejandro\_Alaco](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/alejandro_alaco/32/59849_2.png) [@Alejandro\_Alaco](https://forum.inductiveautomation.com/u/Alejandro_Alaco)\
**Post date:** [April 26, 2024, 9:53am UTC](https://forum.inductiveautomation.com/t/table-excel-export-with-button-in-ignition-perspective/89514/3 "2024-04-26T09:53:04Z")

</div>

doesn´t download the csv when I launching Perspective session.

---

<div class="post-metadata">

**Author:** ![Transistor](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/transistor/32/3380_2.png) [@Transistor](https://forum.inductiveautomation.com/u/Transistor)\
**Post date:** [April 26, 2024, 9:54am UTC](https://forum.inductiveautomation.com/t/table-excel-export-with-button-in-ignition-perspective/89514/4 "2024-04-26T09:54:38Z")

</div>

You didn't tell it to. You told it to export it to a file on the gateway.

---

<div class="post-metadata">

**Author:** ![Alejandro\_Alaco](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/alejandro_alaco/32/59849_2.png) [@Alejandro\_Alaco](https://forum.inductiveautomation.com/u/Alejandro_Alaco)\
**Post date:** [April 26, 2024, 9:55am UTC](https://forum.inductiveautomation.com/t/table-excel-export-with-button-in-ignition-perspective/89514/5 "2024-04-26T09:55:36Z")

</div>

Oh, ok thanks Transistor, adding that part, cheers

---

<div class="post-metadata">

**Author:** ![Transistor](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/transistor/32/3380_2.png) [@Transistor](https://forum.inductiveautomation.com/u/Transistor)\
**Post date:** [April 26, 2024, 9:56am UTC](https://forum.inductiveautomation.com/t/table-excel-export-with-button-in-ignition-perspective/89514/6 "2024-04-26T09:56:30Z")

</div>

> [@Exporting Perspective Table data to CSV](https://forum.inductiveautomation.com/t/exporting-perspective-table-data-to-csv/89354/3):
>
> [system.dataset.toCSV()](https://www.docs.inductiveautomation.com/docs/8.1/appendix/scripting-functions/system-dataset/system-dataset-toCSV#keywords) requires a dataset. # root \> table-flex \> body \> table table = self.getChild("Table Flex").getChild("Body").getChild("Table") # create a list of columns that are selected by user colsToKeep = [col["field"] for col in table.props.columns if col["visible"]] data=[] for el in table.props.data: rowData = [v["value"] for \_,v in el.items() if \_ in colsToKeep] data.append(rowData) newCsv = system.dataset.toCSV(system.dataset.toDataSet(colsToKeep, data) sy…

---

<div class="post-metadata">

**Author:** ![Alejandro\_Alaco](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/alejandro_alaco/32/59849_2.png) [@Alejandro\_Alaco](https://forum.inductiveautomation.com/u/Alejandro_Alaco)\
**Post date:** [May 7, 2024, 8:41am UTC](https://forum.inductiveautomation.com/t/table-excel-export-with-button-in-ignition-perspective/89514/7 "2024-05-07T08:41:04Z")

</div>

I added this code to my button:

```python
def runAction(self, event):

	
	component = self.getSibling("CO2Table")
	
	csv = system.dataset.toCSV(component.props.data)	
	
	system.perspective.download("myExport.csv", csv)

```

and now I can download the table content as a excel file.

step by step:

1. **Identify Hierarchical Structure** : Know the relative position of your button and table component to determine which navigation method (`getParent`, `getChild`, `getSibling`) to use.
2. **Use Component Navigation Functions** : Apply the proper function to locate the table relative to the button.
3. **Export Table Data** : Utilize the appropriate Ignition Perspective functions to retrieve the dataset and initiate a download.

---

<div class="post-metadata">

**Author:** ![Transistor](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/transistor/32/3380_2.png) [@Transistor](https://forum.inductiveautomation.com/u/Transistor)\
**Post date:** [May 7, 2024, 9:05am UTC](https://forum.inductiveautomation.com/t/table-excel-export-with-button-in-ignition-perspective/89514/8 "2024-05-07T09:05:57Z")

</div>

This has a very strong smell of ChatGPT. You have been warned about posting AI answers several times.

Please state clearly if this is your work or if you got it from AI.

---

<div class="post-metadata">

**Author:** ![Alejandro\_Alaco](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/alejandro_alaco/32/59849_2.png) [@Alejandro\_Alaco](https://forum.inductiveautomation.com/u/Alejandro_Alaco)\
**Post date:** [May 7, 2024, 9:09am UTC](https://forum.inductiveautomation.com/t/table-excel-export-with-button-in-ignition-perspective/89514/9 "2024-05-07T09:09:29Z")

</div>

You right, I came with the code, then get the explanation from chatGPT to make the post easier to understand.

---

<div class="post-metadata">

**Author:** ![Transistor](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/transistor/32/3380_2.png) [@Transistor](https://forum.inductiveautomation.com/u/Transistor)\
**Post date:** [May 7, 2024, 9:14am UTC](https://forum.inductiveautomation.com/t/table-excel-export-with-button-in-ignition-perspective/89514/10 "2024-05-07T09:14:49Z")

</div>

Yes, and ChatGPT gives a poor answer. Using hierarchical structure means that the application will break if anything gets moved. The preferred method is to use message handlers.

Please stop posting ChatGPT. See [FAQ - Inductive Automation Forum](https://forum.inductiveautomation.com/faq).

> [Post Only Your Own Stuff](https://forum.inductiveautomation.com/faq#stealing)  
> You may not post anything digital that belongs to someone else without permission. You may not post descriptions of, links to, or methods for stealing someone’s intellectual property (software, video, audio, images), or for breaking any other law.  
> **This includes artifacts of large language models or other "AI" tools, such as ChatGPT.** While LLMs are often useful, they lack useful context for Ignition development and should be used sparingly for specific purposes. Posting LLM output as your own content _with no human authored content_ attached is not a useful post, and **may earn you a warning**.

---

<div class="post-metadata">

**Author:** ![Alejandro\_Alaco](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/alejandro_alaco/32/59849_2.png) [@Alejandro\_Alaco](https://forum.inductiveautomation.com/u/Alejandro_Alaco)\
**Post date:** [May 7, 2024, 9:31am UTC](https://forum.inductiveautomation.com/t/table-excel-export-with-button-in-ignition-perspective/89514/11 "2024-05-07T09:31:02Z")

</div>

Ok, going to learn to use message handlers
