SQL table to Excel File Conversion in Ignition

I would like by means of click of button in Designer to convert SQL table to excel file.
How to do that, please advise.

results  =   system.db.runQuery( "SELECT * FROM example1 LIMIT 100" )
results  =   system.dataset.toDataSet(results)
spreadsheet  =   system.dataset.toExcel( 1 , [results])
filePath  =   "C:\\output\\results.xls"
system. file .writeFile(filePath, spreadsheet)

https://docs.inductiveautomation.com/display/DOC80/system.dataset.toExcel

got this error:

AttributeError: ‘com.inductiveautomation.ignition.common.script.Imm’ object has no attribute ‘toExcel’

As the function documentation notes, you need to be on Ignition 8.0.7 or higher. The corresponding function that works on other versions is system.dataset.datasetToExcel - but it has limitations and can only export in a slightly non-compliant .XLS format; hence the new toExcel function.

Thank you, guys, it works now!

Hi @PGriffith

Will the above query by @bkarabinchak.psi also works on Perspective session?
I am configuring this under a button click. But, getting this error always. Please help

Just guessing that the error is actually a SQL error.

What flavor of DB are you running? LIMIT is not valid in all DB flavors.

For instance in MSSQL you would use:

SELECT TOP 100 * FROM sensor.alarm_events
1 Like

@lrose I am using MySQL

Can you post the details of the error message?