Multi-Line Statements in XLSX

All multi-line directives such as #if, #else, #elseif, #foreach, and #macro must be used under the following conditions.

The beginning and ending statements must be declared within a single cell. The figures below show samples of invalid usage of the #if and #foreach statements between cells respectively.

Executing multi-line statements.

Invalid usage of #foreach statements.

In the first figure, since the body of the #if statement ($e.name) resides in the A2 cell, not in the A1 cell, the body will not be generated when generating a report, regardless of the evaluation of the #if statement. The code shown in the second figure will break the structure of a spreadsheet document.

The following two figures demonstrate samples of valid usage of the #if and #foreach statements respectively.

Valid usage of an #if statement.

Valid usage of a #foreach statement.
  • A VTL Macro must be declared within a single cell. Do not insert the multi-cell recorded macros in a single cell, see figure below.

Invalid usage of a VTL Macro.

The macro will copy all contents between #macro and #end. Cells and rows will be included in the macro as well. Once this record has been inserted, the macro content will break the document structure.

The following figure demonstrates a sample of valid usage of the #macro statement.

Valid usage of a VTL Macro.

Creating data for multiple rows

The #foreach directive can only be used in a single cell record. To create data for multiple rows, use the #forrow directive instead (see the following figure).

The forrow directive.

The figure below demonstrates the output of the above code.

Results of running the code from figure 7.

Creating data for multiple columns

#forcol is used for creating data for multiple columns (see the figure below). This statement can be used in conjunction with the #forrow statement.

The forcol directive.

The following figure demonstrates the output of the above code.

Results of running the code from the figure above.

Displaying content in a cell

Texts in any generated report are always wrapped. Also, the cells’ width in the generated report depends on the cells’ width in the report template used. For example, an XLSX report template in the first figure below will generate an output report as shown in the second figure below.

Sample of Wrapped Text (Column B) in an XLSX Report Template

The forrow directive.

Wrapping Text Output in XLSX

Results of running the code from the figure above.

Limitation when used in Microsoft Office Excel worksheet

You cannot use #sectionBegin and #includeSection in XLSX. If you try to use #sectionBegin or #includeSection in an XLSX report template (the first figure below) an error message will open (the second figure below).

Invalid usage of a sectionBegin directive.

The error message from running the code in the figure above.