Form Template
A Form is composed of three parts:
- Header
The header is the top part of a form and is repeated on every page. Data is passed to the header through a dynamic array to Excel named shapes and/or cells.
Start by creating your header based on the data to be placed in the body. Create the body header by sizing the columns as required and make sure the total width of the body fits the width of the your page. To avoid unnecessary page breaks, set the page scaling to "Fit All Columns on One Page" as shown below:
Once the columns defined, add the shapes to the footer. Shapes are convenient because they don't have to be "snapped" to a cell, they can be placed anywhere on the sheet. You can control their font style and color independently from the sheet. Make sure you every shape you will send data to is named and make sure names are unique. Excel does not check for uniqueness!
- Body
The content of the body can be the result of a query or a data blob generated by a BASIC program.
- Result of a Query
Create a standard report using the standard method. Make sure that the number of display fields selected matches the column definition in the header. All custom formating are maintained (font, color, justification, format...) with the exception of the column width. The column width defined in the header is not affected by the display field defined in the Data View.
- Data Blob
Data Blob is 1 or more item that contains a block of data. In a data blob item, each attribute corresponds to a row and each value corresponds to a column. In our example, the data blob would have 7 values (7 columns) per attribute. This is the recommended structure but since it is not enforced by phiReport you can provide any data format you like.
The Data blob can be generated by a BASIC program called by the Pre-Query Process. This program reads input parameters from the command line and writes blob item in a work file.
To turn on Data Blob mode, check the box "Data Blob" on the "Report Parameter" tab.
In the "Start Column/Row" fields, enter the Excel coordinate where to start the body.
On the "Pre/Post Processes" tab, select "Execute TCL Command(s) and enter the name of the BASIC program to execute and the command line parameters.
In our example we execute "Demo_Invoice_PreQuery" and pass it two parameters:
- %%@Invoice Number%% : The Invoice number to prompt the user
- %%@USERPORT%% : The User Port (@PIB in D3, @USERNO)
The "STOP" command indicates a "no active list" return. By default, phiReport expects Pre-Query processes to return an active list to be used as the starting point for the main query. If no active list is returned, phiReport considers that there's no data and stops the reporting process. The command "STOP" tells phiReport to ignore the active list and continue processing.
- Footer
The footer is the bottom part of the form. There can be up-to two footers. One for pages 1 to page n-1 and one for page n; the last page. Data is passed to the footer through a dynamic array to Excel named cells. Excel formulas can also be used to plot data to the footer.
In our example the Base_footer1 sheet is used on pages 1 to n-1 and Base_footer2 is used on the last page only. If the form only returns a single page, Base_footer2 is used.
Base_footer1
Footer 1 is defined in the top 8 rows of Base_Footer1 sheet
Base_footer2
Footer 2 is defined in the top 15 rows of Base_Footer2 sheet.
Notice the named cells in the footers. These are used to "inject" data from the report program to the sheet. Cells that show "#VALUE!" are Excel formulas, these do not need to be named.
Note: Footers do not support Excel Shapes, only Named Cells can be used.
"Pad to Bottom" pushes the footer to the bottom of the page by inserting empty rows after the last row of data.
"Multi-Page Template" enables "Smart paging" which automatically inserts footer 1 at the end of each page and footer 2 on the last page. This feature is only runs when saving the form as PDF and when sending the report to a printer. Excel does not support footer preview in its "Preview" mode.
When creating a multi-page form, Excel will create a sheet similar to the one below:
Only the last page footer is shown and the default Excel page break ignores the header and the "in between" page footer.
Print Preview also skips all the footers
Below is the printed output (first page and last page):