Best Practices and Pitfalls
Harry
· 24 Sep 2026
· 1 views
Log in to track your progress and mark lessons complete.
Sponsored
Checklist Before Shipping
- Close everything with try-with-resources (
Workbook, streams). On Windows an unclosed stream locks the file. - Reuse styles — the 64k style limit is per workbook and easy to hit in loops.
- Dates are numbers: check
DateUtil.isCellDateFormatted(cell)before reading. - Physical vs logical rows:
getPhysicalNumberOfRows()counts non-empty rows;getLastRowNum()+1counts the span. They differ when rows are blank. - Version alignment:
poi,poi-ooxmlandpoi-ooxml-litemust share one version. - Memory: over ~100k rows switch writes to SXSSF and reads to the event API.
- File locking on servers: never write directly to a served file — write to
file.tmp, then atomic-move.
Where Next?
Clone the poi-examples repo, run each class, then adapt WriteExcelExample into your own export feature. Pair this with the Open Source Libraries tutorial for iText (PDF) and JavaMail (email the file you just built).