pfx-excel:marshal

Transforms internal representation into the Excel format.

  • Input: List<Map<String, String>> — a list of rows, where each row is a map of column name to value.

  • Output: byte[] — the generated Excel file content. Returns null when using fileToAppend (output is written directly to file).

Properties

Option

Type

Default

Since

Description

hasHeaderRecord

Boolean

true

IM 1.1.18

Indicates whether the input contains a header record (must be on the first row).

skipHeaderRecord

Boolean

false

IM 1.1.18

Determines whether to skip the header record in the output.

header

String


IM 1.1.18

Comma-separated list of headers from the input which should be present in the output. When set, only the specified columns are included.

format

String

xlsx

IM 1.1.18

Sets the format of the output file. Options: xlsx, xls.

sheetIndex

Integer

0

IM 1.1.18

Index of the sheet to write data to.

sheetName

String


IM 1.1.18

Name of the sheet to write data to. If filled, takes precedence over sheetIndex.

fileToAppend

String


PFIMCORE-1876 (Feb 2024)

Full path to an existing Excel file to append data to. When set, data is appended to the target file instead of creating a new one. Uses SXSSFWorkbook for memory-efficient streaming writes. Supports split operations — state is preserved across split exchanges.

dataConversionMode

Enum

AUTO

IM 6.0.13 (PFIMCORE-2687, Oct 2025)

Controls automatic data type conversion for cell values. AUTO — attempts to parse values as integers and writes them as numeric cells (falls back to string on failure). NONE — writes all values as string cells without any conversion.

Data Type Handling

Mode

Behavior

AUTO (default)

Attempts to parse each value as an integer. If successful, writes a numeric cell; otherwise writes a string cell.

NONE

All values are written as string cells regardless of content. Useful when leading zeros or specific formatting must be preserved (e.g., SKU codes like 00010).

Examples

Marshal data into Excel format (default)

XML
<route>
  <from uri="direct:start"/>
  <setBody>
    <groovy>[[sku: 'sku', name: 'name'], [sku: 10, name: 'BMW'], [sku: 20, name: 'AUDI']]</groovy>
  </setBody>
  <to uri="pfx-excel:marshal"/>
</route>

Marshal with dataConversionMode=NONE (preserve leading zeros)

XML
<route>
  <from uri="direct:start"/>
  <setBody>
    <groovy>[[sku: 00010, name: 'BMW'], [sku: 020, name: 'AUDI']]</groovy>
  </setBody>
  <to uri="pfx-excel:marshal?header=sku,name&amp;hasHeaderRecord=false&amp;dataConversionMode=NONE"/>
</route>

Append data to an existing Excel file

XML
<route>
  <from uri="direct:start"/>
  <split>
    <simple>${body}</simple>
    <to uri="pfx-excel:marshal?fileToAppend=/tmp/output/result.xlsx"/>
  </split>
</route>

Each split chunk is appended to the target file. The workbook state is preserved across splits and finalized when the last split is processed (Exchange.SPLIT_COMPLETE).

Common Pitfalls

  • Leading zeros lost — Default AUTO mode converts 00010 to numeric 10. Use dataConversionMode=NONE for SKU codes, EAN codes, or any field where leading zeros matter.

  • Large files with fileToAppend — When using fileToAppend inside a split, the output body is null (data is written directly to file). Do not chain further body-dependent steps after marshal.

  • XLS vs XLSX — Default output format is xlsx. If you need xls for legacy systems, set format=xls explicitly.