Apache POI Cheat Sheet

Apache POI is the de-facto Java library for reading and writing Microsoft Office documents. The link below jumps straight to the official quick guide covering both the old HSSF (BIFF8/XLS) and newer XSSF (OOXML/XLSX) APIs.

Quick Tips

  • Use WorkbookFactory.create(InputStream) when you need to support both XLS and XLSX without branching.
  • Close SXSSFWorkbook instances explicitly to flush temporary files when writing large spreadsheets.
  • Validate cell formats before exporting sensitive financial data; Excel silently truncates decimals if format strings are incorrect.

Maintenance Note

Always pin your project to a supported POI version—older releases packaged in legacy apps can contain security vulnerabilities (CVE-2019-12415, CVE-2021-36090). Review the Apache POI release notes before upgrading production systems.