How can I customize the name and order of columns/Attributes when exporting to an Excel file?
For example: I want to export a list of receipts to an Excel file.
The original list of receipts (
ReciptTable.List) is fed by the following Aggregate:
I want my Excel file to have "Store" (originally "Name"), "Date and Time" (originally "DateTime"), "Customer" (originally "ClientName") and "Order Total" (originally "Total") columns.
To customize the name and order of columns/Attributes when exporting a List to an Excel file follow these steps:
In the Data tab, create a Structure (
ReceiptsExport) and add the following Attributes:
- Store: set the Data Type to Text.
- DateandTime: set the Label to
Date and Timeand the Data Type to Date Time.
- Customer: set the Data Type to Text.
- OrderTotal: set the Label to
Order Totaland the Data Type to Decimal.
This Structure defines the final labels and order of the columns in the Excel file.
In the Logic tab, create an ExportReceiptsToExcel Server Action and add a
ListToExportLocal Variable and set the
ReceiptsExport Listby selecting
Add an Assign element with the assignment
ReceiptTable.Listand set the Mapping to ReceiptsExport as:
This defines the relation between the original List Attributes and the Structure Attributes.
After the Assign node add a Record List To Excel element (
ListToExcel), set the source
Record Listas the
ListToExportStructure and in
Attribute Selectiontick the
(All Attributes)check box.
Create an Output Parameter (
ReceiptsExcelFile) and set the Data Type to Binary.
After the Record List To Excel element, add an Assign element and assign the output of the Record List To Excel to the Output Parameter with the assignment
After these steps, calling the ExportReceiptsToExcel Action will generate an Excel file with the desired column names and order:
To enable the download of the Excel file follow this step:
In a screen action, add the ExportReceiptsToExcel Server Action, replace the End node with a Download node and define the following properties:
- File Content:
- File Name:
- (Only for Traditional Web) Mime-Type:
- File Content: