simple-excel
simple-excel copied to clipboard
org.apache.poi.ss.usermodel.CellStyle are not reused
From reading the code, I think you end up generating a new CellStyle object every time a cell is added to the workbook. There is a limit of 64000 unique cell formats per workbook (https://support.office.com/en-nz/article/Excel-specifications-and-limits-16c69c74-3d6a-4aaf-ba35-e6eb276e8eaa).
I think if the CellStyles aren't being reused then it would be worth adding caching so that a Style object will only create a CellStyle on the workbook once. Then if you maintain a reference to a Style object then the same CellStyle instance from the workbook will be applied to each cell that uses the Style instance.
I'm happy to submit a pull request for this if you agree on my analysis.
Good idea, thanks. It'd be interesting to try and create a test to demonstrate it :see_no_evil: !!
Happy to accept pull requests.
I wonder if we can cache it here:
https://github.com/tobyweston/simple-excel/blob/e20b43d1dbb6a72f6a449cf93b63915624d66ddf/src/main/java/bad/robot/excel/style/StyleBuilder.java#L73
or
https://github.com/tobyweston/simple-excel/blob/e20b43d1dbb6a72f6a449cf93b63915624d66ddf/src/main/java/bad/robot/excel/style/StyleBuilder.java#L73