# How to export data that are selected in an Easychart?

**URL:** <https://forum.inductiveautomation.com/t/how-to-export-data-that-are-selected-in-an-easychart/78062>\
**Category:** General Discussion\
**Tags:** vision, ignition81, scripting\
**Created:** [August 18, 2023, 7:46am UTC](https://forum.inductiveautomation.com/t/how-to-export-data-that-are-selected-in-an-easychart/78062 "2023-08-18T07:46:34Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Miguel\_Cimildoro](https://avatars.discourse-cdn.com/v4/letter/m/53a042/32.png) [@Miguel\_Cimildoro](https://forum.inductiveautomation.com/u/Miguel_Cimildoro)\
**Post date:** [August 18, 2023, 7:46am UTC](https://forum.inductiveautomation.com/t/how-to-export-data-that-are-selected-in-an-easychart/78062/1 "2023-08-18T07:46:34Z")

</div>

Hello everyone,

is there any way to export the data that is selected in an EasyChart? I am using the .exportExcel method, but I don't know if there is any other method that is more suited to what I am looking for.

e.g. export all those selected in the enabled column

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

---

<div class="post-metadata">

**Author:** ![Miguel\_Cimildoro](https://avatars.discourse-cdn.com/v4/letter/m/53a042/32.png) [@Miguel\_Cimildoro](https://forum.inductiveautomation.com/u/Miguel_Cimildoro)\
**Post date:** [August 18, 2023, 9:31am UTC](https://forum.inductiveautomation.com/t/how-to-export-data-that-are-selected-in-an-easychart/78062/2 "2023-08-18T09:31:20Z")

</div>

this is the code I have managed to make and the error I get when I try to open excel

```auto
# Get the Dataset component named "DDBB"
data_ddbb = event.source.parent.getComponent('DDBB').pens

enabled_column_index = data_ddbb.getColumnIndex("ENABLED")
column_name = data_ddbb.getColumnName(7)
selected_rows = []

for i in range(data_ddbb.getRowCount()):
    if data_ddbb.getValueAt(i, enabled_column_index):
        selected_rows.append(data_ddbb.getValueAt(i, enabled_column_index))

file_path = system.dataset.exportExcel("SelectedData", True, selected_rows)

```

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

msj: Excel cannot open the file "SelectedData.xlsx" because the format or extension is not valid. check that the file has not been damaged or that the file extension and format match.

---

<div class="post-metadata">

**Author:** ![Dharani\_T](https://avatars.discourse-cdn.com/v4/letter/d/bc8723/32.png) [@Dharani\_T](https://forum.inductiveautomation.com/u/Dharani_T)\
**Post date:** [August 18, 2023, 12:01pm UTC](https://forum.inductiveautomation.com/t/how-to-export-data-that-are-selected-in-an-easychart/78062/3 "2023-08-18T12:01:12Z")

</div>

Have you tried like this  
system.dataset.toCSV(selected\_rows)

---

<div class="post-metadata">

**Author:** ![Miguel\_Cimildoro](https://avatars.discourse-cdn.com/v4/letter/m/53a042/32.png) [@Miguel\_Cimildoro](https://forum.inductiveautomation.com/u/Miguel_Cimildoro)\
**Post date:** [August 18, 2023, 12:20pm UTC](https://forum.inductiveautomation.com/t/how-to-export-data-that-are-selected-in-an-easychart/78062/5 "2023-08-18T12:20:48Z")

</div>

exports nothing

---

<div class="post-metadata">

**Author:** ![justinedwards.jle](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/justinedwards.jle/32/37854_2.png) [@justinedwards.jle](https://forum.inductiveautomation.com/u/justinedwards.jle)\
**Post date:** [August 18, 2023, 7:34pm UTC](https://forum.inductiveautomation.com/t/how-to-export-data-that-are-selected-in-an-easychart/78062/6 "2023-08-18T19:34:52Z")

</div>

The problem is that you're not creating a dataset out of the selected data for the exportExcel method to export.

Here is an example that will work, and should be simple to adapt for your specific usage case:

```auto
# Get the Dataset component named "DDBB"
data_ddbb = event.source.parent.getComponent('DDBB').pens

# get the column index of the enabled column to filter data
enabled_column_index = data_ddbb.getColumnIndex("ENABLED")

# Create a list that will become a list of lists for a dataset
data = []

# Get the column headers from the pens dataset
headers = list(data_ddbb.columnNames)

# iterate through each row of the pens dataset to see if the pen is enabled
for row in range(data_ddbb.rowCount):
	if data_ddbb.getValueAt(row, enabled_column_index):
		
		# Create a row list for the row data 
		rowData = []
		
		# iterate through each column to get the row data
		for column in range(data_ddbb.columnCount):
			rowData.append(data_ddbb.getValueAt(row, column))

		# append the row list to the main list
		data.append(rowData)
		
# Create a dataset with the selected pens data for exporting to Excel
selectedData = system.dataset.toDataSet(headers, data)

# Export the dataset
file_path = system.dataset.exportExcel("SelectedData", True, selectedData)

```

---

<div class="post-metadata">

**Author:** ![Miguel\_Cimildoro](https://avatars.discourse-cdn.com/v4/letter/m/53a042/32.png) [@Miguel\_Cimildoro](https://forum.inductiveautomation.com/u/Miguel_Cimildoro)\
**Post date:** [August 22, 2023, 8:03am UTC](https://forum.inductiveautomation.com/t/how-to-export-data-that-are-selected-in-an-easychart/78062/7 "2023-08-22T08:03:19Z")

</div>

thank you very much for your example, it helped me a lot. it was what i was looking for.
