Output a single-sheet document to Excel (Swift)
By default, when you send report data to an Excel™ spreadsheet, each page produces a separate Excel sheet. You can merge the pages into a single sheet, but you must then configure the report to avoid problems with alignment and calculation.
If the page breaks are not desirable, you can change the page size to a larger custom value. However, creating a huge page can adversely affect memory reclamation and performance. It is often better to use a standard page size to merge the pages into a single-sheet result.
mergepages
parameter to TRUE
in the configureXLSDevice()
or configureXLSXDevice()
functions to write all data to a single
sheet....
let rcPtr = createRuntimeConfiguration(reportDesignFileName)
selectDevice (rcPtr, XLS)
configureXLSDevice (rcPtr,INT_NULL,INT_NULL,BOOLEAN_NULL,BOOLEAN_NULL,
BOOLEAN_NULL,BOOLEAN_NULL,TRUE)
...
Fixing issues with column alignment
When you merge sheets, elements such as page headers and group totals might cause problems with layout and calculation. For example, Figure 1 shows how a page header can disrupt the columns.
To avoid this problem, remove all page footers and turn all page headers to first page
headers. You can remove these elements at runtime by using the RTL Runtime class method
producingExcelOutput()
:
- In all Page Footers, and in the First Page Header, set the Visibility
Condition property to:
!Runtime.producingExcelOutput()
- In the Any Page Header, set the Section property
to:
Runtime.producingExcelOutput()?Port.FirstPageHeader:Port.AnyPageHeader
When you merge sheets, the page headers and footers now line up correctly, as in Figure 2.
Group totalsGroup totals can also disrupt the column alignment. For example, Figure 3 shows a report design document where the "Total" is created from two separate elements: a Word Box and a Decimal Format Box.
For the first page of the report, the product ID is listed in column A and the product name is listed in column B. However, for the last page of the report, the overall total is printed in column B and the product name is moved to the right into column C, as in Figure 4
To avoid this problem, edit the report design document using one of the following strategies:
- Force a page break by adding a vertical box before the total and setting the Y-size of the box to “rest”. The page break moves the total line to a separate page where it is tabulated apart from the main table data.
- Change the size and position of the total so it does not require new cells. In this case, move the decimal format box to the right so it is directly beneath the product name.