system.dataset.toExcel
This function is used in Python Scripting.
Descriptionβ
Formats the contents of one or more datasets as an Excel spreadsheet, returning the results as a byte array. Each dataset specified will be added as a worksheet in the Excel workbook.
This function replaces the deprecated system.dataset.dataSetToExcel function.
Client Permission Restrictionsβ
This scripting function has no Client Permission restrictions.
Syntaxβ
system.dataset.toExcel(showHeaders, dataset, [nullsEmpty], [sheetNames])
Parametersβ
| Type | Parameter | Description |
|---|---|---|
| Boolean | showHeaders | If True, the spreadsheet will include a header row. If False, the header row will be omitted. |
| List[Dataset] | dataset | A sequence of one or more datasets, one for each sheet in the resulting workbook. |
| Boolean | nullsEmpty | If True, the spreadsheet will leave cells with NULL values empty, instead of allowing Excel to provide a default value like 0. Defaults to False. [optional] |
| List[String] | sheetNames | Expects a list of strings, where each string is a name for one of the datasets. When used, there must be an equal number of string names in sheetName as there are datasets in the dataset parameter. Names provided in this parameter may be sanitized into acceptable Excel sheet names. [optional] |
Returnsβ
Array - A byte array representing an Excel workbook.
Scopeβ
Gateway, Vision Client, Perspective Session
Code Examplesβ
Code Snippet
# This snippet would run a SQL query against a database, and turn the results into a string that is XML that Excel can open.
# It then writes the string to a file on the local hard drive.
results = system.db.runNamedQuery("Fetch Records",{})
spreadsheet = system.dataset.toExcel(True, [results])
filePath = "C:\\output\\results.xlsx"
system.file.writeFile(filePath, spreadsheet)