Overview
Reads an Excel file (.xlsx) using pfx-excel:read and loads the data into Pricefx. The Excel component reads a specified sheet and returns rows as a List<Map<String, Object>>.
Mapper: mappers/product-excel-mapper.xml
<mappers>
<loadMapper id="productExcelMapper">
<body in="SKU" out="sku"/>
<body in="Product Name" out="label"/>
<body in="Currency" out="currency"/>
<groovy expression="body['Unit Price']?.toBigDecimal()" out="attribute1"/>
<body in="Category" out="attribute2"/>
</loadMapper>
</mappers>
Note: in values must match the Excel column header names exactly (case-sensitive).
Route: routes/import-from-excel.xml
<routes xmlns="http://camel.apache.org/schema/spring">
<route id="importProductsFromExcel">
<from uri="file:{{import.fromUri}}?include=.*\\.xlsx"/>
<to uri="pfx-excel:read?sheetName={{excel.sheetName}}&headerRow=0"/>
<to uri="pfx-api:loaddata?objectType=P&mapper=productExcelMapper"/>
<onCompletion onCompleteOnly="true">
<to uri="pfx-api:internalCopy?label=Product"/>
</onCompletion>
</route>
</routes>
Properties:
import.fromUri=import/excel
excel.sheetName=Products
How It Works
-
file:component watches theimport/exceldirectory for.xlsxfiles -
pfx-excel:readreads the specified sheet —headerRow=0means the first row contains column names -
The body becomes a
List<Map<String, Object>>where each Map is one row, keyed by column header -
pfx-api:loaddataloads the rows using the mapper
Common Pitfalls
-
Column header names in the mapper
inattribute must match the Excel headers exactly including spaces and casing -
pfx-excel:readloads the entire file into memory — for very large files (100k+ rows), prefer CSV -
Date cells are returned as
java.util.Dateobjects — use a Groovy expression to format them:body.Date?.format('yyyy-MM-dd') -
sheetNameis case-sensitive and must exactly match the sheet tab name in Excel