# Perspective Table excel report

**URL:** <https://forum.inductiveautomation.com/t/perspective-table-excel-report/70598>\
**Category:** Ignition\
**Tags:** perspective\
**Created:** [March 3, 2023, 6:27pm UTC](https://forum.inductiveautomation.com/t/perspective-table-excel-report/70598 "2023-03-03T18:27:29Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Amir\_Farmanbar](https://avatars.discourse-cdn.com/v4/letter/a/a8b319/32.png) [@Amir\_Farmanbar](https://forum.inductiveautomation.com/u/Amir_Farmanbar)\
**Post date:** [March 3, 2023, 6:27pm UTC](https://forum.inductiveautomation.com/t/perspective-table-excel-report/70598/1 "2023-03-03T18:27:29Z")

</div>

I wonder is it possible to get an excel report from **Perspective table** info? someone just click on button and export all info to excel file?

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

---

<div class="post-metadata">

**Author:** ![bschroeder](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/bschroeder/32/13260_2.png) [@bschroeder](https://forum.inductiveautomation.com/u/bschroeder)\
**Post date:** [March 3, 2023, 6:41pm UTC](https://forum.inductiveautomation.com/t/perspective-table-excel-report/70598/2 "2023-03-03T18:41:14Z")

</div>

Slap a button on the view, grab the dataset from the table and run it through system.dataset.toExcel: [system.dataset.toExcel - Ignition User Manual 8.1 - Ignition Documentation](https://docs.inductiveautomation.com/display/DOC81/system.dataset.toExcel) and system.perspective.download [system.perspective.download - Ignition User Manual 8.1 - Ignition Documentation](https://docs.inductiveautomation.com/display/DOC81/system.perspective.download)

Stripped example from a working application:

```auto
tableDS= self.parent.getChild("Table").props.data
excelBytes= system.dataset.toExcel(True,tableDS)
fileName = 'TableExport{}.xlsx'.format(system.date.format(system.date.now(),'yyyMMd_kms'))
system.perspective.download(fileName,excelBytes,'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet')	

```

---

<div class="post-metadata">

**Author:** ![Amir\_Farmanbar](https://avatars.discourse-cdn.com/v4/letter/a/a8b319/32.png) [@Amir\_Farmanbar](https://forum.inductiveautomation.com/u/Amir_Farmanbar)\
**Post date:** [March 6, 2023, 2:29pm UTC](https://forum.inductiveautomation.com/t/perspective-table-excel-report/70598/3 "2023-03-06T14:29:00Z")

</div>

> [@bschroeder](#):
>
> ```auto
> tableDS= self.parent.getChild("Table").props.data
> excelBytes= system.dataset.toExcel(True,tableDS)
> fileName = 'TableExport{}.xlsx'.format(system.date.format(system.date.now(),'yyyMMd_kms'))
> system.perspective.download(fileName,excelBytes,'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet')
> 
> ```

Thank you. It works.

---

<div class="post-metadata">

**Author:** ![mdemaris](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/mdemaris/32/54639_2.png) [@mdemaris](https://forum.inductiveautomation.com/u/mdemaris)\
**Post date:** [February 7, 2024, 1:13am UTC](https://forum.inductiveautomation.com/t/perspective-table-excel-report/70598/4 "2024-02-07T01:13:20Z")

</div>

I get an error on the line that calls the `toExcel()` function:

```auto
Error running action 'component.onActionPerformed' on DataSetPlayGround@C/root/Button: Traceback (most recent call last): File "<function:runAction>", line 13, in runAction TypeError: can't convert [9, u'Test'] to com.inductiveautomation.ignition.common.Dataset

```

The data type from the DB is an `nvarchar`. Is there a simple way to strip the unicode character `u` off the string?

Thanks

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [February 7, 2024, 1:59am UTC](https://forum.inductiveautomation.com/t/perspective-table-excel-report/70598/5 "2024-02-07T01:59:06Z")

</div>

> [@mdemaris](#):
>
> strip the unicode character `u` off

Don't. It isn't really "there". It is an artifact of `repr()` operations when printing complex objects.

What it means is that you tried to supply something other than a list of datasets to the excel conversion function.

---

<div class="post-metadata">

**Author:** ![mdemaris](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/mdemaris/32/54639_2.png) [@mdemaris](https://forum.inductiveautomation.com/u/mdemaris)\
**Post date:** [February 7, 2024, 2:04am UTC](https://forum.inductiveautomation.com/t/perspective-table-excel-report/70598/6 "2024-02-07T02:04:34Z")

</div>

Ok,  
Here's my code:

```auto
results = system.db.runNamedQuery("CAT/Material")
self.parent.custom.result = type(results)
spreadSheet = system.dataset.toExcel(True, results)
filePath = "C:\\Users\\...\\Data Exports\\results.xls"
system.file.writeFile(filePath, spreadSheet)

```

The type is a `PyDataset`, just found that out.  
The error is the `toExcel` line.

Pretty basic query, 2 columns, 9 rows. I followed the docs for this function...oh, hang on, think I just saw something... I realized I was missing the `[]` around results. No error this time but I didn't get a file either.

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [February 7, 2024, 1:03pm UTC](https://forum.inductiveautomation.com/t/perspective-table-excel-report/70598/7 "2024-02-07T13:03:09Z")

</div>

This is a Perspective topic. Writing a file like that happens in the gateway. Are you looking in the gateway filesystem?

---

<div class="post-metadata">

**Author:** ![mdemaris](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/mdemaris/32/54639_2.png) [@mdemaris](https://forum.inductiveautomation.com/u/mdemaris)\
**Post date:** [February 7, 2024, 4:54pm UTC](https://forum.inductiveautomation.com/t/perspective-table-excel-report/70598/8 "2024-02-07T16:54:42Z")

</div>

@pturmel I moved this topic to this [thread](https://forum.inductiveautomation.com/t/how-to-export-data-to-existing-excel-workbook/85343/3), since the OP has already solved his issue and there are probably going to be more questions.

Thanks!
