# system.dataset.toExcel(True, \[datos\_dataset\]) dont work

**URL:** <https://forum.inductiveautomation.com/t/system-dataset-toexcel-true-datos-dataset-dont-work/99148>\
**Category:** Ignition\
**Tags:** perspective\
**Created:** [November 26, 2024, 8:02pm UTC](https://forum.inductiveautomation.com/t/system-dataset-toexcel-true-datos-dataset-dont-work/99148 "2024-11-26T20:02:50Z")\
**Posts on this page:** 16\
**Page:** 1

<div class="post-metadata">

**Author:** ![omafeli](https://avatars.discourse-cdn.com/v4/letter/o/ba9def/32.png) [@omafeli](https://forum.inductiveautomation.com/u/omafeli)\
**Post date:** [November 26, 2024, 8:02pm UTC](https://forum.inductiveautomation.com/t/system-dataset-toexcel-true-datos-dataset-dont-work/99148/1 "2024-11-26T20:02:50Z")

</div>

Hello everyone,

I am having problems with `system.dataset.toExcel(True,[data]).`

I am passing it a dataset that I create with one data and some headers, but at the moment of performing the toExcel() it doesn't perform it.

Do you know what could it be?

This is my code.

```python
datos = self.view.custom.listado_carga_masiva
datos_filtrados = [fila[1:-2] for fila in datos]
encabezados = [cod_archivo, rut_num_cliprov,nombre_cliprov,num_cuenta,ptotal_clp,codigo_abono,codigo_banco,email_cliprov,texto_archivo]

system.perspective.print(str(datos_filtrados))
system.perspective.print(str(encabezados))

# Create dataset
datos_dataset = system.dataset.toDataSet(encabezados, datos_filtrados)
self.parent.parent.parent.parent.getChild(flex_tabla).getChild(Table).props.data = datos_dataset

spreadsheet = system.dataset.toExcel(True, [datos_dataset])
system.perspective.print(spreadsheet)

```

This is an image of what my google chrome browser responds to.

```python
system.perspective.print(str(datos_filtrados))
system.perspective.print(str(encabezados))

```

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/b/b/bbe2ac7d36ecbd68d11d4e7096d3d726f4b03d01.png)

In this part `system.dataset.toExcel(True, [datos_dataset])` dont work

I cant  
`system.perspective.download(filename, spreadsheet)`

---

<div class="post-metadata">

**Author:** ![bschroeder](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/bschroeder/32/13260_2.png) [@bschroeder](https://forum.inductiveautomation.com/u/bschroeder)\
**Post date:** [November 26, 2024, 8:08pm UTC](https://forum.inductiveautomation.com/t/system-dataset-toexcel-true-datos-dataset-dont-work/99148/2 "2024-11-26T20:08:20Z")

</div>

How do you know it doesn't work?

[system.dataset.toExcel | Ignition User Manual](https://docs.inductiveautomation.com/docs/8.1/appendix/scripting-functions/system-dataset/system-dataset-toExcel) returns array.

What are you trying to do with this once it is an Excel spreadsheet?

---

<div class="post-metadata">

**Author:** ![omafeli](https://avatars.discourse-cdn.com/v4/letter/o/ba9def/32.png) [@omafeli](https://forum.inductiveautomation.com/u/omafeli)\
**Post date:** [November 26, 2024, 8:12pm UTC](https://forum.inductiveautomation.com/t/system-dataset-toexcel-true-datos-dataset-dont-work/99148/3 "2024-11-26T20:12:43Z")

</div>

In the code I have the following:

```python
spreadsheet = system.dataset.toExcel(True, [dataset_dataset])
system.perspective.print(“spreadsheet”)

```

But that print does not do it, it gets stuck in toExcel() and does not show anythings.

---

<div class="post-metadata">

**Author:** ![bschroeder](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/bschroeder/32/13260_2.png) [@bschroeder](https://forum.inductiveautomation.com/u/bschroeder)\
**Post date:** [November 26, 2024, 8:15pm UTC](https://forum.inductiveautomation.com/t/system-dataset-toexcel-true-datos-dataset-dont-work/99148/4 "2024-11-26T20:15:40Z")

</div>

I'm not sure that it'll print it.

What do you mean by

> [@omafeli](#):
>
> it gets stuck in toExcel() and does not show anythings.

And once you have the spreadsheet, are you trying to download it?

---

<div class="post-metadata">

**Author:** ![Transistor](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/transistor/32/3380_2.png) [@Transistor](https://forum.inductiveautomation.com/u/Transistor)\
**Post date:** [November 26, 2024, 8:17pm UTC](https://forum.inductiveautomation.com/t/system-dataset-toexcel-true-datos-dataset-dont-work/99148/5 "2024-11-26T20:17:45Z")

</div>

> [@omafeli](#):
>
> `system.perspective.print(“spreadsheet”)`

The [system.perspective.print | Ignition User Manual](https://www.docs.inductiveautomation.com/docs/8.1/appendix/scripting-functions/system-perspective/system-perspective-print) says,

> Prints the supplied message to the local console (or the gateway logs, as appropriate) - by default, this means the Output Console when in the Designer, and the browser's console when in a live session.

If you look in the output console or the browser's console when in a live session you should see the work "spreadsheet", which is what you have asked it to print.

---

<div class="post-metadata">

**Author:** ![omafeli](https://avatars.discourse-cdn.com/v4/letter/o/ba9def/32.png) [@omafeli](https://forum.inductiveautomation.com/u/omafeli)\
**Post date:** [November 26, 2024, 8:25pm UTC](https://forum.inductiveautomation.com/t/system-dataset-toexcel-true-datos-dataset-dont-work/99148/6 "2024-11-26T20:25:20Z")

</div>

This is my code:

```python
datos = self.view.custom.listado_carga_masiva
datos_filtrados = [fila[1:-2] for fila in datos]
encabezados = ["cod_archivo", "rut_num_cliprov","nombre_cliprov","num_cuenta","ptotal_clp","codigo_abono","codigo_banco","email_cliprov","texto_archivo"]
			
system.perspective.print(str(datos_filtrados))
system.perspective.print(str(encabezados))
			
# Crear dataset
datos_dataset = system.dataset.toDataSet(encabezados, datos_filtrados)
system.perspective.print(str(datos_dataset))
system.perspective.print(type(datos_dataset))
			
spreadsheet = system.dataset.toExcel(True, [datos_dataset])
system.perspective.print("BEFORE EXCEL")
		
# Convert the dataset to CSV
filename = payload['nombre_archivo'].upper() + '.xls'
system.perspective.download(filename, csv)

```

This is the browser console

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/c/5/c5f75da81b24d72c2c70afcbb9b00d6009bd7b33.png)

The message after the  
`system.dataset.toExcel(True, [dataset_data])`  
doesn't print it, it kind of gets stuck in that part.

---

<div class="post-metadata">

**Author:** ![KathyApplebaum](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kathyapplebaum/32/7261_2.png) [@KathyApplebaum](https://forum.inductiveautomation.com/u/KathyApplebaum)\
**Post date:** [November 26, 2024, 11:35pm UTC](https://forum.inductiveautomation.com/t/system-dataset-toexcel-true-datos-dataset-dont-work/99148/7 "2024-11-26T23:35:50Z")

</div>

The last two lines are the result of your print statement. Datasets don't have a "nice" print -- you'd have to loop through to print all the elements.

---

<div class="post-metadata">

**Author:** ![omafeli](https://avatars.discourse-cdn.com/v4/letter/o/ba9def/32.png) [@omafeli](https://forum.inductiveautomation.com/u/omafeli)\
**Post date:** [November 27, 2024, 2:49am UTC](https://forum.inductiveautomation.com/t/system-dataset-toexcel-true-datos-dataset-dont-work/99148/8 "2024-11-27T02:49:54Z")

</div>

I understand, that is to show that to `system.dataset.toExcel(True, [datos_dataset])` I am passing as parameter a dataset, but it is as if it was not executed, since the message after, `system.perspective.print("BEFORE EXCEL")`, is not shown

---

<div class="post-metadata">

**Author:** ![KathyApplebaum](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kathyapplebaum/32/7261_2.png) [@KathyApplebaum](https://forum.inductiveautomation.com/u/KathyApplebaum)\
**Post date:** [November 27, 2024, 3:09pm UTC](https://forum.inductiveautomation.com/t/system-dataset-toexcel-true-datos-dataset-dont-work/99148/9 "2024-11-27T15:09:48Z")

</div>

Ah, I'm with you now.

There are a couple of exceptions that can be thrown by `toExcel()`, so you might try wrapping that in a `try-catch` block to get more info.

---

<div class="post-metadata">

**Author:** ![omafeli](https://avatars.discourse-cdn.com/v4/letter/o/ba9def/32.png) [@omafeli](https://forum.inductiveautomation.com/u/omafeli)\
**Post date:** [November 27, 2024, 3:24pm UTC](https://forum.inductiveautomation.com/t/system-dataset-toexcel-true-datos-dataset-dont-work/99148/10 "2024-11-27T15:24:11Z")

</div>

Thanks, I have that code block in a `try-catch`, printing the error in console, but it does not print any error.

```python
try:
	datos = self.view.custom.listado_carga_masiva
	datos_filtrados = [fila[1:-2] for fila in datos]
	encabezados = ["cod_archivo", "rut_num_cliprov","nombre_cliprov","num_cuenta","ptotal_clp","codigo_abono","codigo_banco","email_cliprov","texto_archivo"]
				
	system.perspective.print(str(datos_filtrados))
	system.perspective.print(str(encabezados))
				
	# Crear dataset
	datos_dataset = system.dataset.toDataSet(encabezados, datos_filtrados)
	system.perspective.print(str(datos_dataset))
	system.perspective.print(type(datos_dataset))
				
	spreadsheet = system.dataset.toExcel(True, [datos_dataset])
	system.perspective.print("BEFORE EXCEL")
			
	# Convert the dataset to CSV
	filename = payload['nombre_archivo'].upper() + '.xls'
	system.perspective.download(filename, csv)

except Exception as e:
	system.perspective.print(str(e))

```

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/3/7/37ce8bc3f91ca75ce4ff7e00207e4bb54c107f46.png)  
It is as if it runs correctly but gets stuck in `toExcel()`.

Is there another way to create an .xls or .xlsx file in Perspective?

---

<div class="post-metadata">

**Author:** ![victordcq](https://avatars.discourse-cdn.com/v4/letter/v/f6c823/32.png) [@victordcq](https://forum.inductiveautomation.com/u/victordcq)\
**Post date:** [November 27, 2024, 3:32pm UTC](https://forum.inductiveautomation.com/t/system-dataset-toexcel-true-datos-dataset-dont-work/99148/11 "2024-11-27T15:32:35Z")

</div>

also try adding in java execptions

```python
from java.lang import Throwable

try:
	...
except Throwable, t:
	...
except Exception, e:
	...

```

or

```python
from java.lang import Exception as JavaExpection
try:
	...
except (JavaExpection, Exception), e:		
	...print(e)

```

---

<div class="post-metadata">

**Author:** ![omafeli](https://avatars.discourse-cdn.com/v4/letter/o/ba9def/32.png) [@omafeli](https://forum.inductiveautomation.com/u/omafeli)\
**Post date:** [November 27, 2024, 4:59pm UTC](https://forum.inductiveautomation.com/t/system-dataset-toexcel-true-datos-dataset-dont-work/99148/12 "2024-11-27T16:59:44Z")

</div>

I tried with the two you mention but no errors appear.

---

<div class="post-metadata">

**Author:** ![jlandwerlen](https://avatars.discourse-cdn.com/v4/letter/j/bc8723/32.png) [@jlandwerlen](https://forum.inductiveautomation.com/u/jlandwerlen)\
**Post date:** [November 27, 2024, 5:48pm UTC](https://forum.inductiveautomation.com/t/system-dataset-toexcel-true-datos-dataset-dont-work/99148/13 "2024-11-27T17:48:02Z")

</div>

I have had weird issues with code that just wouldn't work. Usually that happens when I pasted code from somewhere. When this happens I paste the code in an external editor, like visual studio code. If you see errors in the external editor, then clean them up and copy/paste back into ignition.

I'm not saying this is your issue, but for me it's happened enough that doing this is the first thing I do when I think it should work and doesn't. For whatever reason the ignition editor doesn't flag the errors and just won't execute, not sure why.

If you don't see errors then it's probably a good time to call IA and have them assist you.

---

<div class="post-metadata">

**Author:** ![omafeli](https://avatars.discourse-cdn.com/v4/letter/o/ba9def/32.png) [@omafeli](https://forum.inductiveautomation.com/u/omafeli)\
**Post date:** [November 28, 2024, 12:59pm UTC](https://forum.inductiveautomation.com/t/system-dataset-toexcel-true-datos-dataset-dont-work/99148/14 "2024-11-28T12:59:28Z")

</div>

I tried it but the same thing keeps happening, quite stranger.

`system.dataset.toExcel()` returns an xls or xlsx format?

---

<div class="post-metadata">

**Author:** ![jlandwerlen](https://avatars.discourse-cdn.com/v4/letter/j/bc8723/32.png) [@jlandwerlen](https://forum.inductiveautomation.com/u/jlandwerlen)\
**Post date:** [November 28, 2024, 1:24pm UTC](https://forum.inductiveautomation.com/t/system-dataset-toexcel-true-datos-dataset-dont-work/99148/15 "2024-11-28T13:24:44Z")

</div>

To steal Phil's line, you need someone to hold your hand on this. Call IA and they can help you.

---

<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:** [November 28, 2024, 2:54pm UTC](https://forum.inductiveautomation.com/t/system-dataset-toexcel-true-datos-dataset-dont-work/99148/16 "2024-11-28T14:54:24Z")

</div>

Probably only paid emergency help today--national holiday here in the U.S. (I'm not terribly interested in the parade my family has been watching.)
