I’m using runPrepQuery to return a dataset which I’m then sending to Excel.
I’ve been asked to insert some blank rows in to try and make it more readable, specifically when a value in a certain column changes.
Here is part of my code. data2 holds the dataset returned from the query and the column I’m looking for a change in is “Load Reference”.
[code] loadRef=""
newRows=[]
# Loop through data
for row in data2:
if loadRef!=row[“Load Reference”]:
# Avoid gap line at the start
if loadRef!="":
# Insert gap line
newRows.append(["","","","","",""])
# Store new load reference
loadRef=row[“Load Reference”]
# Store original data
newRows.append([row[0], row[1], row[2], str(row[3]), row[4], str(row[5])])
# Now convert to dataset
newData2 = system.dataset.toDataSet(["Supplier","Product","Load Reference","Machine","Description","Value"], newRows)
[/code]
Now after much messing about this basically does seem to do what I want.
But is this the best way do to it? Is there an easier way?
Specifically, should I be able to do newRows.append(row) rather than they way I’ve done it, listing out every single column?
And also is there a way to easily reuse the column headers from the original dataset rather than defining them again like I have done? I tried the system.dataset.getColumnHeaders function but couldn’t get it to work.