Posts

Showing posts with the label Apache Poi

Apache POI AutoSizeColumn Resizes Incorrectly

Answer : Just to make an answer out of my comment. The rows couldn't size properly because Java was unaware of the font you were trying to use this link should help if you want to install new fonts into Java so you could use something fancier. It also has the list of default fonts that Java knows. Glad this helped and you got your issue solved! This is probably related to this POI Bug which is related to Java Bug JDK-8013716: Renderer for Calibri and Cambria Fonts fails since update 45. In this case changing the Font or using JRE above 6u45 / 7u21 should fix the issue. You can also mtigitate the issue and avoid the columns from being totally collapsed by using a code like this: sheet.autoSizeColumn(x); if (sheet.getColumnWidth(x) == 0) { // autosize failed use MIN_WIDTH sheet.setColumnWidth(x, MIN_WIDTH); } I was also running into this issue and this was my solution. Steps: Create workbook Create spreadsheet Create row Create/Set font t...

Apache POI GetRow() Returns Null And .createRow Fails

Answer : See the documentation for the SXSSFWorkbook constructor that takes the XSSFWorkbook as param. You cannot override or access the initial rows in the template file. You are trying to overwrite an existing row and the API does not support this. Your exception message reflects this. https://poi.apache.org/apidocs/org/apache/poi/xssf/streaming/SXSSFWorkbook.html#SXSSFWorkbook(org.apache.poi.xssf.usermodel.XSSFWorkbook) For your use case, you may want to try http://jxls.sourceforge.net. If you want to read or edit an exist row, you can firstly do it in xssf type, and then create the sxssf file base on the xssf file. The code is something like below... XSSFWorkbook xssfWorkbook = new XSSFWorkbook(new FileInputStream(file)); //do the read and edit operation with xssf...... ...... ...... SXSSFWorkbook sXSSFbook = new SXSSFWorkbook(xssfWorkbook); //do the write operation with sxssf...... ...... ......