Quantcast
Channel: SCN : All Content - Process Integration (PI) & SOA Middleware
Viewing all articles
Browse latest Browse all 7030

ExcelTransformBean Part 2: Convert simple XML to various Excel formats easily

$
0
0

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 NameAllowed valuesDefault valueRemarks
conversionTypeSimpleXML2ExcelRequired field. Determines conversion type.
excelFormatxls, xlsxxlsxDetermines output file format
sheetNameSheet1Name 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:

  • none = No header line
  • fromXML = Column names are determined from XML field names
  • fromConfiguration = Column names are determined from parameter fieldNames
fieldNamesName 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 NameParameter Value
conversionTypeSimpleXML2Excel

 

Result

Inputin1.png
Outputout1.png

 

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 NameParameter Value
conversionTypeSimpleXML2Excel
excelFormatxls
sheetNameMySheet1
addHeaderLinefromXML

 

Result

Inputin2.png
Outputout2.png

 

 

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 NameParameter Value
conversionTypeSimpleXML2Excel
addHeaderLinefromConfiguration
fieldNamesField1,Date,Field2,Quantity

 

 

Result

Inputin3.png
Outputout3.png

Viewing all articles
Browse latest Browse all 7030

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>