Export Layout

The export action can be enabled to create excel files with the information being shown in a grid.

The excel file is created using the ExcelDocument Data Type.

In some cases, the developer may wish to customize how these files are created. For example, the developer may wish to include a preamble before the file's content, or a footer at the end.

These scenarios can be solved using the "Export Layout" object. This is an procedure in the KB that contains code that will be included in the export action's source code.

The developer can choose an "Export Layout" object in the Standard Actions node or in the "Export" node in K2BEntityServices Settings. Configuration done in the settings object is used as a default for all instances, where changing the Modes node only affects that instance.

The export layout object must follow these rules in order to be interpreted correctly:

  1. Variables can be created in the object.
  2. Source code must be organized in subroutines. No code should be present outside a subroutine.
    1. K2BTools will look for some subroutines in the source code. If they are found, they will be called in different points of the action's execution, as seen in the following table.
      Subroutine Name Execution moment
      'BeforeInitialization' After permissions are checked, before initializing the ExcelDocument.
      'AfterInitialization'

      After initialization of all variables used in object, including the output file name, delimiters (in case of CSV output), etc.

      This event was introduced in K2BTools 13.2.

      'BeforeTitle' After initializing the ExcelDocument, before printing the report title. Only included if ShowContextHeader = True.
      'BeforeFilters' After printing the Title, but before printing the applied filter values. Only included if ShowContextHeader = True.
      'BeforeGridTitles' Before printing the grid titles to the ExcelDocument.
      'BeforeGridRow' Inside the For Each body, before printing the row.
      'AfterGridRow' Inside the For Each body, after printing the row.
      'AfterGrid' After the for each command is executed.
      'AfterResponse' After the file has been sent to the client.

  3. The &CellRow and &FirstColumn variables may be used and updated in the subroutines to move the content in the document.

Example: Including the company name as a header, and its address as a footer.

To do this, the developer may define an Export Layout object with this source code:

Sub 'BeforeTitle'
    &ExcelDocument.Cells(&CellRow, &FirstColumn).Size = 15
    &ExcelDocument.Cells(&CellRow, &FirstColumn).Bold = True
    &ExcelDocument.Cells(&CellRow, &FirstColumn).Text = "My Company Ltd."
    &CellRow += 2
EndSub

Sub 'AfterGrid'
    &CellRow += 2
    &ExcelDocument.Cells(&CellRow, &FirstColumn).Size = 15
    &ExcelDocument.Cells(&CellRow, &FirstColumn).Bold = True
    &ExcelDocument.Cells(&CellRow, &FirstColumn).Text = "1234 Test St."
EndSub