# Tag to Excel

**URL:** <https://forum.inductiveautomation.com/t/tag-to-excel/12484>\
**Category:** Ignition\
**Created:** [December 20, 2016, 10:54am UTC](https://forum.inductiveautomation.com/t/tag-to-excel/12484 "2016-12-20T10:54:48Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![HALW80](https://avatars.discourse-cdn.com/v4/letter/h/47e85d/32.png) [@HALW80](https://forum.inductiveautomation.com/u/HALW80)\
**Post date:** [December 20, 2016, 10:54am UTC](https://forum.inductiveautomation.com/t/tag-to-excel/12484/1 "2016-12-20T10:54:48Z")

</div>

Looking for the best option to write a few tags to Excel for a customer at 5 min interval.  
In the following format

Tagname Date Value Units

e.g. Tag1 11:00 6 m3/h  
Tag2 11:00 6.3 m  
Tag3 11:00 5.5 bar  
Tag1 11:05 6.2 m3/h  
Tag2 11:05 7.1 m  
Tag3 11:05 3.5 bar

I tried using a query and writing the dataset to excel but they were coming out in columns  
ie t\_stamp Tag1 Tag2 Tag3  
11:00 6 6.3 5.5  
11:05 6.2 7.1 3.5

---

<div class="post-metadata">

**Author:** ![JordanCClark](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jordancclark/32/83362_2.png) [@JordanCClark](https://forum.inductiveautomation.com/u/JordanCClark)\
**Post date:** [December 20, 2016, 1:17pm UTC](https://forum.inductiveautomation.com/t/tag-to-excel/12484/2 "2016-12-20T13:17:04Z")

</div>

Once you have your dataset from the query, you can rearrange through scripting.

In the attached window, I made a table with your example dataset, there’s a button to process it and display in another table, and another button to clear the results.

Here’s the meat of the script:

[code]# get input dataset  
dataIn=system.dataset.toPyDataSet(event.source.parent.getComponent(‘Table In’).data)

# get column names from input dataset

headersIn = dataIn.getUnderlyingDataset().getColumnNames()

# initialize output data

headersOut = [‘Tagname’,‘Date’,‘Value’,‘Units’]  
units\_list = [’’,‘m3/h’,‘m’,‘bar’]  
dataOut=[]

# process data

for row in dataIn:

# This might look strange, but pyhton lets you iterate theough multiple lists in parallel.

# The zip() function ties the lists together

for header, col, unit in zip(headersIn, row, units\_list):  
#set timestamp value, otherwise, add to output data  
if header == ‘t\_stamp’:  
ts = col  
else:  
dataOut.append([header, ts, col, unit])

datasetOut = system.dataset.toDataSet(headersOut, dataOut)  
event.source.parent.getComponent(‘Table Out’).data = datasetOut  
[/code]

---

<div class="post-metadata">

**Author:** ![HALW80](https://avatars.discourse-cdn.com/v4/letter/h/47e85d/32.png) [@HALW80](https://forum.inductiveautomation.com/u/HALW80)\
**Post date:** [December 20, 2016, 3:00pm UTC](https://forum.inductiveautomation.com/t/tag-to-excel/12484/3 "2016-12-20T15:00:51Z")

</div>

Thanks Jordan, will give it a try

---

<div class="post-metadata">

**Author:** ![HALW80](https://avatars.discourse-cdn.com/v4/letter/h/47e85d/32.png) [@HALW80](https://forum.inductiveautomation.com/u/HALW80)\
**Post date:** [January 11, 2017, 8:43am UTC](https://forum.inductiveautomation.com/t/tag-to-excel/12484/4 "2017-01-11T08:43:19Z")

</div>

I have added and manipulated all the data and have it writing to excel with the touch of a button.

I now need to automate it that it writes to file once a day - via gateway script I presume.  
except I don’t seem to be able to access the window/table from the gateway script.

---

<div class="post-metadata">

**Author:** ![JordanCClark](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jordancclark/32/83362_2.png) [@JordanCClark](https://forum.inductiveautomation.com/u/JordanCClark)\
**Post date:** [January 11, 2017, 2:39pm UTC](https://forum.inductiveautomation.com/t/tag-to-excel/12484/5 "2017-01-11T14:39:12Z")

</div>

Window components are not accessible to the gateway.

The gateway script should be similar to what you have, you will just need to export the manipulated dataset to Excel directly instead of sending it to a table first.

---

<div class="post-metadata">

**Author:** ![HALW80](https://avatars.discourse-cdn.com/v4/letter/h/47e85d/32.png) [@HALW80](https://forum.inductiveautomation.com/u/HALW80)\
**Post date:** [January 12, 2017, 9:00am UTC](https://forum.inductiveautomation.com/t/tag-to-excel/12484/6 "2017-01-12T09:00:24Z")

</div>

I figured that eventually!

Instead of a table using Tag History on a window, I used a query tag to get the data and then the gateway script accessed the tag and manipulated the dataset as required with your script.  
Thanks again for your input as I had hit a brick wall up to that ![:prayer:](https://us1.discourse-cdn.com/inductiveautomation/original/1X/e5a7e3b63facc151ea73e3b45db7bdb3d4bdc316.gif ":prayer:")

---

<div class="post-metadata">

**Author:** ![toughautomation](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/toughautomation/32/27171_2.png) [@toughautomation](https://forum.inductiveautomation.com/u/toughautomation)\
**Post date:** [May 2, 2019, 5:42pm UTC](https://forum.inductiveautomation.com/t/tag-to-excel/12484/7 "2019-05-02T17:42:40Z")

</div>

Hey guys, was this application writing to an existing Excel file, or to a new one?

I’m trying to write tag data into an existing macro-enabled spreadsheet to a specific tab, and specific intervals. Have either of you dealt with this or know where I could get some direction on this? Or better yet, know someone who would like to be hired to handle the code for me?
