Best Practices and Pitfalls

Harry · 24 Sep 2026 · 1 views
Log in to track your progress and mark lessons complete.

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()+1 counts the span. They differ when rows are blank.
  • Version alignment: poi, poi-ooxml and poi-ooxml-lite must 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.

Apache POI best practices checklist

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).

Share this post:

Comments (0)

Please login or register to comment.

Create a free account to keep reading

You've enjoyed a free tutorial! Register (it's free) to unlock every tutorial, track your progress and save code.

or sign in with your account

Already have an account? Log in