hssfcgi- a simple way to create spreadsheets with · pdf filea simple way to create...

20
Last modified on 01/16/2016 HSSFCGI A simple way to create Spreadsheets with HSSFR4 by Giovanni B. Perotti (Italy) About it Prerequisites Installation Maintenance HTTP instance The XLSGEN language The nasty question Why using an XML document to create a spreadsheet via HSSF POI Java classes? Excel natively supports XML documents as spreadsheets. Why not create a spreadsheet directly from an XML document, and skip POI altogether? Excel native support for XML documents is simply horrible. One may spend days without obtaining anything. Diagnostic is ridiculous. This is why we'd rather develop a simplifying interface to it. See our utility XLSCGI. Excel native support for XML documents starts with MS Office 2003, previous versions are not supported. HSSF POI is reported to support Microsoft Office from 1997 version on. Excel native support for XML documents does not include any graphic support (pictures). HSSF POI does. 1-About it From Wikipedia: Apache POI, a project run by the Apache Software Foundation, and previously a sub-project of the Jakarta Project, provides pure Java libraries for reading and writing files in Microsoft Office formats, such as Word, PowerPoint and Excel. A subcomponent of this project is HSSF. Wikipedia: HSSF (Horrible SpreadSheet Format) – reads and writes Microsoft Excel (XLS) format files. It can read files written by Excel 97 onwards; this file format is known as the BIFF 8 format. (As the Excel file format is complex and contains a number of tricky characteristics, some of the more advanced features cannot be read. For example, POI is unable to open spreadsheets that have filters or views.) In the last few years (2004 to 2010), Scott Klement has developed and maintained some free System i ILE-RPG service program, named HSSFR4. By interfacing HSSF POI Java classes, HSSFR4 offers facilities (ILE-RPG subprocedures) to create even complex Excel spreadsheets. In this way, it is now possible to have - on IBM i - ILE-RPG programs creating Excel spreadsheet. Information about HSSFR4 can be found in a Scott Klement's presentation (PDF) going through several articles by Scott, that I have collected. In addition to HSSFR4 subprocedures, you can develop your ones by referring to the Developers' Guide to HSSF and XSSF page. Learn how to do it from Scott's HSSFR4 prototypes. In April 2009, after trying with success Scott Klement's HSSFR4, I came to the following conclusion: Interfacing HSSFR4 directly from an ILE-RPG program, in order to create a given spreadsheet - though results may be impressive - requires some medium-high programming ability and may need some relevant debugging effort. XLSGEN language I then decided to develop an XML-like language able to support spreadsheet creation. It would be interpreted by an ILE-RPG program, providing the necessary interfaces to HSSFR4 subprocedures. Though supporting only some of the most common HSSFR4 subprocedures, this language would allow: To quickly create manually an XML-like script able to generate a prototype spreadhsheet, useful in verifying development assumptions. 1. Once satisfied by the manual XML-like script, to write a rather conventional program on the IBM i that would generate such XML-like script and would call the script interpreter. 2. Worth to be noted that such conventional spreadsheet-creating program could be written in any language available on the IBM i, such COBOL, RPG, C and even ... Java. 3. Such an XML-like language is now available, it is named XLSGEN and is interpreted through command HSSFCGI/XLSGEN. While in the next pages we provide details on this language, you may immediately get some ideas about it by running the following examples: spreadsheet created from this XLSGEN XML-like script 1.xls 1.txt 2.xls 2.txt TABLEXLS command Using the XLSGEN language, a general purpose command, named TABLEXLS, has been developed. This command allows to generate an XLS (Microsoft Office 2003) or XLSX (Microsoft Office 2007) Excel spreadsheet from any database file. This command can be run in interactive mode, in batch mode and ... even from a WEB browser. Important notes All the following are free of charge and are loaded on the IBM i during installation of library HSSFCGI: POI Java classes HSSFR4 service programs, both the version for POI 3.2 (Excel 2003) and the version for POI 3.6 (Excel 2007). XLSGEN interpreter 1. HSSF allows to imbed pictures in a spreadsheet. Once imbedded, the images are "hard-coded" in the spreadsheet, and do not need to reference the original images. HSSFR4 supports this feature. So does XLSGEN. 2. 2-Prerequisites Compiler ILE RPG IV, product 57xxWDS, opt. 31 - Necessary to install the product and to run command XLSTABLE. Library QSYSINC, product 57xx-SS1, opt. 13 - Necessary to build Scott Klement's service program HSSFR4. Library QSHELL, product 57xx-SS1, opt. 30 Library QPASE, product 57xx-SS1, opt. 33 If you want to create just XLS (Office 2003) Excel spreadsheets, you need Microsoft Office 2003 or subsequent OS/400 release V5R3 or subsequent Library QJAVA, product 57xx-JV1, opt. 6 ( Java 1.4) or opt. 7 ( Java 1.5) or subsequent. If you want to create also XLSX (Office 2007) Excel spreadsheets, you need Microsoft Office 2007 or subsequent OS/400 release V5R4 or subsequent Library QJAVA, product 57xx-JV1, opt. 7 ( Java 1.5) or subsequent. For more information on IBM i 57xxJV1 product options vs OS/400 releases, see this page. HSSFCGI Developer Guide 1

Upload: dinhduong

Post on 06-Mar-2018

322 views

Category:

Documents


13 download

TRANSCRIPT

Page 1: HSSFCGI- A simple way to create spreadsheets with · PDF fileA simple way to create Spreadsheets with HSSFR4 by Giovanni B. Perotti(Italy) About it Prerequisites Installation ... Library

Last modified on 01/16/2016

HSSFCGIA simple way to create Spreadsheets with HSSFR4

by Giovanni B. Perotti (Italy)

About itPrerequisitesInstallationMaintenanceHTTP instanceThe XLSGEN language

The nasty question

Why using an XML document to create a spreadsheet via HSSF POI Java classes? Excel natively supportsXML documents as spreadsheets. Why not create a spreadsheet directly from an XML document, and skip POIaltogether?

Excel native support for XML documents is simply horrible. One may spend days without obtaininganything. Diagnostic is ridiculous. This is why we'd rather develop a simplifying interface to it. See ourutility XLSCGI.Excel native support for XML documents starts with MS Office 2003, previous versions are notsupported. HSSF POI is reported to support Microsoft Office from 1997 version on.Excel native support for XML documents does not include any graphic support (pictures). HSSF POIdoes.

1-About it

From Wikipedia: Apache POI, a project run by the Apache Software Foundation, and previously a sub-project of the Jakarta Project, provides pure Java librariesfor reading and writing files in Microsoft Office formats, such as Word, PowerPoint and Excel.

A subcomponent of this project is HSSF.Wikipedia: HSSF (Horrible SpreadSheet Format) – reads and writes Microsoft Excel (XLS) format files. It can read files written by Excel 97 onwards; this file format isknown as the BIFF 8 format.(As the Excel file format is complex and contains a number of tricky characteristics, some of the more advanced features cannot be read. For example, POI is unable to open spreadsheets that have filters orviews.)

In the last few years (2004 to 2010), Scott Klement has developed and maintained some free System i ILE-RPG service program, named HSSFR4.By interfacing HSSF POI Java classes, HSSFR4 offers facilities (ILE-RPG subprocedures) to create even complex Excel spreadsheets. In this way, it is now possible tohave - on IBM i - ILE-RPG programs creating Excel spreadsheet.Information about HSSFR4 can be found

in a Scott Klement's presentation (PDF)going through several articles by Scott, that I have collected.

In addition to HSSFR4 subprocedures, you can develop your ones by referring to the Developers' Guide to HSSF and XSSF page. Learn how to do it from Scott'sHSSFR4 prototypes.

In April 2009, after trying with success Scott Klement's HSSFR4, I came to the following conclusion:Interfacing HSSFR4 directly from an ILE-RPG program, in order to create a given spreadsheet - though results may be impressive - requires somemedium-high programming ability and may need some relevant debugging effort.

XLSGEN languageI then decided to develop an XML-like language able to support spreadsheet creation. It would be interpreted by an ILE-RPG program, providing the necessaryinterfaces to HSSFR4 subprocedures.Though supporting only some of the most common HSSFR4 subprocedures, this language would allow:

To quickly create manually an XML-like script able to generate a prototype spreadhsheet, useful in verifying development assumptions.1. Once satisfied by the manual XML-like script, to write a rather conventional program on the IBM i that would generate such XML-like script and wouldcall the script interpreter.

2.

Worth to be noted that such conventional spreadsheet-creating program could be written in any language available on the IBM i, such COBOL, RPG,C and even ... Java.

3.

Such an XML-like language is now available, it is named XLSGEN and is interpreted through command HSSFCGI/XLSGEN.While in the next pages we provide details on this language, you may immediately get some ideas about it by running the following examples:

spreadsheetcreated fromthis XLSGEN

XML-like script1.xls 1.txt2.xls 2.txt

TABLEXLS commandUsing the XLSGEN language, a general purpose command, named TABLEXLS, has been developed.This command allows to generate an XLS (Microsoft Office 2003) or XLSX (Microsoft Office 2007) Excel spreadsheet from any database file.This command can be run in interactive mode, in batch mode and ... even from a WEB browser.

Important notesAll the following are free of charge and are loaded on the IBM i during installation of library HSSFCGI:

POI Java classesHSSFR4 service programs, both the version for POI 3.2 (Excel 2003) and the version for POI 3.6 (Excel 2007).XLSGEN interpreter

1.

HSSF allows to imbed pictures in a spreadsheet. Once imbedded, the images are "hard-coded" in the spreadsheet, and do not need to reference the originalimages. HSSFR4 supports this feature. So does XLSGEN.

2.

2-Prerequisites

Compiler ILE RPG IV, product 57xxWDS, opt. 31 - Necessary to install the product and to run command XLSTABLE.Library QSYSINC, product 57xx-SS1, opt. 13 - Necessary to build Scott Klement's service program HSSFR4.Library QSHELL, product 57xx-SS1, opt. 30Library QPASE, product 57xx-SS1, opt. 33If you want to create just XLS (Office 2003) Excel spreadsheets, you need

Microsoft Office 2003 or subsequentOS/400 release V5R3 or subsequentLibrary QJAVA, product 57xx-JV1, opt. 6 (Java 1.4) or opt. 7 (Java 1.5) or subsequent.

If you want to create also XLSX (Office 2007) Excel spreadsheets, you needMicrosoft Office 2007 or subsequentOS/400 release V5R4 or subsequentLibrary QJAVA, product 57xx-JV1, opt. 7 (Java 1.5) or subsequent.

For more information on IBM i 57xxJV1 product options vs OS/400 releases, see this page.

HSSFCGI Developer Guide

1

perotti
Highlight
Page 2: HSSFCGI- A simple way to create spreadsheets with · PDF fileA simple way to create Spreadsheets with HSSFR4 by Giovanni B. Perotti(Italy) About it Prerequisites Installation ... Library

Warning on 57xxJv1 - Make sure to have installed the last PTF cumulative for 57xxJV1 !!!

3-Installation

Remove any POI-related and any XLPARSE-related objects from /QIBM/UserData/Java400/ext. Adding such Java objects to this directory is a bad practiceand should be discontinued.If you already installed a previous version of library HSSFCGI, rename it HSSFCGIOLD.You may delete library HSSFCGIOLD upon successful installation of the new version of library HSSFCGI.Download file hssfcgi.zip from the Easy400 download page and unzip it.Follow the Readme.txt instructions to upload and to restore library HSSFCGI.On the iSeries run the following procedure:STRREXPRC SRCMBR(INSTALL) SRCFILE(HSSFCGI/QREXSRC)It does the following:

creates Scott Klement's service program HSSFR4_1 (POI 3.2), service program HSSFR4_2 (POI 3.6) and related demos in library HSSFCGI.Sources are stored in source files HSSFCGI/QRPGLESRC1 and HSSFCGI/QRPGLESRC1creates programs XLSGEN (the XLSGEN interpreter) and TABLEXLScreates XLSGEN demo programs GUB and FAMACCcreates and populates library HSSFCGIDTA (used to store your TABLEXLS data)restores IFS directory /hssfcgi, which includes Java classes for POI 3.2, POI 3.6, etc.displays the HTTP directives that you may install on an Apache HTTP instance of yours.[You may later on display again this HTTP directives with commandDSPF STMF('/HSSFCGI/apache/http_directives.txt') ]

To validate the installation, run commandHSSFCGI/VALIDATE.If the validation is successful, message "HSSFCGI installation was validated" is displayed.

Note 1- Replicating HSSFCGI installation on other boxesInstead of repeating the installation procedure, you may just restore libraries HSSFCGI and HSSFCGIDTA. You must then run command HSSFCGI/INSTALL to completethe setup.

Note 2- Installing HSSFCGI on production boxes without ILE-RPG compilerDo as described in Note 1. However, as the ILE-RPG compiler is not available, on the production box you cannot use command TABLEXLS to create Excelspreadsheets from other database files.New TABLEXLS-generated Excel spreadsheets should be created on a development box equipped with the ILE-RPG compiler and exported to the production box bysaving and restoring library HSSFCGIDTA (this job is faster carried out using our utility ODF (Object Distribution Facility)).

4-Maintenance

This utility is maintained on request, both for applying fixes and for adding enhancements.Send your requests to the author.To know what is new, just take a look at its Change Log.

5-HTTP instance

HTTP INSTANCEIn case where

you do not want to modify an exsiting HTTP instance, oryou prefer to have a separate HTTP instance to run this utility, oryou have no experience in handling HTTP instances

you may follow our instructions to create an HTTP instance named HSSFCGI.It listens on port 8016.Its configuration directives are in the IFS stream file /hssfcgi/conf/httpd.conf .This is how you create and use this HTTP instance:

run the following command to create the HTTP instance HSSFCGI (which listens on port 8016):CPYF FROMFILE(HSSFCGI/QATMHINSTC) TOFILE(QUSRSYS/QATMHINSTC) FROMMBR(HSSFCGI) TOMBR(HSSFCGI) MBROPT(*REPLACE) CRTFILE(*YES)

i.

run the following command to start the HTTP instance HSSFCGI:STRTCPSVR *HTTP HTTPSVR(HSSFCGI)

ii.

to run TABLEXLS, use the following URL:http://...:8016/tablexls

iii.

1.

RESTRICTING THE ACCESS TO THIS UTILITYThe last group of HTTP directives in IFS stream file /hssfcgi/conf/httpd.conf performs user validation vs the system user profiles. This is a convenient way ofrestricting the access to the user profiles having the proper rights for accessing a given database file.

However, if you do not like to enable all user profiles to access TABLEXLS, you may decide to use instead a validation list in order to restrict the access to agiven set of user names.This is how you do it:

Create a validation listCRTVLDL VLDL(QGPL/xxx) AUT(*EXCLUDE)GRTOBJAUT OBJ(QGPL/xxx) OBJTYPE(*VLDL) USER(QTMHHTTP QTMHHTP1) AUT(*USE)where xxx is the name of your validation list

i.

Use HTTP instance ADMIN to add/update entries to this validation listSTRTCPSVR SERVER(*HTTP) HTTPSVR(*ADMIN)http://...:2001click link IBM Web Administration for iSeriespress the Advanced tabpress the Internet Users and Groups tabselect one of the following:

Add Internet UserChange Internet User PasswordDelete Internet User

specify your validation list asl ibrary_name/validation_list_name

ii.

From a 5250 session enter commandEDTF '/hssfcgi/conf/httpd.conf'to update the HSSFCGI HTTP instance configuration file, and replace the last group of directives as follow:# The following group of directives is for user validation vs the system user profiles<LocationMatch (^/hssfcgip/(.*)$|^/tablexls$)>AuthType BasicAuthName "HSSFCGI reserved tools"PasswdFile QGPL/XXXUserID YYYRequire valid-user</LocationMatch>where

XXX is the name of your validation listYYY is the name of an user profile of your choice.User profiles QTMHHTTP and QTMHHTP1 should be granted for its *USE.

iii.

Restart the HSSFCGI HTTP instance:STRTCPSVR SERVER(*HTTP) RESTART(*HTTP) HTTPSVR(HSSFCGI)

iv.

2.

HSSFCGI Developer Guide

2

perotti
Highlight
Page 3: HSSFCGI- A simple way to create spreadsheets with · PDF fileA simple way to create Spreadsheets with HSSFR4 by Giovanni B. Perotti(Italy) About it Prerequisites Installation ... Library

Last modified on 01/24/2016 19:50:21

HSSFCGIThe XLSGEN language

The XLSGEN commandA prototypeThe XLSGEN syntaxMore on ...Large worksheetsError recordingCreating an XLS/XLSX stream file from a program

The XLSGEN command

The XLSGEN language is a rather simple XML-like language, that allows to generate XLS or XLSX Excel spreadsheets.

The XLSGEN script must be done in an IFS stream file and input-ed either to command HSSFCGI/XLSGEN:

XLS generator (XLSGEN) Type choices, press Enter.

Input XML stream file . . . . . INPSTMF Output XLS stream file . . . . . OUTSTMF Add Sheets to existing WkBook . ADDTO *NO *NO, *YES Decimal positions . . . . . . . DECPOS *AUTO 0-9, *AUTO, *NOC Display zero values . . . . . . ZERODSP *YES *YES, *NO Format all date cells as . . . . CVTDATE *NO *NO, *MDY, *DMY, *YMD... Initial rows to be frozen . . . FROZEN 0 Number ColHdg background color . . . . HDGCOLOR *NONE Default cell colors: DFTCELLCOL Font color . . . . . . . . . . BLACK Background color . . . . . . . WHITE Cell border . . . . . . . . . . CELLBORDER *NO *NO, *YES, *COLOR, *FCOLOR... Failure recovery: RECOVERY Try to recover . . . . . . . . *NO *YES, *NO Max. cells per worksheet . . . 10000000 100000-99999999 Generate log . . . . . . . . . . LOG *NO *YES, *NO Run it in a submitted job . . . SBMJOB *NO *YES, *NO

Figure 1a - Command HSSFCGI/XLSGEN

or to command HSSFCGI/XLSXGEN:

XLSX generator (XLSXGEN) Type choices, press Enter.

Input XML stream file . . . . . INPSTMF Output XLSX stream file . . . . OUTSTMF Add Sheets to existing WkBook . ADDTO *NO *NO, *YES Decimal positions . . . . . . . DECPOS *AUTO 0-9, *AUTO, *NOC Display zero values . . . . . . ZERODSP *YES *YES, *NO Format all date cells as . . . . CVTDATE *NO *NO, *MDY, *DMY, *YMD... Initial rows to be frozen . . . FROZEN 0 Number ColHdg background color . . . . HDGCOLOR *NONE Default cell colors: DFTCELLCOL Font color . . . . . . . . . . BLACK Background color . . . . . . . WHITE Cell border . . . . . . . . . . CELLBORDER *NO *NO, *YES, *COLOR, *FCOLOR.... Failure recovery: RECOVERY Try to recover . . . . . . . . *NO *YES, *NO Max. cells per worksheet . . . 1300000 100000-99999999 Generate log . . . . . . . . . . LOG *NO *YES, *NO Run it in a submitted job . . . SBMJOB *NO *YES, *NO

Figure 1b - Command HSSFCGI/XLSXGEN

Input XML stream file (INPSTMF) - Specifies the XML-like XLSGEN scriptOutput XLS/XLSX stream fi le (OUTSTMF) - Provides the path and the name of the generated Excel spreadsheet. Extension .XLS or XLSX must be specified.Add Sheets to existing WkBook (ADDTO) - Specifies whether generated worksheets should be added to an existing workbook or to a new workbook. Enter:

*NO when the workbook does not already exist or must be re-created from scratch*YES to add the worksheet(s) to a workbook already existing.

Decimal positions (DECPOS) - Specifies the number of decimal positions to be assigned to numeric cells.If you specify a number from 0 to 9, all the numeric cells display that number of decimal positions. Thousand delimiters are displayed. If you specify *AUTO, eachnumeric cell displays the number of decimal positions specified in the input XML stream file (parameter INPSTMF). Thousand delimiters are displayed.*NOC (no commas) is the same as *AUTO, except that thousand delimiters are not displayed.Display zero values (ZERODSP) - Whether the numeric cells containing a value zero should display a zero or should display nothing. Select:

*YES (default value) to have the numeric cells containing a zero value displaying a zero*NO to have the numeric cells containing a zero value displaying nothing. This option is recommended when a large number of numeric cells may contain zerovalues, because this makes user reading much easier.

Format all date cells as (CVTDATE) - Use this parameter to format all the date cells of the spreadsheet in the same way. Leave *NO, if you want each date cell in thespreadsheet be formatted according to the related FORMAT parameter specified in the XLSGEN control statements.Initial rows to be frozen (FROZEN) - Use this parameter to establish the number of initial rows to be frozen.This parameter implements a "freeze pane".This tecnique may be used to keep steady the heading rows, while the data rows are scrolled. Very useful when handling spreadsheets with a large number of rows.Frozen rows are repeated in all print pages, thus providing a better understanding of column meanings.ColHdg background color (HDGCOLOR) - Use this parameter to select one from 47 colors (see Figure 6) to be used as background color of the text cells with type"column-header", or select *NONE to avoid using such a background color.Default cell colors (DFTCELLCOL) - Use this parameter to set the default colors (font and background) for the cells of the spreadsheet. Default cell colors do not affectcolumn header cells.Cell border (CELLBORDER) - Use this parameter to specify which cells should have borders. Enter:

*NO not to generate borders for any cells*YES to generate borders for all cells*COLOR to generate borders for cells having a background color other than WHITE or a foreground color other than BLACK*FCOLOR to generate borders for cells having a foreground color other than BLACK*BCOLOR to generate borders for cells having a background color other than WHITE.

Failure recovery (RECOVERY) - This parameter tells how the program behaves in case of failure.Program failures may be caused by improper XLSGEN script tags or by an excessive memory demand to the JVM when large worksheets are generated. This

HSSFCGI Developer Guide

3

perotti
Highlight
Page 4: HSSFCGI- A simple way to create spreadsheets with · PDF fileA simple way to create Spreadsheets with HSSFR4 by Giovanni B. Perotti(Italy) About it Prerequisites Installation ... Library

parameter is made of two elements:Try to recover - Specify *YES if you require the program to recover from a possible failure.a. Max. cells per worksheet - When *YES is specified for Recover, the program splits the workbook in multiple worksheets. Each worksheet contains the numberof cells specified in Max. cells per worksheet, rounded up to fill up the last worksheet row.Should then a failure occurr,

a workbook containing a number of worksheets - excluding the last one where the failure occurred - is made available, anda submitted batch job resumes the process with a new workbook starting with the worksheet where the failure occurred.Should a failure occur in the submitted batch job, the recovery scheme applies again.

The ultimate result could be a number of workbooks generated by several jobs.Please note that the original process does not end until the last job in the chain completes. The original process stays in place collecting and displaying (ifrunning in interactive mode) the messages sent from the jobs in the batch chain.

b.

Generate log (LOG) - If you specify LOG(*YES), log file XLSGENLOG is generated in library QTEMP. This log contains an entry for each generated worksheet cell. Incase of a failure, by displaying this log file you can easily establish which was the last spreadsheet cell generated successfully before the failure occurred.Run in a submitted job (SBMJOB) - If you specify SBMJOB(*YES), all the Java process is executed in a batch submitted job. In this way the settings of the Java VirtualMachine of the bach job cannot conflict with the JVM settings of the current job.

Note- Commands XLSGEN and XLSXGEN provide, for any generated worksheet, a record in file QTEMP/XLSGENRPT. For the record layout, see this page.Command HSSFCGI/RPTXLSGEN reads this file and provides a printout listing all the workbooks, with information about their sheets, generated from the current job.

Usually, an initial XLSGEN is written manually and input-ed to command XLSGEN or XLSGENX to create a prototype spreadsheet.

Subsequently, one may write a program thatgenerates the XLGEN script as an IFS stream file1. invokes comand XLSGEN or XLSGENX to generate an XLS or XLSX stream file from the XLGEN script2. if a CGI program, sends the XLS / XLSX stream file to the browser.3.

For details on such a program see the next page.

1-A prototype

Take a look at this spreadsheet prototype:

Figure 2 - A prototype spreadsheet

The following XLSGEN script was used for generating it:

<XML><workbook> <worksheet name="gumb" print-header="Giovanni's Used Boats" print-orientation="portrait" print-scale="110" paper-size="A4_PAPERSIZE"> <row row-height="40"> <cell hspan="2"> <data type="LargeTextC" valign="center"> GUMB - Giovanni's Used Motor Boats </data> </cell> </row> <row> <cell hspan="2"> <data type="SmallTextC" valign="center"> available in April 2016 </data> </cell> </row> <row> <cell hspan="2"> </cell> </row> <row row-height="100"> <cell> <data type="picture" width="187"> /hssfcgi/images/boatM01.jpg </data> </cell> <cell> <data type="text" valign="center"> 36' Solent Spear %LF Year: 2005%LF Current Price: £ 155,000 ... Single Diesel%LF </data> </cell> </row> <row row-height="100"> <cell> <data type="picture" width="187"> /hssfcgi/images/boatM02.jpg </data> </cell> <cell> <data type="text" valign="center"> 75' Riva Venere%LF Year: 2006%LF Current Price: EUR 2,850,000 ... Twin Diesel%LF </data> </cell> </row> </worksheet></workbook></XML>

Figure 3 - A script prototype

The following is what the interpreter (command HSSFCGI/XLSGEN or HSSFCGI/XLSXGEN) does:on tag <workbook> - starts a workbookon tag <worksheet name="gumb"> - starts a worksheet named "gumb"

HSSFCGI Developer Guide

4

Page 5: HSSFCGI- A simple way to create spreadsheets with · PDF fileA simple way to create Spreadsheets with HSSFR4 by Giovanni B. Perotti(Italy) About it Prerequisites Installation ... Library

on tag <header>Giovanni's Used Boats</header> defines a print header

on tag <row> - starts row 1on tag <cell hspan="2"> - creates logical cell 1AB, spanning the size of two physical cells (hspan means horizontal span)on tag <data type="LargeTextC"> - establishes a large centered font for the contents of cell 1ABthen writes the text "GUMB - Giovanni's Used Motor Boats" to cell 1ABon tag </data> ends writing to the cellon tag </cell> ends cell 1ABon tag </row> ends row 1.

Row 2 is similar to row 1. The font is now a small centered one.

Row 3 is similar to rows 1 and 2, but has no text.

The next logical row is made of two cells, both spanning 7 physical rows (row 4 to 10). This is done by specifying a vertical span keyword vspan="7" at cell level.The first cell contains a picture with an horizontal size (width) of 187 pixel, containing the image of a boat. The name of the IFS stream file containing the picture mustbe given in the data portion.The second cell contains a plain text, the description of a boat. Within the text you can see some %LF sequences. They are used to generate line feeds.

the next logical row is similar to the previous one.

2-The XLSGEN syntax

XLSGEN is a tag language similar to XML:A <tag> must always have a closing </tag>A tag may contain keywords. The syntax of a keyword is

keyword="value"The pair of double quotes (") is mandatory.Tag, keywords and keyword values are case insensitive.

The following table lists the keywords available for each tag.

tag keyword meaning commentsXML Used to be consistent with XML syntax. The interpreter ignores it.

WORKBOOK Starts a workbook A workbook is a set of worksheets.An XLS / XLSX file can contain just one workbook.

WORKSHEET Starts a worksheet

NAME="value" Name assigned to the worksheet Example:<worksheet name="2016">

PRINT-HEADER="page header text"

Worksheet print page header Example:<worksheet name="2016" print-header="Sales this year">

PRINT-ORIENTATION="PORTRAIT" or "VERTICAL" OR"LANDSCAPE" or "HORIZONTAL"

Worksheet print page orientation (♣) Example:<worksheet name="2016" print-header="Sales this year"print-orientation="landscape">

FIT-WIDTH=number of pages

Number of pages the width of the spreadsheet shouldbe compressed into. (♣)A value of 1 forces all columns to fit in the width of asingle page.

Example:<worksheet name="2016" print-header="Sales this year"print-orientation="landscape" fit-width="1">

FIT-HEIGHT=number of pages

Number of pages the height of the spreadsheet shouldbe compressed into. (♣)A value of 1 forces all rows to fit in the height of asingle page.

Example:<worksheet name="2016" print-header="Sales this year"print-orientation="landscape" fit-width="1" fit-height="1">This will fit the printout in a single page.

PRINT-SCALE=values from "10" to "400"

Worksheet print page scaling percentage (♣)This keyword is ignored when a FIT-... keyword isspecified.

Example:<worksheet name="2016" print-header="Sales this year"print-orientation="landscape" print-scale="120">

PAPER-SIZE="one of 33 possible values"(DSPPFM HSSFCGI/PAPERSIZES)

Worksheet page size (♣) Example:<worksheet name="2016" print-header="Sales this year"print-orientation="landscape" print-scale="120"paper-size="A4_PAPERSIZE">

ROW Starts a row Examples:<row><row row-height="90"><row page-break>

ROW-HEIGHT="number of points" Sets the height (in points) of this row

PAGE-BREAK Generates a print page break before this row (♣)

CELL Starts a cell Examples:<cell><cell border><cell hspan="2" vspan="7"><cell hspan="2" vspan="7" overlay><cell cell-width="150">

BORDER Add borders to this single cell

HSPAN="value" Number of cells that should be horizontally spanned(merged into this cell)

VSPAN="value" Number of cells that should be vertically spanned(merged into this cell)

OVERLAY To be used only when VSPAN="value greater than 1"to allow the spanned rows to contain also other cells.See Figure 5.

CELL-WIDTH="value" Allows to size the width of a cell to a given number ofpixels. See the example on your right. Maximum widthis 889 pixels. It does not work when HSPAN is alsospecified.

DATA Defines type and format of cell data

TYPE="value" Possible values:COLUMN-HEADER - centered small textTEXT - left aligned standard textTEXTC - centered standard textTEXTR - right aligned standard textLARGETEXT - left aligned large characterstextLARGETEXTC - centered large characterstextLARGETEXTR - right aligned largecharacters textSMALLTEXT - left aligned small characterstextSMALLTEXTC - centered small characterstextSMALLTEXTR - right aligned smallcharacters textNUMBER - right aligned numberLARGENUMBER - right aligned largecharacters numberDATE - centered datePICTURE - imageFORMULA - Excel valid formulaDefines a formula to be computed by Excel.The expression defining the formula mustbe given between <data ... > and </data> .

Examples:<data type="largeTextC" wrap><data type="number"><data type="date" format="mdy"><data type="picture" width="187"><data type="formula">

HSSFCGI Developer Guide

5

Page 6: HSSFCGI- A simple way to create spreadsheets with · PDF fileA simple way to create Spreadsheets with HSSFR4 by Giovanni B. Perotti(Italy) About it Prerequisites Installation ... Library

Example:<data type="formula"> sum(a1:b1)</data>Note. Hyperlinks are supported as formulaspecial cases.

VALIGN="value" Defines the vertical alignment.Possible values:

TOPtop-aligned vertical alignmentCENTERcenter-aligned vertical alignmentBOTTOMbottom-aligned vertical alignmentJUSTIFYvertically justified vertical alignment

Example:<data type="largeTextC" valign="center">

F-COLOR="value" Defines the font color of a cell(except for <data type="column-header" ...>).The available font colors are listed in Figure5.

Example:<data type="number" f-color="blue">

B-COLOR="value" Defines the background color of a cell.(except for <data type="column-header" ...>).The available background colors are listed in Figure5.

Example:<data type="number" f-color="blue" b-color="gold">

FORMAT="value" Defines the format of a date spreadsheet cell.Possible values:

cell format*MDY mm/dd/yy

*DMY dd/mm/yy*DMYY dd/mm/yyyy

*YMD yy/mm/dd

*YYMD yyyy/mm/dd*ISO yyyy-mm-dd

*USA mm/dd/yyyy

*EUR dd.mm.yyyy*JIS yyyy-mm-dd

*JUL yyyy-nnn

Example:<data type="date" format="mdy">

WIDTH="value" Defines the width of a picture, in pixel. Example:<data type="picture" width="187">

BOLD Applies to text, date, number and formula data types. Itassigns a bold weight to the font.

Examples:<data type="text" bold><data type="largeTextC" bold><data type="number" bold>

UNDERLINE Applies to text, date, number and formula data types. Itunderlines the cell data.

Examples:<data type="text" underline><data type="text" bold underline>

ITALIC Applies to text, date, number and formula data types. Itsets the cell data to i tal ic types.

Examples:<data type="text" italic><data type="text" underline italic>

WRAP Applies only to the text data types. It tells whether thetext string can be folded (wrapped).

Example:<data type="largeTextC" wrap>

(data value) Data value must be written between the tag <data ... > and the tag </data> .Figure 4 - Tags and keywords

Figure 5 - Effect of the OVERLAY keyword(<cell hspan="3" vspan="7" overlay>)See the sample XLSGEN stream file /hssfcgi/tmp/zzz.xml .

3-More on ...Some special charactersCharacters < and > cannot be used within a text cell (COLUMN-HEADER, TEXT, LARGETEXT(C), SMALLTEXT(C)), as these two characters are used as delimiters.Specifying these characters whithin a text cell will cause XLSGEN to provide unpredictable results.Should you, however, need these characters within a text string, you may use their corresponding HTML entities:

&lt; (less than) instead of character <&gt; (greater than) instead of character >

Folding (wrapping) character stringsThere are two ways to fold character strings:

Using keyword WRAP. In this case Excel decides where the folding should take place, depending on the column width.1. Inserting line-feed sequences %LF in the text string. In this case Excel adjusts the column width on the length of the longest text segment.2.

These two techniques may be combined.Example:

<data type="text" wrap>Like as the waves make towards the pebbled shore,%LFSo do our minutes hasten to their end</data>

NUMBERSNumeric values are represented as follow:

<data type="number">numeric_value

</data>and must have been edited with edit code J, L, N or P.Examples of numeric_values:

editcode

englishlanguage

italianlanguage

J 1,234,567.89- 1.2334.567,89-

HSSFCGI Developer Guide

6

Page 7: HSSFCGI- A simple way to create spreadsheets with · PDF fileA simple way to create Spreadsheets with HSSFR4 by Giovanni B. Perotti(Italy) About it Prerequisites Installation ... Library

L 1234567.89- 12334567,89-N -1,234,567.89 -1.2334.567,89P -1234567.89 -12334567,89

Note on decimal point and thousand separator characters:Decimal point and thousand separator characters (if used) must be consistent with system value QDECFMT.Inconsistent decimal points and/or thousand separator characters result to wrong value interpretation.Thousand separator characters can be used, but are not required.

DATESDates must always be written in the ISO format YYYY-MM-DD.The desired date format for the resulting spreadsheet date cell must be specified by the keyword FORMAT=xxx .Example:

<data type="date" format="mdy">2009-04-23

</data>FORMULAS

Any formulas supported by Excel 2003 can be used. Example:<data type="formula">AVERAGE(B34:J34)

</data>Warnings:

If for any reason POI finds out that a formula cannot be supported, you will receive the following message when running XLSGEN:The call to HSSF_FORMU ended in error (C G D F)

a.

For Excel formulas see this page.b. Besides, XLSGEN includes the following commands to generate Excel formulas:

VSUM - Tells Excel to compute the sum of the numbers from the preceding numeric cells in the same column.1. HSUM - Tells Excel to compute the sum of the numbers from the preceding numeric cells in the same row.2. VAVG - Tells Excel to compute the average of the numbers from the preceding numeric cells in the same column.3. HAVG - Tells Excel to compute the average of the numbers from the preceding numeric cells in the same row.4. XVSUM - Tells Excel to compute the sum of the preceding VSUM cells in the same column.This allows to obtain a grand total from the preceding subtotals in the same column.This technique is demonstrated in the HSSFCGI CGI program XVSUMTRY.

5.

Example of using one of the above formula commands:<data type="formula">vsum</data>

Note 1: About "noclear" parameter.Once a VSUM, HSUM, VAVG or HAVG command has been processed, as a rule it is no longer possible to refer - through one ofsuch commands - to the preceding numeric cells in the same column or row, unless parameter noclear is specified.Example - Suppose that for a cell of a given column and a given row you specify

<data type="formula">vsum noclear</data>

and in the cell of the next row and the same column you specify<data type="formula">vavg</data>

In this way you have the vertical sum of the numbers from the preceding numeric cells in that column, and in the next row you havethe vertical average of the same data.Note 2: About "store" parameter.As a rule, numeric formula cells generated from VSUM, HSUM, VAVG and HAVG commands are not eligible to partecipate in asubsequent VSUM, HSUM, VAVG or HAVG command.Should you however need to VSUM or HSUM a series of previously defined VSUM, HSUM, VAVG or HAVG cells, you can do it,provided that those preceding VSUM, HSUM, VAVG or HAVG cells do specify parameter store as in this example:

<data type="formula">vsum store</data>

The following picture summarizes the case:numeric cell numeric cell ... numeric cell formula cell: HSUM storenumeric cell numeric cell ... numeric cell formula cell: HSUM store

... ... ... ... ...numeric cell numeric cell ... numeric cell formula cell: HSUM store

formula cell: VSUM formula cell: VSUM ... formula cell: VSUM formula cell: VSUMNow, the last VSUM cell does perform the vertical sum of the preceding cells in its column, just because they specify store in theirHSUM formula.This case is demonstrated in the HSSFCGI CGI program XVSUMTRY.

Parameter dec-pos="n" (n = 0 to 9) can be used to establish the number of decimal positions in the result of a formula. Example:<data type="formula" dec-pos="3"> sum(b1:b6)</data>

In absence on this parameter, the number of decimal positions is inherited from the previous numeric cells.HyperLinks are supported as formula special cases.The syntax to be used is as follow:

<data type="formula"> hyperlink("link","text")</data>

wherelink can be

an url link, example: http://www.easy400.neta mail l ink, example: mailto:[email protected] fi le l ink, example: c:\i386\blank.txt

text is the text to be linked, example:<data type="formula"> hyperlink("http://www.easy400.net","Easy400 home page")</data>

To set the width of a column containing formulas, use<cell cell-width="nnn"> (where nnn is the desired number of pixels)

in at least one cell of that column (for instance, in the column header cell).PICTURESPicture support is an uniqueness within HSSF. Pictures are copied into the workbook. In this way, they can be exported with the XLS / XLSX file itself.Warning - Only PNG and JPEG (jpg) pictures are supported.Some care should be paid in order to avoid picture distorsion. Some tips:

Picture height.This should be cared first.In the <row ...< tag specify a ROW-HEIGHT value (in points) for the desired height of the picture.

i.

Picture width.Make sure that a column containing pictures does not contain anything else. Column widths are set by the largest contents, and you need the width of thiscolumn to be under your control, to avoid picture distorsions.Specify the desired picture width in points through keyword WIDTH at <data ... > level.Example:

<row row-height="100"><cell> <data type="picture" width="187"> /hssfcgi/images/boatM01.jpg </data></cell>

ii.

Picture resizing and relocating.You may tell how a picture should behave when the related column width is changed, or when a new row or column is inserted.The anchor parameter establishes the picture behavior:

<data type="picture" anchor="move">

iii.

HSSFCGI Developer Guide

7

Page 8: HSSFCGI- A simple way to create spreadsheets with · PDF fileA simple way to create Spreadsheets with HSSFR4 by Giovanni B. Perotti(Italy) About it Prerequisites Installation ... Library

This is the default behavior: ifthe column size is changed, ora new column or a new row is added

the picture maintains its size and the picture row and column are relocated.<data type="picture" anchor="movesize">

Ifthe column size is changed, ora new column or a new row is added

the picture size is changed to fit the cell size and the picture row and column are relocated.<data type="picture" anchor="fixed">

Ifthe column size is changed, ora new column or a new row is added

the picture maintains its absolute position and size.CELL COLORSThe are four different ways to assign colors (font colors and background colors) to spreasheet cells.

Automated fontsCells with <data type="Formula">HSUM</data> (horizontal sum) andcells with <data type="Formula">HAVG</data> (horizontal average)are assigned a brown font.Cells with <data type="Formula">VSUM</data> (vertical sum) andcells with <data type="Formula">VAVG</data> (vertical average)are assigned a royal_blue font.Cells with <data type="Formula">formula_expression</data>are assigned an indigo font.

If - in commands XLSGEN, XLSXGEN or TABLEXLS - parameter DFTCELLCOL specifies other than (BLACK WHITE), these cells are handled as any other cell inthe spreadsheet (also they do receive the default font color and the background color specified in parameter DFTCELLCOL).

1.

Column headersIn the XLSGEN language, column headers are identified from the <data type="Column-Header"> .In commands XLSGEN, XLSXGEN and TABLEXLS, parameter HDGCOLOR allows to specify one out of 47 (see Figure 6) background colors to be assigned tothe column header cells. The font color is automatically assigned: black for light background colors, white for dark background colors.

2.

Default cell colorsIn commands XLSGEN, XLSXGEN and TABLEXLS, parameter DFTCELLCOL allows to specify a given font color and a given background color to be used for allspreahsheet cells, except the column heading ones. If default values (BLACK WHITE) are selected, no special action is taken.

3.

XLSGEN language parameters f-color and b-colorThese parameters can be used in a XLSGEN script to set the font color (f-color) and the background color (b-color) of a given cell.As an example, the following:

<cell> <data type="number" f-color="blue" b-color="gold"> 2982 </data></cell>

generates the following spreadsheet cell:

2,982 Note that cells like this retain their colors also when default cell colors are assigned through parameter DFTCELLCOL in command XLSGEN or XLSXGEN.

4.

Aqua Dark_red Lavender Olive_green Sea_greenBlack Dark_teal Lemon_chiffon Orange Sky_blueBlue Dark_yellow Light_blue Orchid TanBlue_grey Gold Light_cornflower_blue Pale_blue TealBlue_green Green Light_green Turquoise violetBrown Grey_25_percent Light_orange Pink WhiteCoral Grey_40_percent Light_turquoise Plum YellowCornflower_blue Grey_50_percent Light_yellow RedDark_blue Grey_80_percent Lime RoseDark_green Indigo Maroon Royal_blue

Figure 6 - Supported cell colorsCELL STYLESCell styles are established from DATA parameters TYPE, F-COLOR, B-COLOR, BOLD and UNDERLINE.The number of supported cell styles for a workbook are 10,064:

64 of these styles are program-defined values and are related to different values of the TYPE parameter.The remaining 10,000 styles are left for user definition in the XML-like stream file input to XLSGEN.A user-defined style can be implemented combining a pre-defined style with foreground colors, background-colors and optionally the "bold" and/or the "underline"keywords.Example of a user-defined style: <data type="largenumber" f-color="blue" b-color="gold" bold>where:

type defines a pre-defined stylef-color defines a foreground colorb-color defines a background colorbold provides a bold font weight.

When the input stream file contains more than 10,000 user-defined cell styles, a warning message appears in the joblog, and only the first 10,000 user-defined styles arehonored.

4-Large worksheets

Excel worksheets have some published limits. For instance:In MS Office 2003: 65,536 rows by 256 columnsIn MS Office 2010: 1,048,576 rows by 16,384 columns

However, you should not expect to reach those limits with our POI-based tools, because here we have to deal with JVM memory restrictions.We have developed a model of a large spreadsheet generator, based on a XLSGEN script that requires to generate a spreadsheet with 65,540 rows by 256 columns, totalling16,778,240 cells. All cells aree numeric, values range from 1 to 16,778,240.The experience is rather sad: while the XLSGEN program (MS Office 2003) was interrupted by memory problems after generating 13,556,925 cells, XLSXGEN (Ms Office 2010)was interrupted after generating just some 1,3 million cells (that is understandable, as MS Office 2003 is reported to have a far larger memory footprint than the 2003 one).

Therefore, trying to generate a huge worksheet, though it requires hours of computer time, may result just to a message likeJava exception "java.lang.OutOfMemoryError:" when calling method "createCell" ,a few dumps and ... no worksheet at all.

To overcome this problem, you should use parameter RECOVERY in command XLSGEN or XLSXGEN.By specifying RECOVERY(*YES), we were able to obtain - from our huge XLSGEN script -

from command XLSGEN ... RECOVERY(*YES 10000000)two workbooks, each with a single worksheet: one with 39,063 rows and the other with 26,477 rows,obtained from an initial job and one recovery job automatically submitted to batch.That was done in 11,5 hours on a 60x box running V6R1.from command XLXSGEN ... RECOVERY(*YES 1300000)13 workbooks, each with a single worksheet: 12 with 5,079 rows and the last one with 4,592 rows,obtained from an initial job and a chain of 12 batch jobs automatically submitted.That was done in 18.0 hours on a 60x box running V6R1.

It should be noticed that each memory error caused the program to stay inactive for about 30 minutes. During that time JVM was running 100% of CPU time and generating a lot ofdumps and other error reports both on spool files and on stream files. This explains the different duration (11.5 vs 18.0 hours) of our XLSGEN and XLSXGEN tests.

5-Error recording

When an XLSGEN or XLSXGEN process is interrupted by an error condition, understanding what happened is not a simple job. It may require to investigate joblog and dumps, the

HSSFCGI Developer Guide

8

Page 9: HSSFCGI- A simple way to create spreadsheets with · PDF fileA simple way to create Spreadsheets with HSSFR4 by Giovanni B. Perotti(Italy) About it Prerequisites Installation ... Library

XLSGEN script and the program source code.

There are three type of exceptions:Program errorsJava exceptions due to wrong tags in the XLSGEN scriptJava exceptions due to memory problems.

XLGEN and XLSGEN program code is clean enough and you should not expect any program errors from it.Java exceptions may be caused by incorrect XLSGEN tags, such as a formula that Excel would not accept.Java exceptions due to memory are caused by attempts to generate a too large workbook.

In order to provide the user with a quick problem determination tool, both XLGEN and XLSGEN have been added an error routine that records some basic error information on adatabase file.To display the error collection you just run command hssfcgi/dsperrs.

You receive a first screen listing all the errors collected in a time descending sequence (the most recent error is listed first). For each error you are displayed:The time when the error occurreda. The name of the workbook being created (parameter OUTSTMF)b. The name of the last worksheet saved in the workbookc. The total number of worksheet rows in the workbookd. The name of the worksheet being processed when the error occurrede. The number of the worksheet row being written when the error occurred (this is a row sequence number within the worksheet)f. The number of row-cell being written when the error occurred (this is a cell sequence number within the worksheet row)g. The absolute number of the row being written when the error occurred (this is a row sequence number within the workbook)h. The absolute number of the cell being written when the error occurred (this is a cell sequence number within the workbook)i.

- When items 1f and 1g are different from zero, most likely the error occurred while trying to write that specific cell. Either the cell contains an unsupported value, or amemory constraint did not allow the cell to be added.- When items 1f and 1g are both zero, most likely the error occurred while trying to add the worksheet to the workbook, and that is usually a memory problem (the workbookis too big).

1.

If you select the error with a 9, you are displayed a second screen telling you more:The procedure, RPG program and RPG module names. XLSGEN_1 and XLSGEN_2 are the programs run by command XLSGEN. XLSXGEN is the program run bycommand XLSXGEN.

a.

The number of the source statement in the RPG program module that was tried to be executed when the error occurred. This piece of information is generally for thedeveloper, unless you are willing to check the source code.

b.

The RPG IV routine that was in execution when the error occurred. This is generally the name of the Scott Klements HSSFR4 subprocedure invoked by the sourcestatement 2b (Scott Klements subprocedures are the ones interfacing Java). For instance, the name write refers to a subprocedure which writes the spreadsheet intothe workbook.The names hssf_text and ss_text refer to subprocedures that write a text cell into a spreadsheet row.The names hssf_num and ss_num refer to subprocedures that write a numeric cell into a spreadsheet row.The names hssf_date and ss_date refer to subprocedures that write a date cell into a spreadsheet row.The names hssf_formula and ss_formula refer to subprocedures that write a formula cell into a spreadsheet row.

c.

2.

6-Creating an XLS / XLSX stream file from a program

That is documented in the next page.

Footnotes(♣) Unluckily, keywords PRINT-ORIENTATION, FIT-WIDTH, FIT-HEIGHT, PRINTS-SCALE, PAPER-SIZE and BREAK work only for spreasheets with extension XLS (MS Office

2003), they do not work on spreadsheets with extension XLSX (MS Office 2007).

HSSFCGI Developer Guide

9

Page 10: HSSFCGI- A simple way to create spreadsheets with · PDF fileA simple way to create Spreadsheets with HSSFR4 by Giovanni B. Perotti(Italy) About it Prerequisites Installation ... Library

Last modified on 01/16/2016

HSSFCGICreate a spreadsheet from a program

Simple programmimngFacilities for CGIDEV2-based programsWorking with multiple Java frameworks

1-Simple programmimg

To write a program that generates a spreadsheet you do not have to know Java, nor you have to know ILE-RPG or the CGI techniques supported by CGIDEV2.

The only thing you have to do is to use your favorite programming language to build on the IBM i a program able to generate an IFS stream file containing an XLSGENscript.Once this is done, use command

xlsgen to generate the XLS spreadsheet as an IFS stream file, ORxlsxgen to generate the XLSX spreadsheet as an IFS stream file

and have it executed from EXCEL.

If you were able to do this manually, as a programmer you would love to have it done from a program.

2-Facilities for CGIDEV2-based programs

Of course, if you are an ILE-RPG programmer and expecially if you are trained to use CGIDEV2, then you will start smiling, because the next part of this page is foryou.

In HSSFCGI/QRPGLESRC there are three sample CGI programs providing teaching demos for this job:

The first sample program, named FAMACC (Family Accounting), reads a family-accounting data basefile to generate a single sheet workbook.Though pretty simple, it features HSUM, VSUM and VAVG formulas, plus a true Excel formula.

Press this link to have it generating a spreadsheet and sending it to your browserPress this link to display the XLSGEN script generated by this programPress this link to display the source of this program.

1.

The second sample program, named GUB (Giovanni's Used Boats), reads a boats-for-sale database file to come up with a two sheets workbook.The fun of it is that it features cells including pictures.

Press this link to have it generating a spreadsheet and sending it to your browserPress this link to display the printout from this spreadsheetPress this link to display the XLSGEN script generated by this programPress this link to display the source of this program.

2.

The third sample program, named XVSUMYTRY (XVSUM example), reads a sales summary database file and shows how to use XLGEN formulas VSUM andXVSUM to create subtotals and grand totals.

Press this link to have it generating a spreadsheet and sending it to your browserPress this link to display the XLSGEN script generated by this programPress this link to display the source of this program.

3.

Write your program following one or the other of the example programs:Use subprocedure GetHtmlIfs or GetHtmlIfsMult to load the external script /hssfcgi/html/standardXML.txt. Always use this script as a skeleton for yourXLSGEN script.

1.

Use subprocedures UpdHtmlvar and WrtSection to create the XLSGEN script in the output buffer.2. Use subprocedure WrtHtmlToStmf to create the XLSGEN-script IFS stream file.3. Use subprocedure ClrHtmlBuffer to clear the output buffer.4. Run command hssfcgi/xlsgen to interpret the XLSGEN-script and to generate the XLS or XLSX spreadsheet stream file.5. If running under HTTP, use subprocedure SndStmfToBrowser to send the XLS or XLSX spreadsheet stream file to the browser. SubprocedureSndStmfToBrowser is from service program hssfcgi/hssfcgix.

6.

Command WEBXLSGENIn writing you CGI program you may also take advantage of command HSSFCGI/WEBXLSGEN. This command is very similar to commands XLSGEN and XLSXGEN,but provides further functions:

Creates the XLS or XLSX stream file from the XML-like XLSGEN stream file (as commmands XLSGEN or XLSXGEN would do). Then, if running in a HTTPinstance, ...

a.

Sends the XLS or XLSX stream file to the browserb. Submits a job to delete the XLS/XLSX stream file after 5 minutes.(Note that it is a program responsibility to decide to delete the XML-like XLSGEN stream file.)

c.

Subprocedure GetColName()In your program creating the XLSGEN XML-like script, you may have the need specify in a formula some cell names in the way it is done by Excel. As an example, cellname AK82 would be the cell in column number 37 and row 82.Usually your program has full control on the column and row numbers. So, at a given point of your program you know that you are on row 82 and column 37. However,how do you convert 37 to the "AK" Excel notation?You do that with subprocedure GetColName(), example:

colName=GetColName(37) .See the sample program in HSSFCGI/QRPGLESRC member GETCOLNAME.

3-Working with multiple Java frameworks

Java environment variables CLASSPATH, QIBM_RPG_JAVA_PROPERTIES and JAVA_HOME must be set in a job before the Java Virtual Machine (JVM) is started.Trying to replace them after JVM has started, is no use.

This may cause problems when your program tries two use more than one Java framework.

As an example, let us assume that your programsets up the Java environment to use Scott Klement's JDBC framework to create a tablecreates the tabletries to run command HSSFCGI/TABLEXLS to generate a spreadsheet from that table.

Though command HSSFCGI/TABLEXLS tries to set up the Java environment by replacing the Java environment variables, this has no effect, as the JVM has alreadystarted, and command TABLESLS ... bumps out because unable to retrieve the needed Java classes.

There are two ways to solve this problem.

Setup a complete Java environment before starting the JVM .This approach requires that the Java environment variables are setup for all the Java frameworks used by the program before using the first framework. Thiscould be not so easy to be coded, as the environment variables needed by the HSSFCGI commands are hidden in a service program. However, your programmay use subprocedure Get_HSSFCGI_Java() to retrieve these environment variables. Source member SAMPLEJPGM in HSSFCGI/QRPGLESRC provides

A.

HSSFCGI Developer Guide

10

perotti
Highlight
Page 11: HSSFCGI- A simple way to create spreadsheets with · PDF fileA simple way to create Spreadsheets with HSSFR4 by Giovanni B. Perotti(Italy) About it Prerequisites Installation ... Library

the example of how to perform Java environment initialisation when using two frameworks, JDBC and HSSFCGI.Note- It should however be noted that once your program has started, the Java setup for the job can no longer be changed and that may prevent using otherJava-based programs in the same job.

Use SBMJOB(*YES) on HSSFCGI commands XLSGEN, XLSXGEN or TABLEXLS.If you specify parameter SBMJOB(*YES) on HSSFCGI commands XLSGEN, XLSXGEN or TABLEXLS, the Java part of the related program is executed in asubmitted batch job. This is done in a completely seamless way. By doing this, you cannot have conflicts between HSSFCGI Java setup and the Java setup ofyour job.Note- That does not completely solve the problem of having a JVM been started in your job, unless you provide a way to run also the other Java frameworks insubmitted jobs synchronized with your main job.

B.

HSSFCGI Developer Guide

11

Page 12: HSSFCGI- A simple way to create spreadsheets with · PDF fileA simple way to create Spreadsheets with HSSFR4 by Giovanni B. Perotti(Italy) About it Prerequisites Installation ... Library

Last modified on 01/16/2016 15:10:46

HSSFCGITABLEXLS: Create Excel workbooks from IBMi database files

In the previous pages we have describedA special XML-like script language that allows command XLSGEN to generate an XLS or XLSX Excel workbookHow you can produce such an XML-like script from a program.

As the next step, what about a general program that wouldread whatever database files1. generate from them an XLSGEN XML-like script2. invoke command XLSGEN or XLSXGEN to create an Excel workbook containing one or more spreadsheets ?3.

We have developed such a program for you in library HSSFCGI, and you can run it through command TABLEXLS.

Generate an XLS/XLSX from db files (TABLEXLS) Type choices, press Enter.

From database files . . . . . . FROMFILE Name Library . . . . . . . . . . . *LIBL Name, *LIBL + for more values

*LIBL From members . . . . . . . . . . FROMMBR *ALL Name, generic*, *FIRST, *ALL + for more values To .xml stream file . . . . . . TOXML *AUTO To .xls or .xlsx stream file . . TOXLS Add Sheets to existing WkBook . ADDTO *NO *NO, *YES Edit the .xml stream file . . . EDITXML *NO *YES, *NO Sheet names . . . . . . . . . . SHEETNAME *MBRNAME Name, *MBRNAME Paper size . . . . . . . . . . . PAPERSIZE A4_PAPERSIZE Header: PRTHDR 'Print header' . . . . . . . . *MBRTXT Show also on worksheet . . . . *YES *YES, *NO Print-orientation . . . . . . . PRTORIENT *PORTRAIT *PORTRAIT, *LANDSCAPE Print-fit: PRTFIT Sheet fit-width (nbr. pages) 0 0-99999 Sheet fit-height (nbr. pages) 0 0-99999 Print-scale . . . . . . . . . . PRTSCALE 100 10-400 Alternate Column Headings stmf ALTCOLHDG Frozen pane: FROZEN no. of frozen initial rows . . 1 0-99999 no. of frozen initial columns 0 0-99999 ColHdg background color . . . . HDGCOLOR *NONE Default cell colors: DFTCELLCOL Font color . . . . . . . . . . BLACK Background color . . . . . . . WHITE Cell border . . . . . . . . . . CELLBORDER *NO *NO, *YES, *COLOR, *FCOLOR... Decimal positions . . . . . . . DECPOS *AUTO 0-9, *AUTO, *NOC Display zero values . . . . . . ZERODSP *YES *YES, *NO Convert all date fields to . . . CVTDATE *NO *NO, *MDY, *DMY, *YMD... Ignore fields . . . . . . . . . IGNFLDS *NONE Name, *NONE + for more values HyperLink fields: LINKFLDS Link field . . . . . . . . . . Name Text field . . . . . . . . . . Name + for more values Display pictures . . . . . . . . PICTURES *NO *YES, *NO VSPAN for picture cells . . . . VSPAN 7 Number Pictures width in pixel . . . . WIDTH 187 Number Failure recovery: RECOVERY Try to recover . . . . . . . . *NO *YES, *NO Max. cells per worksheet . . . 10000000 100000-99999999 Generate log . . . . . . . . . . LOG *NO *YES, *NO Run XLSGEN in a submitted job . SBMJOB *NO *YES, *NO Download Excel stmf if CGI job . DOWNLOAD *YES *YES, *NO

Figure 5 - Command HSSFCGI/TABLEXLS

This command generates - from one or more database files - an Excel workbook on the IFS. The workbook is either type XLS or XLSX depending on the extensionspecified in the TOXLS stream file name. The generation process goes through three main steps:

For each database file a so-called AD-HOC ILE-RPG program is generated in library HSSFCGIDTA(This is why to run command TABLEXLS on an IBM i box you need the ILE-RPG compiler).These programs are used to read the database files. An XLSGEN script (an XML-like script, input to command XLSGEN or XLSXGEN) is then generatedwhile reading the database files.

1.

If you specify TOXLS(*NONE), the process stops here. You can then display, edit or update with some program of yours the XML-like XLSGEN script, thatyou will later on process with command XLSGEN or XLSXGEN under your control.

2.

If you specify for TOXLS a stream file name, then the TABLEXLS program goes on and processes the XML-like XLSGEN script through command XLSGENor command XLSXGEN (according to the extension of the TOXLS stream file), thus generating an XLS or XLSX stream file ready for Excel.

3.

Note on date fieldsOur utility cannot tell whether a database record field contains a date, unless the field definition supports the DDS keyword DATFMT (date format). If the DATFMTkeyword is found at field level, then we are sure that the field contains a date, and the value of the DATFMT keyword tells us what is the date format that shouldbe displayed.DDS data type L is used to define date fields on physical files, and these type of fields support the DATFMT keyword. Also logical file signed and packed fieldsbased on physical date fields should support the DATFMT keyword, according to the IBM System i DDS Manual.Only the database fields supporting the DATFMT keyword are date fields for the TABLEXLS utility. They are converted to spreadsheet date cells and are editedaccording to their DATFMT values.Other fields containing date values, such as plain numeric or character fields, are not detected as date fields by the TABLEXLS utility, and are converted tospreadsheet numeric or text cells without any date formatting.

Should you need to have some character or numeric fields be converted to spreadsheet date cells, you must use parameter TOXLS(*NONE) to generate just theXML-like XLSGEN script, change the <data type="..."> declarations to <data type="date" format="..."> declarations, then process the XML-like script withcommand XLSGEN or XLSXGEN.

HSSFCGI Developer Guide

12

perotti
Highlight
Page 13: HSSFCGI- A simple way to create spreadsheets with · PDF fileA simple way to create Spreadsheets with HSSFR4 by Giovanni B. Perotti(Italy) About it Prerequisites Installation ... Library

Command parameters:From database files (FROMFILE) - Qualified names of one or more (up to 50) database files that will be used to generate the XLS or XLSX Excel workbook.From members (FROMMBR) - Up to 50 database file members to be processed. Each member will be a separate worksheet in the workbook. Allowed singlevalues:

*FIRST - the first or only database file member*ALL - all the database file members.

NOTE- If a list of members is provided, but none of such members is found on a given database file, member *FIRST is assumed for that database file.To .xml stream file (TOXML) - This is the name of the XLSGEN script (an XML-like) stream file that will be generated, then processed.

If you specify *AUTO, the name of this stream file will be assigned by the program, and the stream file will be deleted at the end of the process.If you specify a stream file name of your choice, the stream file will not be deleted at the end of the process. This option allows you to manuallymodify the XLSGEN script and to use it as input to an XLSGEN command under your control. In this way you may customize the XLS/XLSXspreadsheet according to your needs.

To .xls or .xlsx stream file (TOXLS) - This is the name of the XLS stream file (the workbook) that will be generated by the program through the use of anXLSGEN command.An estension .xls or .xlsx is required.

Note: You may specify *NONE instead of a stream file name. If you do so, command XLSGEN/XLSXGEN is not invoked, and the XLS/XLSXstream file is not generated. In this way you may edit or process the generated XML-like stream file, update it to better fit your needs andprocess it later on with command XLSGEN or XLSXGEN.

Add Sheets to existing WkBook (ADDTO) - This parameter specifies whether generated worksheets should be added to an existing workbook or to a newworkbook. Enter:

*NO when the workbook does not already exist or must be re-created from scratch*YES to add the worksheet(s) to a workbook already existing.

Edit the .xml stream file (EDITXML) - If you specified TOXLS(*NONE), and you are running an interactive job, you may ask to edit the XML-like stream fileas soon as it is generated.Sheet names (SHEETNAME) - Name to be assigned to the generated worksheets. You have two choices:

Leave the default value *MBRNAME. By doing so, each sheet is assigned the name of the related database file member.a. Enter a name of up to 8 characters. By doing so, each sheet is assigned this name followed by a sequence number.b.

Paper size (PAPERSIZE) - 33 different paper sizes are available. Use the command prompt or run command DSPPFM HSSFCGI/PAPERSIZES to displaythem.Header (HEADER) - This parameter is used to specify the print header. Two elements are needed:

Print header - The allowed values are:*DFT - The print header displays the qualified database file name*FILETXT - The print header displays the database file text description*MBRTXT - The print header displays the member text descriptiona text description of your own that will apply to all members.

1.

Show also on the worksheet - Select*YES, to display the print header in the first row of the worksheets. Note that *YES is disregarded when *DFT is selected for the print header.*NO, not to display the print header on the worksheets.

2.

Print-orientation (PRTORIENT) - Select*PORTRAIT to print the worksheet in Portrait mode (no page rotation)*LANDSCAPE to print the worksheet in Landscape mode (90 degree rotated page).

Print-fit (PRTFIT) - This parameter may be used to fit the printout of a spreadsheet in a given number of pages.This parameter has two elements:

The first element (Sheet fit-width) tells into how many pages the width of the spreadsheet should be compressed.For instance, if the width of the spreadsheet usually requires two pages in order to print all the columns of a given spreadsheet row, by specifying 1in this element you force all the columns of a row to fit in a single page.

1.

The second element (Sheet fit-height) tells into how many pages the height of the spreadsheet should be compressed.2. By leaving both elements set to 0, you are not asking any print compression.By setting both elements to 1, you are asking the printout to fit in a single page.Note. This parameter, when used, inhibits the use of parameter PRTSCALE.Print-scale (PRTSCALE) - Percent scale to be used for printing. For instance, a value of 75 means that the print scale should be reduced to 75%.Alternate Column Headings stmf (ALTCOLHDG) - As a default, a single spreadsheet column header row would be generated from the database file fielddescriptions.An alternate column headings structure, made of one or more spreadsheet rows, defined by the user, can be used only for the first database file. Thisalternate column headings structure

must be defined on a stream file using the XLSGEN tags <row>, <cell>, <data>, </data>, </cell> and </row>.Note: Of course, when an ALTCOLHDG stream file is specified, parameter HDGCOLOR (Column headings background color) no longer applies. To obtainforeground and background colors, XLSGEN keywords f-color and b-color must be specified in the <DATA ...> tags of the stream file (XLSGEN script)specified in this parameter ALTCOLHDG.For a detail example about using this parameter, see this page.Freeze pane columns and rows (FROZEN) - Number of initial rows and columns to be frozen.Frozen intial rows and/or columns keep steady while you scroll the spreadsheet.Note- The generated column headers are all contained within the first row. This is why the default value of the first element is set to 1.ColHdg background color (HDGCOLOR) - Select one of 47 colors to be used as background color for the cells in the first row of the generated spreadsheet(Column Headers), or select *NONE to avoid using a background color.The available colors are listed here.Column Header cells are always assigned borders, regardless of what is specified in parameter CELLBORDER (see below).Default cell colors (DFTCELLCOL) - These are the default cell colors to be assigned to all spreadsheet cells. There are two default cell colors:

The first color is the font color for the text to be written in a cell.The second color is the background color of the cell.

Each color can be chosen from a list of 47 colors.The available colors are listed here.Cell border (CELLBORDER) - Specifies which cells should be given borders. Enter:

*NO not to generate borders for any cells*YES to generate borders for all cells*COLOR to generate borders for cells having a background color other than WHITE or a foreground color other than BLACK*FCOLOR to generate borders for cells having a foreground color other than BLACK*BCOLOR to generate borders for cells having a background color other than WHITE.

Decimal positions (DECPOS) - Number of decimal positions for the numeric cells of the spreadsheet.If you specify a number from 0 to 9, all the numeric cells display that number of decimal positions. Thousand delimiters are displayed. If you specify *AUTO,each numeric cell displays the number of decimal positions specified in the input XML stream file (parameter INPSTMF). Thousand delimiters are displayed.*NOC (no commas) is the same as *AUTO, except that thousand delimiters are not displayed.Display zero values (ZERODSP) - Whether the numeric cells containing a value zero should display a zero or should display nothing. Select:

*YES (default value) to have the numeric cells containing a zero value displaying a zero*NO to have the numeric cells containing a zero value displaying nothing. This option is recommended when a large number of numeric cells maycontain zero values, because this makes user reading much easier.

Convert date fields to (CVTDATE) - Whether all database date fields should be converted to a given format. Leave *NO if date field formats are to bemaintained as they are. Available conversion formats are:

*MDY (mm/dd/yy)*DMY (dd/mm/yy)*DMYY (dd/mm/yyyy)*YMD (yy/mm/dd)*YYMD (yyyy/mm/dd)*ISO (yyyy-mm-dd)*USA (mm/dd/yyyy)*EUR (dd.mm.yyyy)*JIS (yyyy-mm-dd)*JUL (yyyy-ddd)

Ignore fields (IGNFLDS) - You may specify up to 50 field names that are to be excluded from the generated Excel spreadsheet.Hyperlink fields (LINKFLDS) - You may specify up to 50 pairs of field names to be used for creating hyperlink spreadsheet cells.Each pair of field names is made up of

The name of a character field containing one of the following link types:an URL link, example: http://www.easy400.neta MAIL link, example: mailto:[email protected] FILE link, example: c:\mydir\mydoc.doc .

1.

HSSFCGI Developer Guide

13

Page 14: HSSFCGI- A simple way to create spreadsheets with · PDF fileA simple way to create Spreadsheets with HSSFR4 by Giovanni B. Perotti(Italy) About it Prerequisites Installation ... Library

The name of a character field containing a description of the link.2. You may run a test of this feature by entering commandTABLEXLS FROMFILE(hssfcgi/hyper) TOXLS('/tmp/hyper.xls') PRTHDR(*MBRTXT) LINKFLDS((itmlnk itmdes))Display pictures (PICTURES) - If the database file contains character fields specifying the names of .PNG or .JPG pictures (example: /mydir/mypicture1.jpg), you may ask to have these pictures displayed in the spreadsheet instead of just showing their names. Select:

*YES to display the pictures instead of their names, or*NO to display just the stream file names of the pictures, as for any other character field.

Note- For some information about how pictures are specified in a XLSGEN XML-like script, see this page.VSPAN for picture cells (VSPAN) - This parameter (vertical span) is required if PICTURES(*YES) is specified. This parameter is used to specify the heightof the pictures and is expressed as the number of spreadsheet rows to be spanned for a picture cell. The default value is 7 (picture cells are given a heightcorresponding to 7 spreadsheet rows).Pictures width in pixel (WIDTH) - This parameter is required if PICTURES(*YES) is specified. This parameter is used to specify the width in pixel of thepictures cells. Please note that a picture width is always expanded to the cell width, which is assessed by the largest cell in the same spreadsheet column.Failure recovery (RECOVERY) - This parameter tells how the program behaves in case of failure.Program failures may be caused by improper XLSGEN script tags or by an excessive memory demand to the JVM when large worksheets are generated.This parameter is made of two elements:

Try to recover - Specify *YES if you require the program to recover from a possible failure.a. Max. cells per worksheet - When *YES is specified for Recover, the program splits the workbook in multiple worksheets. Each worksheet containsthe number of cells specified in Max. cells per worksheet, rounded up to fill up the last worksheet row.Should then a failure occurr,

a workbook containing a number of worksheets - excluding the last one where the failure occurred - is made available, anda submitted batch job resumes the process with a new workbook starting with the worksheet where the failure occurred.Should a failure occur in the submitted batch job, the recovery scheme applies again.

The ultimate result could be a number of workbooks generated by several jobs.Please note that the original process does not end until the last job in the chain completes. The original process stays in place collecting anddisplaying (if running in interactive mode) the messages sent from the jobs in the batch chain.

b.

Generate log (LOG) - If you specify LOG(*YES), log file XLSGENLOG is generated in library QTEMP. This log contains an entry for each generatedworksheet cell. In case of a failure, by displaying this log file you can easily establish which was the last spreadsheet cell generated successfully before thefailure occurred.Run XLSGEN in a submitted job (SBMJOB) - If you specify SBMJOB(*YES), all the XLSGEN Java process is executed in a batch submitted job. In this waythe settings of the Java Virtual Machine of the bach job cannot conflict with the JVM settings of the current job.Download Excel stmf if CGI job (DOWNLOAD) - When command TABLEXLS is executed from a job in subsystem QHTTPSVR (a CGI job), this optionallows to download to the client browser the generated Excel stream file. Of course, if this is done, no other response from the CGI program should be sentto the browser.If command TABLEXLS is issued from a CGI program:

Leave *YES to have the CGI program sending out the Excel stream fileType *NO to avoid downloading the Excel stream file and to have the CGI program providing its own response to the browser.

Note- Command TABLEXLS provides, for any generated worksheet, a record in file QTEMP/XLSGENRPT. For the record layout, see this page.Command HSSFCGI/RPTXLSGEN reads this file and provides a printout listing all the workbooks, with information about their sheets, generated from the current job.

Command TABLEXLS is for a 5250 black-green screen or for execution within a program.Then, how to run this command from a WEB browser?If you have installed the Apache HTTP directives in stream file /hssfcgi/apache/http_directives.txt, just try one of the following URL's:

http://.../tablexls or http://.../hssfcgip/webtablexl.pgm

You will receive the following page:

Figure 6 - Command TABLEXLS from a WEB browser

After submitting the XLSTABLE command, the XLS or XLSX Excel spreadsheet is generated and sent to your browser.

Notes.

The WEB page includes a yellow "demo" button in the bottom left corner. A cycle of three demos is available. This can be used to get some familiarity with thetool.You may try now, just use the "demo" button. Press this link to go.

1.

If, after pressing the "submit" button, command TABLEXLS - launched from the CGI program - fails, the command in error is displayed at the bottom of the page.You are suggested to copy, paste and run it from a green screen session in order to receive some diagnostic messages.

2.

HSSFCGI Developer Guide

14

Page 15: HSSFCGI- A simple way to create spreadsheets with · PDF fileA simple way to create Spreadsheets with HSSFR4 by Giovanni B. Perotti(Italy) About it Prerequisites Installation ... Library

Last modified on 01/16/2016

HSSFCGITABLEXLS2: Create Excel workbooks from IBMi database files

Command TABLEXLS2 is the Junior version of command XLSTABLE.It is 1.3 times faster than TABLEXLS, does not require the ILE-RPG compiler to run, but has less features.

1-Highlights2-About the XLSGEN2 language3-Generating the XLSGEN2 script from your ILE-RPG program4-Commands XLSGEN2 and XLSXGEN25-Command WEBXLSGEN2 for CGI programs6-XLSTABLE2 for the WEB

1-Highlights

While command TABLEXLS generates - for each database file to be read - an ad hoc ILE-RPG program, command TABLEXLS2 does not need that.Therefore, to run command TABLEXLS2 you do not need an ILE-RPG compiler. This may help if you want to run it on a production box hosting no compilers.TABLEXLS2 generates an intermediate XLSGEN2 script made of some XML-like XLSGEN statements and data exported from a CPYTOIMPF command. Thegeneration of this script is quicker than the XLSGEN script generated from command TABLEXLS, and this is the performance advantage of XLSTABLE2.The script is then read by program XLSGEN2, similar to program XLSGEN, which creates an XLS or XLSX Excel workbook.The following parameters, available in command TABLEXLS, are missing in command TABLEXLS2:

IGNFLDS (Fields to be omitted)LINKFLDS (Hyperlink fields)PICTURES, VSPAN, WIDTH (Ability to display pictures)

2-About the XLSGEN2 language

A XLSGEN2 script begins as a XLSGEN script, defining the workbook, the worksheet and the first row of cells containing the column headers.However, instead of defining the row cells (containing the record field data) through the XLSGEN <row> <cell> and <data> tags, XLSGEN2 appends to the scriptstream file the output from a CPYTOIMPF command over the database file member. The result is a sequence of lines, one for each database record, where data fieldsare represented by semicolumn-separated strings.Character strings are enclosed in double quotes (example: ;"...text...";), while numbers are not (example: ;1827;).In XLSGEN2, this bunch of lines representing the database member records are preceded by the tag <Start_of_rows> and followed by the tag <End_of_rows>.

Please take a look at this XLSGEN2 script.It was generated by the following command:TABLEXLS2 FROMFILE(HSSFCGI/UTILITIES) TOXML('/hssfcgi/tmp/uti2.txt') TOXLS('/hssfcgi/tmp/uti2.xls') SHEETNAME(DT150903) PRTORIENT(*LANDSCAPE) PRTSCALE(75) HDGCOLOR(LAVENDER) XLSGENRPT(*NO)

After generating the XLSGEN2 script stream file, TABLEXLS2 inputs that XLSGEN2 stream file to command XLSGEN2, in order to generate the Excel workbook.In the above example, the XLSGEN2 command executed from TABLEXLS2 is:XLSGEN2 INPSTMF('/hssfcgi/tmp/uti2.txt') OUTSTMF('/hssfcgi/tmp/uti2.xls') FROZEN(1 0) HDGCOLOR(LAVENDER) XLSGENRPT(*NO)and the result is this Excel spreadsheet.

3-Generating the XLSGEN2 script from your ILE-RPG program

If you are familiar with CGIDEV2-based ILE-RPG programs, you may still use the template /hssfcgi/html/standardXML.txt to generate the initial part of theXLSGEN2 script (defining the workbook, the worksheet and the first row of cells containing the column headers) in the client output buffer and send it to yourscript stream file using CGIDEV2 procedure WrtHtmlToStmf().Otherwise, if you are familiar with opening, closing and writing to stream files, you can do write that initial part of the script stream file using standard open(),write() and close() procedures.If you need some example, please refer to member TABLEXLS2 in HSSFCGI/QRPGLESRC.Next, you have to

open the script stream file for appendwrite the tag <Start_of_rows>use command CPYTOIMPF (referring to a given database file member) to add its output to the script stream filewrite the tag <End_of_rows>Last, you must write the following final tags to the script stream file: </worksheet> </workbook></XML>

Again, you may look at member TABLEXLS2 in HSSFCGI/QRPGLESRC for a complete example of generating a XLSGEN2 script.

4-Commands XLSGEN2 and XLSXGEN2

Command XLSGEN2 generates a XLS Excel workbook from a XLSGEN2 script stream file.Command XLSXGEN2 generates a XLSX Excel workbook from a XLSGEN2 script stream file.These commands are similar to commands XLSGEN and XLSXGEN (see this page), except that they do no support parameter CVTDATE.

5-Command WEBXLSGEN2 for CGI programs

In writing you CGI program you may also take advantage of command HSSFCGI/WEBXLSGEN2. This command is very similar to commands XLSGEN2 andXLSXGEN2, but provides further functions:

Creates the XLS or XLSX stream file from the XLSGEN2 script stream file (as commmands XLSGEN2 or XLSXGEN2 would do). Then, if running in a HTTPinstance, ...

a.

Sends the XLS or XLSX stream file to the browserb. Submits a job to delete the XLS/XLSX stream file after 5 minutes.(Note that it is a program responsibility to decide to delete the XLSGEN2 script stream file.)

c.

6-XLSTABLE2 for the WEB

Command TABLEXLS2 is for a 5250 black-green screen or for execution within a program.Then, how to run this command from a WEB browser?If you have installed the Apache HTTP directives in stream file /hssfcgi/apache/http_directives.txt, just try one of the following URL's:

http://.../tablexls2 or http://.../hssfcgip/webtablex2.pgm

HSSFCGI Developer Guide

15

perotti
Highlight
Page 16: HSSFCGI- A simple way to create spreadsheets with · PDF fileA simple way to create Spreadsheets with HSSFR4 by Giovanni B. Perotti(Italy) About it Prerequisites Installation ... Library

You will receive the following page:

Figure 7 - Command TABLEXLS2 from a WEB browser

After submitting the XLSTABLE2 command, the XLS or XLSX Excel spreadsheet is generated and sent to your browser.

Notes.

The WEB page includes a yellow "demo" button in the bottom left corner. This can be used to get some familiarity with the tool.You may try now, just use the "demo" button. Press this link to go.

1.

If, after pressing the "submit" button, command TABLEXLS2 - launched from the CGI program - fails, the command in error is displayed at the bottom of thepage. You are suggested to copy, paste and run it from a green screen session in order to receive some diagnostic messages.

2.

HSSFCGI Developer Guide

16

Page 17: HSSFCGI- A simple way to create spreadsheets with · PDF fileA simple way to create Spreadsheets with HSSFR4 by Giovanni B. Perotti(Italy) About it Prerequisites Installation ... Library

Figure 2

Last modified on 01/16/2016

HSSFCGITABLEXLS - Parameter ALTCOLHDG

In generating worksheets, TABLEXLS would generally create a single row of column headers for each worksheet. The text for the column headers is retrieved from theFile-Field descriptions related to the processed database file.

Though this is generally acceptable, there may be cases where one would need to have different text descriptions in some column headings or even extend the headingsover more rows.

In command TABLEXLS you may use parameter ALTCOLHDG to replace the default column headings with your own headings. This can be done by specifying in thisparameter the path-name of a stream file where the heading rows are defined in XLSGEN language. The following example explains how this can be done.

The exampleIn this example we use database file HSSFCGIDTA/ADHOCCTL: that is a control file available on your system after installing HSSFCGI. We use this file because youcan repeat this example on your IBMi.

Step 1Let us run the following command:TABLEXLS FROMFILE(HSSFCGI/ADHOCCTL) TOXML('/tmp/adhocctl.txt') TOXLS('/tmp/adhocctl.xls')The resulting worksheet looks like this:

Figure 1

Step 2Let us have a look at the XLSGEN script generated by that command TABLEXLS (the XLSGEN script is then usedby command TABLEXLS to feed command XLSGEN, which creates the XLS). That XLSGEN script is in stream file/tmp/adhocctl.txt (See Figure 2).The part of the script that generates the column headings is the one inside the red rectangle.

If we want different headings from the default ones generated by TABLEXLS, we must write in a stream file ourXLSGEN tags, and mention that stream file in parameter ALTCOLHDG of command TABLEXLS.

Step 3Figure 3 shows the XLSGEN script that we would like to use for generating the column headers of the worksheet.Let us assume that we wrote this script in stream file /hssfcgi/altcolhdg/adhocctl.txt.

Step 4Let us now run the following command:TABLEXLS FROMFILE(HSSFCGIDTA/ADHOCCTL) TOXML('/tmp/adhocctl2.txt') TOXLS('/tmp/adhocctl2.xls') ALTCOLHDG('/hssfcgi/altcolhdg/adhocctl.txt')The resulting worksheet id shown in Figure 4.

Restrictions

The XLGEN script stream file mentioned in parameter ALTCOLHDG applies only to the members of the firstdatabase file in parameter FROMFILE. For the other database file members, column headings are retrievedfrom the related file-field descriptions.

HSSFCGI Developer Guide

17

perotti
Highlight
Page 18: HSSFCGI- A simple way to create spreadsheets with · PDF fileA simple way to create Spreadsheets with HSSFR4 by Giovanni B. Perotti(Italy) About it Prerequisites Installation ... Library

Figure 3

Figure 4

HSSFCGI Developer Guide

18

Page 19: HSSFCGI- A simple way to create spreadsheets with · PDF fileA simple way to create Spreadsheets with HSSFR4 by Giovanni B. Perotti(Italy) About it Prerequisites Installation ... Library

Last modified on 01/16/2016

Java product 5722JV1 / 5761JV1

Option Feature Description Javaversion Library IFS directory Java

Classic

IBMTechnology

for JavaV5R3 V5R4 V6R1 V7R1 V7R2

*BASE 5050+lngIBMDeveloperKit for Java

QJAVA x x x x x

5 5105JavaDeveloperKit 1.3

1.3 QJAVA /QIBM/ProdData/Java400/jdk13 x

6 5106JavaDeveloperKit 1.4

1.4 QJAVA /QIBM/ProdData/Java400/jdk14 x x x x

7 5107JavaDeveloperKit 5.0

1.5 QJAVA /QIBM/ProdData/Java400/jdk15 x x x x

8 5108 J2SE 5.0 32bit 1.5 QJVM50

/QOpenSys/QIBM/ProdData/JavaVM/jdk50/32bit

x x x x

9 5109 J2SE 5.0 64bit 1.5 QJVM5064

/QOpenSys/QIBM/ProdData/JavaVM/jdk50/64bit

x x x

10 5110Java SEDevelopmentKit 6

1.6 QJAVA /QIBM/ProdData/Java400/jdk6 x x x

11 5111 Java SE 632 bit 1.6 QJVM6032

/QOpenSys/QIBM/ProdData/JavaVM/jdk60/32bit

x x x x x

12 5112 Java SE 664 bit 1.6 QJVM6064

/QOpenSys/QIBM/ProdData/JavaVM/jdk60/64bit

x x x x

13 5113

JavaDeveloperKit (J2SE1.4.2 64-bit)

1.4 QJVM1464

/QOpenSys/QIBM/ProdData/JavaVM/jdk14/64bit

x x x

14 5114 Java SE 732 bit 1.7 QJVM7032

/QOpenSys/QIBM/ProdData/JavaVM/jdk70/32bit

x x x

15 5115 Java SE 764 bit 1.7 QJVM7064

/QOpenSys/QIBM/ProdData/JavaVM/jdk70/64bit

x x x

16 5116 Java SE 832 bit 1.8 QJVM8032

/QOpenSys/QIBM/ProdData/JavaVM/jdk80/32bit

x x

17 5117 Java SE 864 bit 1.8 QJVM8064

/QOpenSys/QIBM/ProdData/JavaVM/jdk80/64bit

x x

Reference: Support Java Versions by Operating System Release.

HSSFCGI Developer Guide

19

perotti
Highlight
Page 20: HSSFCGI- A simple way to create spreadsheets with · PDF fileA simple way to create Spreadsheets with HSSFR4 by Giovanni B. Perotti(Italy) About it Prerequisites Installation ... Library

<as400>startbook<XML> <workbook><as400>startsheet <worksheet name="/%sheetname%/" /%worksheetkeywords%/><as400>startrow <row /%rowkeywords%/><as400>startcell <cell /%cellkeywords%/><as400>startdata <data type="/%datatype%/" /%datakeywords%/><as400>data /%data%/<as400>enddata </data><as400>endcell </cell><as400>endrow </row><as400>endsheet </worksheet><as400>endbook </workbook></XML>

standardXML.TXT

HSSFCGI Developer Guide

20

perotti
Highlight