I have built a dynamic table that allows users to select multiple tags and an interval then export them to excel. This issue I am running into is labeling the headers so that they actually reflect the tag names.
I can dynamically change the tag, but the header stays at whatever I have left it at. By using the column properties dataset I can change the label so it looks good inside the client, but as soon as you export is uses the column name, which I cannot seem to change using the tag history tool in the binding.
for example - my Column name is actually Tag 1, but the label is Effluent Flow. When I export to excel I get Tag 1. If I change the name in the column properties, it just breaks the link with the dataset and does nothing.
One way to do it is by creating a new dataset with the column names that you want.
Loop through your existing dataset to create a list of lists, which holds the rows of data for your dataset. Then create a list of the header names that you want.
Then call this function to create the new dataset with the column names that you want:
dataset = system.dataset.toDataSet(headers, data)
I found a simpler way to change the column names of a dataset.
This code goes in the actionPerformed event handler on the button the user presses to export to excel:
dataset = event.source.parent.getComponent('Table').data
dataset.setColumnNames(["col1","col2","col3"])
system.dataset.exportExcel("excelfile", 1,dataset)
EDIT: I looked into this further and it is not good practice in Ignition to directly change existing datasets.
Instead it is better to make a copy first, for example:
from com.inductiveautomation.ignition.common import BasicDataset
dataset = BasicDataset(event.source.parent.getComponent('Table').data)
dataset.setColumnNames(["col1","col2","col3"])
system.dataset.exportExcel("excelfile", 1,dataset)