How to Migrate Apache POI to Axyra Sheets in Java
Map POI calls to Axyra, keep the report data and formatting, and migrate one report at a time.
Axyra Sheets is a Java library for reading, writing, and processing Excel files. If your POI application needs modern formula calculation or built-in PDF and image export, it is an option worth considering.
This guide walks through manually migrating the Java code that generates a sales report from POI to Axyra, while preserving the report’s values, formulas, and formatting.
Prefer an AI-assisted approach? See the Axyra Agent Skill migration guide.
TL;DR
- Replace Apache POI workbook and cell operations with Axyra Sheets APIs such as
Workbook.create(),sheet.cell(), andCellValue. - Use Axyra Sheets to write values, formulas, and reusable styles while preserving your existing report requirements.
- Run both implementations with the same data and compare the generated Excel reports before switching.
Table of contents
- The sample report
- Before you migrate
- Run the manual migration reference project
- 1. Map Apache POI operations to Axyra
- 2. Translate values, dates, and formulas
- 3. Preserve styles and calculation behavior
- 4. Compare outputs and switch the implementation
- FAQ
- Apply the process to your own POI code
The sample report
PoiSalesReport creates an Excel sales report containing order IDs, dates, amounts, a 20% tax calculation, and totals. AxyraSalesReport replaces that Java program while keeping the same report data, formulas, and formats. This is the report you will work with throughout the guide:
| Order ID | Date | Amount | With Tax |
|---|---|---|---|
| 00042 | 2026-10-27 | 1,250.00 | 1,500.00 |
| 00043 | 2026-10-28 | 80.00 | 96.00 |
| Total | 1,330.00 | 1,596.00 |
Both programs produce these values. Dates use yyyy-mm-dd, and amounts use #,##0.00. The With Tax cells contain formulas, and the total row sums both amount columns.
View the original POI and migrated Axyra workbooks
Before you migrate
Start with an existing Apache POI report and its generated XLSX file. Keep the original input data and business calculations unchanged while translating the workbook operations. You can run the completed sample first to see the expected results, then read how each POI operation is rewritten. Alternatively, follow the steps with your own POI report. For larger migrations, use the preparation checklist in the sample project README.
Migration preparation checklist
Run the manual migration reference project
Use Java 17 or later and Maven. The sample project contains PoiSalesReport (the original POI program), AxyraSalesReport (its replacement), and CompareReports (the output comparison program). Run them in this order:
POI migration reference project
git clone https://github.com/keikai/axyra-sheets-examples.git
cd axyra-sheets-examples/java/guide-projects/poi-migration
mvn compile exec:java -Dexec.mainClass=PoiSalesReport
mvn exec:java -Dexec.mainClass=AxyraSalesReport
mvn exec:java -Dexec.mainClass=CompareReports
The programs write output/poi-sales.xlsx and output/axyra-sales.xlsx. Their Sales sheet keeps the text IDs 00042 and 00043, dates, numeric amounts, formulas, and totals of 1,330.00 and 1,596.00. The comparison covers the selected cells and workbook properties in this sample; adapt those checks to the report you are migrating.
The sample uses POI 5.3.0 to generate the original report and read both files for comparison. Examples run in evaluation mode unless you have configured an Axyra license.
1. Map Apache POI operations to Axyra
Both libraries have workbook, sheet, and cell concepts, but their APIs work differently. Axyra provides direct cell and range access without creating a POI-style Row first. Both use zero-based numeric row and column indices.
| Apache POI operation | Axyra Sheets operation |
|---|---|
new XSSFWorkbook() |
Workbook.create(), then createSheet(name) |
WorkbookFactory.create(file) |
Workbook.open(path) |
sheet.createRow(r).createCell(c) |
sheet.cell(r, c) |
cell.setCellValue(text/number) |
cell.setValue(CellValue.text(...)/number(...)) |
cell.setCellFormula(formula) |
cell.setFormula(formula), without a leading = |
createFormulaEvaluator().evaluateAll() |
workbook.recalculate() |
createCellStyle() and createFont() |
CellStyle.builder(), then cell/range.setStyle(...) |
sheet.setColumnWidth(c, 20 * 256) |
sheet.setColumnWidth(c, 20) |
sheet.createFreezePane(0, 1) |
sheet.freezePanes(1, 0) |
workbook.write(outputStream) |
workbook.save(path) or save(outputStream, "xlsx") |
Column widths use different units, and the freeze-pane calls order the row and column arguments differently. Translate those values explicitly. When both libraries remain in the same module, use explicit imports or fully qualified class names to avoid confusing Workbook, Sheet, and Cell types.
This table covers the operations used in the sample report. For other features in your application, use the matching chapter in the developer reference and consult the Java API documentation for classes and methods.
2. Translate values, dates, and formulas
The following snippets come from PoiSalesReport and its AxyraSalesReport replacement. They write the same ID, amount, and formula to the second row of the Sales sheet. Use them inside an open workbook; the linked Java sources contain the complete programs.
Apache POI
org.apache.poi.ss.usermodel.Row row = sheet.createRow(1);
row.createCell(0).setCellValue("00042");
row.createCell(2).setCellValue(1250);
row.createCell(3).setCellFormula("C2*1.2");
Axyra Sheets
sheet.cell(1, 0).setValue(CellValue.text("00042"));
sheet.cell(1, 2).setValue(CellValue.number(1250));
sheet.cell(1, 3).setFormula("C2*1.2");
Axyra addresses cells directly, so the code does not need to create a Row first. The ID stays text, the amount stays numeric, and the formula is written without a leading equals sign.
For the Date column in the same Sales report, apply a number format so the stored value appears as a calendar date. With POI, the example writes a LocalDateTime at midnight:
row.createCell(1).setCellValue(
LocalDate.of(2026, 10, 27).atStartOfDay());
With Axyra, write the same calendar date using setDate(LocalDate):
sheet.cell(1, 1).setDate(LocalDate.of(2026, 10, 27));
Apply yyyy-mm-dd to match the original report display, as shown in the next section. Keep text identifiers as text so leading zeros remain part of the value, and keep amounts numeric so formulas can use them.
If your POI code also reads cell values, use cell.value() and handle the returned CellValue type. Use cell.formattedText() when you need the text displayed in Excel, such as a currency amount or date. This is an additional reading scenario; generating the sample Sales report does not require it.
Reading Excel cell values in Java
3. Preserve styles and calculation behavior
Create reusable styles for headers, dates, amounts, and totals. Apply each style to the matching cells or ranges throughout the report:
CellStyle money = CellStyle.builder()
.numberFormat("#,##0.00").build();
sheet.range("C2:D3").setStyle(money);
sheet.cell(1, 1).setStyle(CellStyle.builder()
.numberFormat("yyyy-mm-dd").build());
Match the font, borders, fills, row heights, and explicit column widths that matter to the original report. To change formatting in an existing template, start with cell.style().toBuilder() so you keep the other style settings. setStyle(...) applies a complete style.
To replace a POI formula-evaluation step, call workbook.recalculate() after writing the data and before reading or saving the results. In automatic mode, input changes update dependent formulas. If your report uses manual calculation, retain that setting. Saving alone does not recalculate formulas.
The sample creates a workbook with Workbook.create() and adds its Sales worksheet with createSheet(). It writes the report, calls recalculate(), and saves output/axyra-sales.xlsx. Use try-with-resources to close the workbook after saving.
If your POI report uses an existing template
This is a separate scenario from the Sales example: open your existing template with Workbook.open(...), update its inputs, and save the completed report to a separate file. When changing formatting, use the current style and toBuilder() to retain other style settings.
Fill an existing Excel report template in Java
4. Compare outputs and switch the implementation
Run the POI and Axyra implementations with the same inputs and compare the resulting report. Check values and types, formula text and results, number formats, required styles, and worksheet structure. Compare an ordinary report as well as empty reports, missing values, and larger datasets handled by your application.
Use a spreadsheet reader for cell-level comparisons and open representative files in the spreadsheet application your recipients use. If your workflow delivers PDFs or images, review their page sizes, pagination, and label layout separately. Compare cell values, formulas, formatting, and layout rather than requiring the two XLSX files to be byte-for-byte identical.
Switch the report-generation code to Axyra once the output meets your requirements. Keep the original implementation available until you have accepted the replacement, then migrate the next report. Remove POI from a module only after its remaining POI usages are gone.
rg -n 'org\.apache\.poi' src
mvn dependency:tree
These commands help locate remaining POI imports and dependencies; also inspect your own spreadsheet helper classes and other modules before removing the dependency.
FAQ
Is migration just a dependency replacement?
You need to translate the spreadsheet calls and their behavior as well as update dependencies and imports. Keep your input mapping, calculations, and report requirements intact while changing the implementation.
Can I keep Apache POI while migrating one report?
Yes. Keep the implementations in separate classes or modules and select the report path you are changing. Use explicit imports while both libraries are present.
Can I start with an existing XLSX template?
Yes. Open the template with Workbook.open(...), write its inputs, calculate where required, and save the completed workbook. This lets you keep the designed report layout while translating the Java code that fills it.
Apply the process to your own POI code
Choose one report, list the POI operations it uses, and capture its expected output. Use the API map to rewrite the report code, compare the results, then repeat for the next report. Refer to the sample project for working code.