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)


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!