# Convert Table filtered data to downloaded excel sheet

**URL:** <https://forum.inductiveautomation.com/t/convert-table-filtered-data-to-downloaded-excel-sheet/77001>\
**Category:** Ignition\
**Tags:** ignition81, perspective\
**Created:** [July 27, 2023, 11:07am UTC](https://forum.inductiveautomation.com/t/convert-table-filtered-data-to-downloaded-excel-sheet/77001 "2023-07-27T11:07:41Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![samer\_samy](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/samer_samy/32/52910_2.png) [@samer\_samy](https://forum.inductiveautomation.com/u/samer_samy)\
**Post date:** [July 27, 2023, 11:07am UTC](https://forum.inductiveautomation.com/t/convert-table-filtered-data-to-downloaded-excel-sheet/77001/1 "2023-07-27T11:07:41Z")

</div>

Hello guys,  
I succeeded to download the table data [self.props.data] to excel sheet using a button as below :

 ![Screenshot 2023-07-26 142804](https://us1.discourse-cdn.com/inductiveautomation/original/3X/7/2/7210c04f0d3db6c92cfde55c2d7186908a7b449b.png)

But I failed to download the filtered data [props.filter.results.data]of the table using a button .  
Can you help me in this as I find the filtered data is not a dataset so how to fix my code .

| | # implement your handler here |
| --- | --- |
| | fileName = 'HighBay Main Search '+self.props.filter.text+'.xls' |
| | excelbytes = system.dataset.dataSetToHTML(1, self.props.data, ) |
| | system.perspective.download(fileName, excelbytes) |

---

<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:** [July 27, 2023, 11:13am UTC](https://forum.inductiveautomation.com/t/convert-table-filtered-data-to-downloaded-excel-sheet/77001/2 "2023-07-27T11:13:33Z")

</div>

Do you need to specify `payload = {}` in your `sendMessage`?

---

<div class="post-metadata">

**Author:** ![samer\_samy](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/samer_samy/32/52910_2.png) [@samer\_samy](https://forum.inductiveautomation.com/u/samer_samy)\
**Post date:** [July 27, 2023, 3:04pm UTC](https://forum.inductiveautomation.com/t/convert-table-filtered-data-to-downloaded-excel-sheet/77001/3 "2023-07-27T15:04:24Z")

</div>

I found the solution.

props.filter.results.data is a dictionary that should be converted to dataset.

> Blockquote

myList =   
for key in value:  
Header=key.keys()  
myList.append(key.values())  
myorder = [5,6, 2,1, 3, 0,4]  
myList = [[sublst[i] for i in myorder] for sublst in myList]  
Header = [Header[i] for i in myorder]

```
return system.dataset.toDataSet(Header, myList)

```

> Blockquote

 ![Screenshot 2023-07-27 180019](https://us1.discourse-cdn.com/inductiveautomation/original/3X/a/c/ac69a7e1d9508a0098d11731cd6617a46d983807.png)

---

<div class="post-metadata">

**Author:** ![lrose](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/lrose/32/62724_2.png) [@lrose](https://forum.inductiveautomation.com/u/lrose)\
**Post date:** [July 27, 2023, 3:52pm UTC](https://forum.inductiveautomation.com/t/convert-table-filtered-data-to-downloaded-excel-sheet/77001/4 "2023-07-27T15:52:58Z")

</div>

You can actually use `system.dataset.filterColumns()` to reorder the columns of a dataset.

```python
header = []
data = []
for key in value:
    if not header:
        header = key.keys()
    data.append(key.values())
return system.dataset.filterColumns(system.dataset.toDataSet(header,data),[5,6,2,1,3,0,4])

```

Also, be carful with scope. In your script the list Header is only defined inside of the for loop. If for some reason value is None or empty, then your script will result in an error.

Also, since the column names should always match, there is no need to get the column names more than once.

---

<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:** [July 27, 2023, 5:13pm UTC](https://forum.inductiveautomation.com/t/convert-table-filtered-data-to-downloaded-excel-sheet/77001/5 "2023-07-27T17:13:21Z")

</div>

> [@samer\_samy](#):
>
> Blockquote

Don't use blockquote to format code. Use the preformatted text button.

 ![Formatting code](https://us1.discourse-cdn.com/inductiveautomation/original/3X/7/0/70741738ea3cbbe8a2d249e1194c80035567335c.png)

This will preserve indentation (essential for Python) and apply syntax highlighting.
