# Export only selected data from Table to Excel \[Ignition Perspective\]

**URL:** <https://forum.inductiveautomation.com/t/export-only-selected-data-from-table-to-excel-ignition-perspective/67710>\
**Category:** Ignition\
**Tags:** database, perspective\
**Created:** [December 16, 2022, 11:53am UTC](https://forum.inductiveautomation.com/t/export-only-selected-data-from-table-to-excel-ignition-perspective/67710 "2022-12-16T11:53:42Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Goutham\_Rao\_Y](https://avatars.discourse-cdn.com/v4/letter/g/eb9ed0/32.png) [@Goutham\_Rao\_Y](https://forum.inductiveautomation.com/u/Goutham_Rao_Y)\
**Post date:** [December 16, 2022, 11:53am UTC](https://forum.inductiveautomation.com/t/export-only-selected-data-from-table-to-excel-ignition-perspective/67710/1 "2022-12-16T11:53:42Z")

</div>

Hello team,  
Module: **Perspective**  
Component: **TABLE**  
Database used: **MSSQL**

I have created a table and have done Query Binding,and have created a button component and have done [**configure event**] script to download the table content in to excel file.

**[screenshot]**

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/7/1/710d9c666e06659c791d1399a2297aed5e473f01.png)

**Currently all data from the table is getting exported to excel file.**

**-\>** Is there any method for downloading the Table data like the following:

1. Download only first page table data shown on the screen  
**[screenshot]**  

2. Download only latest 20 dataset from table

**Code written for exporting table data to excel:**

[code.txt](https://forum.inductiveautomation.com/uploads/short-url/igusteRdwpxwBfDkadPpiWyHtVl.txt) (700 Bytes)

Thanks in Advance,  
Goutham Rao Y

---

<div class="post-metadata">

**Author:** ![ShaneH](https://avatars.discourse-cdn.com/v4/letter/s/3e96dc/32.png) [@ShaneH](https://forum.inductiveautomation.com/u/ShaneH)\
**Post date:** [December 16, 2022, 12:38pm UTC](https://forum.inductiveautomation.com/t/export-only-selected-data-from-table-to-excel-ignition-perspective/67710/2 "2022-12-16T12:38:43Z")

</div>

Hi-

There are probably several ways of doing this.

Based on your shared code, I would change the range() statement to only include the indices you want to download.

First 20: for row in range(0,20):  
Last 20: for row in range(numRows-20,numRows):  
Specific rows: for row in [1, 2, 3, 5, 7, 9]:

You might need to have checks to ensure you have 20 rows (numRows \> 20).

```auto
# only download last 20 rows
numRows = len(data)
for row in range(numRows-20,numRows):
	rowData = []
	for col in range(len(headers)):
		cell = data[row][headers[col]]
		if hasattr(cell, 'value'):
			rowData.append(cell.value)
		else:
			rowData.append(cell)
	datasetData.append(rowData)

```

HTH.  
-Shane

---

<div class="post-metadata">

**Author:** ![Goutham\_Rao\_Y](https://avatars.discourse-cdn.com/v4/letter/g/eb9ed0/32.png) [@Goutham\_Rao\_Y](https://forum.inductiveautomation.com/u/Goutham_Rao_Y)\
**Post date:** [December 19, 2022, 7:30am UTC](https://forum.inductiveautomation.com/t/export-only-selected-data-from-table-to-excel-ignition-perspective/67710/3 "2022-12-19T07:30:42Z")

</div>

Thanks Shane, but if I need to download the table data page by page. how can I do that.  
For example, there are 2 pages in the table [UI part] page 1 and page 2  
[screenshot]  
 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/f/0/f0b26856fd0d09692f4c720531eda9090e2f0754.png)

so, if I want to download page 2 table data, then how can I set the condition to download page 2 data only.

Note: table pages might increase further when more data are uploaded....

---

<div class="post-metadata">

**Author:** ![ShaneH](https://avatars.discourse-cdn.com/v4/letter/s/3e96dc/32.png) [@ShaneH](https://forum.inductiveautomation.com/u/ShaneH)\
**Post date:** [December 19, 2022, 1:53pm UTC](https://forum.inductiveautomation.com/t/export-only-selected-data-from-table-to-excel-ignition-perspective/67710/4 "2022-12-19T13:53:46Z")

</div>

I think if you look at the table component, it has a property for 'activePage'.

You could probably use this, along with the total number of rows in the table, and the number of rows per page, to calculate the range of row indices to export.

```auto
# this assumes 'self' points to a table component
data = self.props.data
numRows = len(data)
numRowsPerPage = 25
activePage = self.props.pager.activePage

startRow = numRowsPerPage * (activePage - 1)
endRow = startRow + numRowsPerPage 

if (endRow > numRows): endRow = numRows

for row in range(startRow, endRow):
   # do the work here

```

HTH.  
-Shane
