# Example of code and location for exporting to an excel sheet

**URL:** <https://forum.inductiveautomation.com/t/example-of-code-and-location-for-exporting-to-an-excel-sheet/4098>\
**Category:** Ignition\
**Created:** [March 2, 2012, 9:42pm UTC](https://forum.inductiveautomation.com/t/example-of-code-and-location-for-exporting-to-an-excel-sheet/4098 "2012-03-02T21:42:03Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![amr123](https://avatars.discourse-cdn.com/v4/letter/a/e5b9ba/32.png) [@amr123](https://forum.inductiveautomation.com/u/amr123)\
**Post date:** [March 2, 2012, 9:42pm UTC](https://forum.inductiveautomation.com/t/example-of-code-and-location-for-exporting-to-an-excel-sheet/4098/1 "2012-03-02T21:42:03Z")

</div>

I need an example of where, how and what sytax to use for sending my alert log to an excel file ever 24 hours at mid night.

I can make it create and send to excel by clicking a button with the code below in the event handler but I need it to be automatic at mid night.

```
 results = system.db.runQuery("SELECT * FROM alert_log")
 results = system.dataset.toDataSet(results)
 spreadsheet = system.dataset.dataSetToExcel(1, [results])
 filePath = "C:\\output\\results1.xls"
 system.file.writeFile(filePath, spreadsheet)

```

I’m new to Ignition and Java language. Please help! 😢

---

<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:** [March 3, 2012, 12:49am UTC](https://forum.inductiveautomation.com/t/example-of-code-and-location-for-exporting-to-an-excel-sheet/4098/2 "2012-03-03T00:49:49Z")

</div>

You can create an Ignition Gateway Timer Event Script from the Project \> Event Scripts Gateway \> Timer menu item in the designer. The timer script will run every hour and it will look something like:`from java.util import Date
import system
d = Date()
if system.db.dateFormat(d, "HH") == "00":
	results = system.db.runQuery("SELECT * FROM alert_log")
	results = system.dataset.toDataSet(results)
	spreadsheet = system.dataset.dataSetToExcel(1, [results])
	filePath = "C:\\output\\results1.xls"
	system.file.writeFile(filePath, spreadsheet)`Of course it will save the results on the server machine. If you want that to happen on each client you can make Client Event Scripts.

---

<div class="post-metadata">

**Author:** ![Greg.Buehler](https://avatars.discourse-cdn.com/v4/letter/g/ecc23a/32.png) [@Greg.Buehler](https://forum.inductiveautomation.com/u/Greg.Buehler)\
**Post date:** [March 3, 2012, 1:00am UTC](https://forum.inductiveautomation.com/t/example-of-code-and-location-for-exporting-to-an-excel-sheet/4098/3 "2012-03-03T01:00:01Z")

</div>

[quote=“Travis.Cox”]You can create an Ignition Gateway Timer Event Script from the Project \> Event Scripts Gateway \> Timer menu item in the designer. The timer script will run every hour and it will look something like:`from java.util import Date
import system
d = Date()
if system.db.dateFormat(d, "HH") == "00":
	results = system.db.runQuery("SELECT * FROM alert_log")
	results = system.dataset.toDataSet(results)
	spreadsheet = system.dataset.dataSetToExcel(1, [results])
	filePath = "C:\\output\\results1.xls"
	system.file.writeFile(filePath, spreadsheet)`Of course it will save the results on the server machine. If you want that to happen on each client you can make Client Event Scripts.[/quote]

I might be advisable to make the filepath dynamic too.

```auto
filePath = "C:\\output\\results_%s.xls" % system.db.dateFormat(d, "yyyyMMdd")
```

---

<div class="post-metadata">

**Author:** ![amr123](https://avatars.discourse-cdn.com/v4/letter/a/e5b9ba/32.png) [@amr123](https://forum.inductiveautomation.com/u/amr123)\
**Post date:** [March 5, 2012, 3:22pm UTC](https://forum.inductiveautomation.com/t/example-of-code-and-location-for-exporting-to-an-excel-sheet/4098/4 "2012-03-05T15:22:59Z")

</div>

Thanks! ![:prayer:](https://us1.discourse-cdn.com/inductiveautomation/original/1X/e5a7e3b63facc151ea73e3b45db7bdb3d4bdc316.gif ":prayer:")

PS Any additional help to make this even better will be GREATLY appreciated!
