# Saving excel file from script console and vision

**URL:** <https://forum.inductiveautomation.com/t/saving-excel-file-from-script-console-and-vision/77368>\
**Category:** Ignition\
**Tags:** perspective, vision\
**Created:** [August 3, 2023, 2:15pm UTC](https://forum.inductiveautomation.com/t/saving-excel-file-from-script-console-and-vision/77368 "2023-08-03T14:15:39Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![zacharyw.larson](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/zacharyw.larson/32/23749_2.png) [@zacharyw.larson](https://forum.inductiveautomation.com/u/zacharyw.larson)\
**Post date:** [August 3, 2023, 2:15pm UTC](https://forum.inductiveautomation.com/t/saving-excel-file-from-script-console-and-vision/77368/1 "2023-08-03T14:15:39Z")

</div>

```auto

ccc = ['a', 'b', 'c', 'd', 'g', 'k', 'm']
fruits = [['apple', 'banana', 'cherry', 'date', 'grape', 'kiwi', 'mango']]
print ( str(len(ccc)) + ' ' + str(len(fruits)))
datasetOut2 = system.dataset.toDataSet(ccc, fruits)

fileName = 'myFile.xls'
ss = system.dataset.toExcel(True, [datasetOut2,datasetOut], ['Fruits','tests'])
#system.perspective.download(filename, ss)

filePath = system.file.saveFile(fileName)
if filePath is not None:
	system.file.writeFile(filePath, ss)

```

This almost works, but my sheet names don't show as Fruits and tests, instead they show as dataset1 and dataset2.

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [August 3, 2023, 2:22pm UTC](https://forum.inductiveautomation.com/t/saving-excel-file-from-script-console-and-vision/77368/2 "2023-08-03T14:22:52Z")

</div>

Take a closer look at the arguments:

[https://docs.inductiveautomation.com/display/DOC81/system.dataset.toExcel](https://docs.inductiveautomation.com/display/DOC81/system.dataset.toExcel)

---

<div class="post-metadata">

**Author:** ![lrose](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/lrose/32/62724_2.png) [@lrose](https://forum.inductiveautomation.com/u/lrose)\
**Post date:** [August 3, 2023, 2:24pm UTC](https://forum.inductiveautomation.com/t/saving-excel-file-from-script-console-and-vision/77368/3 "2023-08-03T14:24:35Z")

</div>

I would try this:

```auto
system.dataset.toExcel(True,[datasetOut2,datasetOut],sheetNames = ['Fruits','tests']

```

Also, just because it bothers me, you can use print like this:

```auto
print len(ccc),' ',len(fruits)

```

---

<div class="post-metadata">

**Author:** ![zacharyw.larson](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/zacharyw.larson/32/23749_2.png) [@zacharyw.larson](https://forum.inductiveautomation.com/u/zacharyw.larson)\
**Post date:** [August 3, 2023, 2:30pm UTC](https://forum.inductiveautomation.com/t/saving-excel-file-from-script-console-and-vision/77368/4 "2023-08-03T14:30:54Z")

</div>

Thanks  
That worked.

I set the extension as '.xlsx' and specified sheetNames like you said.

Solved two issues it seems.  
The sheets are named correctly now, thanks.  
I had been getting a warning the file was possibly corrupted.

I am not very good at reading the arguments and understanding what they mean for me to do.

---

<div class="post-metadata">

**Author:** ![lrose](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/lrose/32/62724_2.png) [@lrose](https://forum.inductiveautomation.com/u/lrose)\
**Post date:** [August 3, 2023, 2:39pm UTC](https://forum.inductiveautomation.com/t/saving-excel-file-from-script-console-and-vision/77368/5 "2023-08-03T14:39:24Z")

</div>

> [@zacharyw.larson](#):
>
> I am not very good at reading the arguments and understanding what they mean for me to do

The problem in this instance is that the `nullsEmpty` argument is expecting a boolean. Since many things in python can have a _Truthy_ value, the function assumed that your list of sheetNames was actually you setting `nullsEmpty` true.

Yes _Truthy_ and _Falsy_ is a thing.

> **[Truthy and Falsy Values in Python: A Detailed Introduction](https://www.freecodecamp.org/news/truthy-and-falsy-values-in-python/)**
>
> Welcome In this article, you will learn: \* What truthy and falsy values are. \* What makes a value truthy or falsy. \* How to use the bool() function to determine if a value is truthy or falsy. \* How to make objects from user-defined classes

As a general rule of thumb, if you look at a function with multiple optional arguments and you want to skip one in the order, then use keyword arguments (e.g. `sheetNames=['name']`) to insure you're setting the argument you actually want to set.

---

<div class="post-metadata">

**Author:** ![zacharyw.larson](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/zacharyw.larson/32/23749_2.png) [@zacharyw.larson](https://forum.inductiveautomation.com/u/zacharyw.larson)\
**Post date:** [August 3, 2023, 5:06pm UTC](https://forum.inductiveautomation.com/t/saving-excel-file-from-script-console-and-vision/77368/6 "2023-08-03T17:06:27Z")

</div>

I expected too much of the optional functions.

Because they are different datatypes, I thought the function detected to datatype to determine the intended use. The flexibility of booleans in python though, have to remember that. Thanks
