# Good Template for Excel

**URL:** <https://forum.inductiveautomation.com/t/good-template-for-excel/3999>\
**Category:** Ignition\
**Created:** [February 14, 2012, 10:53pm UTC](https://forum.inductiveautomation.com/t/good-template-for-excel/3999 "2012-02-14T22:53:35Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![DSI600](https://avatars.discourse-cdn.com/v4/letter/d/ad7895/32.png) [@DSI600](https://forum.inductiveautomation.com/u/DSI600)\
**Post date:** [February 14, 2012, 10:53pm UTC](https://forum.inductiveautomation.com/t/good-template-for-excel/3999/1 "2012-02-14T22:53:35Z")

</div>

I have to show this to a customer on Friday.

I have my MYSQL database and SQL Tags Historian setup and logging. I need to be able to automatically every 10, 30 and 60 minutes to run a query on certian tags and export these to the same excel spreadsheet. Where in the excel spreadsheet I can then move the tags to the correct column and row.

Is there a good document on how to do this.

---

<div class="post-metadata">

**Author:** ![Travis.Cox](https://avatars.discourse-cdn.com/v4/letter/t/b9bd4f/32.png) [@Travis.Cox](https://forum.inductiveautomation.com/u/Travis.Cox)\
**Post date:** [February 14, 2012, 11:41pm UTC](https://forum.inductiveautomation.com/t/good-template-for-excel/3999/2 "2012-02-14T23:41:07Z")

</div>

Sure, you can create a timer script that runs on the gateway (in one location) every 30 seconds like this:[code]from java.util import Date  
from java.util import Calendar

endDate = Date()  
cal = Calendar.getInstance()  
cal.setTime(endDate)  
cal.add(Calendar.HOUR, -24)  
startDate = cal.getTime()  
ds = system.tag.queryTagHistory(["[dbname]Path/To/Tag1", “[dbname]Path/To/Tag2”], startDate, endDate, 0, “MinMax”, “Wide”, [“Tag1”, “Tag2”])

spreadsheet = system.dataset.dataSetToExcel(1, [ds])  
filePath = “C:\output\results.xls”  
system.file.writeFile(filePath, spreadsheet)[/code][where “dbname” in the queryTagHistory() function is the name of the database connection holding your SQLTag history data]

Hope that helps you get started.
