# Problem exporting table data to Excel

**URL:** <https://forum.inductiveautomation.com/t/problem-exporting-table-data-to-excel/79987>\
**Category:** Ignition\
**Tags:** perspective, scripting\
**Created:** [October 3, 2023, 4:38pm UTC](https://forum.inductiveautomation.com/t/problem-exporting-table-data-to-excel/79987 "2023-10-03T16:38:16Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![eMax](https://avatars.discourse-cdn.com/v4/letter/e/cdc98d/32.png) [@eMax](https://forum.inductiveautomation.com/u/eMax)\
**Post date:** [October 3, 2023, 4:38pm UTC](https://forum.inductiveautomation.com/t/problem-exporting-table-data-to-excel/79987/1 "2023-10-03T16:38:16Z")

</div>

Hi there,  
I have a button in my page thta should export table data to excel.  
Everything worked fine before I added a script to change the style of rows based on a value.

```auto
def transform(self, value, quality, timestamp):
	return [
		{'style': {"backgroundColor": "#D62F2F4D" if row['VuotoErr'] > 60 else "none"}, 'value': row} for row in value
		]

```

My button onClick event is:

```auto
	def jsonToDataset(list):
		columns = dict(list[0]).keys()
		data = []
		for item in list:
			row = []
			for column in columns:
				cellValue = item.get(column, '')
				try:
					dict(cellValue)
					cellValue = cellValue['value']
				except:
					pass
				row.append(cellValue)
			data.append(row)
		return system.dataset.toDataSet(columns, data)
		
	json = self.getSibling("tblDeodorazione").props.filter.results.data
	if not json:
		json = self.getSibling("tblDeodorazione").props.data	
	data = jsonToDataset(json)
	Excel_xlsx = system.dataset.toExcel(True,[data])
	system.perspective.download("rptDeodorazione.xlsx",Excel_xlsx)
	

```

if I write something in the table filter the output is correct:

 ![table filter](https://us1.discourse-cdn.com/inductiveautomation/original/3X/a/b/abcaac6cfd3e819a2a4f6c7a8b969176f34bfb29.png)

 ![export filter](https://us1.discourse-cdn.com/inductiveautomation/original/3X/4/4/444d11daebe3349833f5ed8c0414a7745383fb4f.png)

but if I don't wrtite anything on the filter here is the result:

 ![table no filter](https://us1.discourse-cdn.com/inductiveautomation/original/3X/e/e/eef48d34edc81b296a2cb938d32caf88345ec29e.png)  
 ![export no filter](https://us1.discourse-cdn.com/inductiveautomation/original/3X/4/b/4b4e5d62a9eb2cd6ba3c0be96d261eda1386f4cf.png)  
I think that, for sure, the problem is related to the new json structure:  
 ![json struct](https://us1.discourse-cdn.com/inductiveautomation/original/3X/0/e/0ec2ba931082350e95241567f52588195e31fe05.png)

But if the export script works when I have something written in the table filter, then, why it doesn't work if nothing is written there, the structure of the json doesn't change.  
I do not understand.  
If anyone has any suggestions I would be very grateful.  
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:** [October 3, 2023, 5:38pm UTC](https://forum.inductiveautomation.com/t/problem-exporting-table-data-to-excel/79987/2 "2023-10-03T17:38:53Z")

</div>

> [@eMax](#):
>
> the structure of the json doesn't change.

But it does change. You are moving the row into the nested `value` key.

---

<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:** [October 3, 2023, 5:41pm UTC](https://forum.inductiveautomation.com/t/problem-exporting-table-data-to-excel/79987/3 "2023-10-03T17:41:16Z")

</div>

Consider binding the raw data (in dataset format) to a custom property. Transform that custom property into the table's data property to provide the styling as you have it now. Have the export button simply use the dataset in the custom property.

---

<div class="post-metadata">

**Author:** ![eMax](https://avatars.discourse-cdn.com/v4/letter/e/cdc98d/32.png) [@eMax](https://forum.inductiveautomation.com/u/eMax)\
**Post date:** [October 3, 2023, 6:05pm UTC](https://forum.inductiveautomation.com/t/problem-exporting-table-data-to-excel/79987/4 "2023-10-03T18:05:12Z")

</div>

well, I tried but I don't really know how to accomplish that.  
I've used another work around, I've used the named query that fill the table and I use export button like this:

```auto
parameters = {"parStartDate":self.getSibling("startDate").props.value, "parEndDate":self.getSibling("endDate").props.value}
	data = system.db.runNamedQuery("UGP9/qryDeodorazione", parameters)	
	data = system.dataset.toExcel(True, [data])
	system.perspective.download("rptDeodorazione.xlsx",data)

```

My goal was to export values that match table filter only to excel, my solution works, but it's exports all data between startDate and endDate....better than nothing.  
For now I'm making it work fine. I'll do some more research...  
Thank you very much
