omafeli
November 26, 2024, 8:02pm
1
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.
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.
system.perspective.print(str(datos_filtrados))
system.perspective.print(str(encabezados))
In this part system.dataset.toExcel(True, [datos_dataset])
dont work
I cant
system.perspective.download(filename, spreadsheet)
How do you know it doesn't work?
system.dataset.toExcel | Ignition User Manual returns array.
What are you trying to do with this once it is an Excel spreadsheet?
omafeli
November 26, 2024, 8:12pm
3
In the code I have the following:
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.
I'm not sure that it'll print it.
What do you mean by
And once you have the spreadsheet, are you trying to download it?
The system.perspective.print | Ignition User Manual 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.
omafeli
November 26, 2024, 8:25pm
6
This is my code:
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
The message after the
system.dataset.toExcel(True, [dataset_data])
doesn't print it, it kind of gets stuck in that part.
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.
1 Like
omafeli
November 27, 2024, 2:49am
8
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
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.
omafeli
November 27, 2024, 3:24pm
10
Thanks, I have that code block in a try-catch
, printing the error in console, but it does not print any error.
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))
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?
also try adding in java execptions
from java.lang import Throwable
try:
...
except Throwable, t:
...
except Exception, e:
...
or
from java.lang import Exception as JavaExpection
try:
...
except (JavaExpection, Exception), e:
...print(e)
omafeli
November 27, 2024, 4:59pm
12
I tried with the two you mention but no errors appear.
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.
omafeli
November 28, 2024, 12:59pm
14
I tried it but the same thing keeps happening, quite stranger.
system.dataset.toExcel()
returns an xls or xlsx format?
To steal Phil's line, you need someone to hold your hand on this. Call IA and they can help you.
pturmel
November 28, 2024, 2:54pm
16
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.)