How to export data that are selected in an Easychart?

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

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

# 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)

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.

Have you tried like this
system.dataset.toCSV(selected_rows)

exports nothing

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:

# 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)

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