Introduction
This is a continuation of the ExcelTransformBean adapter module. The first part ExcelTransformBean Part 1: Convert various Excel formats to simple XML easily covers Excel to simple XML conversion.
This second part focuses on simple XML to Excel conversion. Similar to the first part, this uses the combined SS interface of Apache POI's API, therefore it is able to write both XLS and XLSX files.
Source Code
The source code is shared with the first part. Refer to the corresponding section in the first article for details on accessing the source code from the GitHub repository.
Module Parameter Reference
Below is a list of the parameters for configuration of the module for XML to Excel conversion (conversionType = 'SimpleXML2Excel'.) Certain parameters will automatically inherit the default values if it is not configured.
Note: All fields in the simple XML structure must exists. If any field does not exist, this will cause the alignment of the columns to be incorrect. This is similar to the behavior of FCC or MTB's SimpleXML2Plain conversion. To ensure proper column alignments, use MapWithDefault when mapping the fields of the target structure.
Parameter Name | Allowed values | Default value | Remarks |
---|---|---|---|
conversionType | SimpleXML2Excel | Required field. Determines conversion type. | |
excelFormat | xls, xlsx | xlsx | Determines output file format |
sheetName | Sheet1 | Name of sheet in output Excel file | |
addHeaderLine | none, fromXML, fromConfiguration | none | Determines if there will be a header line in the output file, and how it should be populated:
|
fieldNames | Name of columns. Required field whenprocessFieldNames = 'fromConfiguration' |
Example Scenarios
Here are some example scenarios of the behavior of the conversion based on different configuration options.
Scenario 1
Default values for all optional parameters.
Excel 2007 XSLX file format with default Sheet1.
No header line.
Module parameters
Parameter Name | Parameter Value |
---|---|
conversionType | SimpleXML2Excel |
Result
Input | |
Output |
Scenario 2
Excel binary XLS file format.
Active sheet name provided
Header line added with details from input XML fields.
Escape sequence & automatically converted to special character &
Module parameters
Parameter Name | Parameter Value |
---|---|
conversionType | SimpleXML2Excel |
excelFormat | xls |
sheetName | MySheet1 |
addHeaderLine | fromXML |
Result
Input | |
Output |
Scenario 3
Excel 2007 XSLX file format with default Sheet1.
Header line added. Column names are provided from configuration.
Certain fields are populated with blank values.
Module parameters
Parameter Name | Parameter Value |
---|---|
conversionType | SimpleXML2Excel |
addHeaderLine | fromConfiguration |
fieldNames | Field1,Date,Field2,Quantity |
Result
Input | |
Output |