GENERATE_SPREADSHEET scalar function
The GENERATE_SPREADSHEET scalar function generates a file in the integrated file system containing a spreadsheet based on either the results of a query or the complete content of a database file.
This scalar function relies upon the CLDownload feature provided by the IBM i Access Client Solutions (ACS) jar that ships on every IBM i. The ACS jar is delivered via the IBM HTTP SERVER FOR i PTF Group, and is found at this path: /QIBM/proddata/Access/ACS/Base/acsbundle.jar
CLOB, BLOB, DBCLOB, and XML data is not supported by CLDownload. It can be returned by casting the column to a non-LOB string data type.
Authorization: See Note below.
- path-name
- A character string containing the name of the path where the result spreadsheet file is to be written. An existing file is overwritten.
- spreadsheet-query
- A character string containing a query to run that identifies the rows to be included in the spreadsheet. The query can be up to 4000 characters long. Objects referenced in the query cannot be in QTEMP and must be fully qualified.
- library-name
- The name of the library containing file-name. QTEMP, *LIBL, and *CURLIB are not supported.
- file-name
- A character string containing the name of the database file that contains the rows and columns of data to include in the spreadsheet. The file must be in SYSBASE.
- spreadsheet-type
- A character string containing the type of spreadsheet to generate. The supported values are csv, ods, txt, xls, and xlsx. These values must be provided in lower case.
- column-headings
- A character string that specifies whether a heading row is included in the spreadsheet result.
- COLUMN
- The column names are used as the heading.
- LABEL
- The column labels are used as the heading. If no column label exists, the column name is used.
- NONE
- No heading row is returned. This is the default.
Note
This function is provided in the SYSTOOLS schema as an example of invoking a Qshell command from within an SQL scalar function. Similar to other Db2® for i provided tools within SYSTOOLS, the SQL source can be extracted and used as a model for building similar helper functions, or to create a customized version within a user-specified schema.
Services provided in SYSTOOLS have authorization requirements that are determined by the interfaces used to implement the service. To understand the authority requirements, extract the SQL for the service and examine the implementation.
Example
- Create a spreadsheet that contains the data from
MYLIB/A.
VALUES SYSTOOLS.GENERATE_SPREADSHEET( PATH_NAME => '/usr/fileA_spreadsheet', FILE_NAME => 'A', LIBRARY_NAME => 'MYLIB');
- Create a spreadsheet that contains the data from a query. Return column names in the first row
of the spreadsheet.
VALUES SYSTOOLS.GENERATE_SPREADSHEET( PATH_NAME => '/usr/query_spreadsheet', SPREADSHEET_QUERY => 'select order_number, customer, balance from orders where shipped = ''YES''', COLUMN_HEADINGS => 'COLUMN');