After filling a sheet with data I try to invoke the sheets autoSizeColumn method on a certain column but get "IllegalArgumentException: Invalid substring range". ------------------------------------ StackTrace: ------------------------------------ java.lang.IllegalArgumentException: Invalid substring range at java.text.AttributedString.addAttribute(AttributedString.java:332) at org.apache.poi.xssf.usermodel.helpers.ColumnHelper.copyAttributes(ColumnHelper.java:447) at org.apache.poi.xssf.usermodel.helpers.ColumnHelper.getColumnWidth(ColumnHelper.java:369) at org.apache.poi.xssf.usermodel.XSSFSheet.autoSizeColumn(XSSFSheet.java:307) at org.apache.poi.xssf.usermodel.XSSFSheet.autoSizeColumn(XSSFSheet.java:290) at [object where sheet.autoSizeColumn([columnIndex]) is called] ------------------------------------ After testing different columns I came to the conclusion this only happens on that specific column, even unfilled columns can be autosized. I searched for the reason inside the cells of that column and discovered this happens only in a specific situation. If the cell is filled with a RichTextString created with an empty String and a Font (or XSSFFont) applied the column with this cell in it can't be autosized. Example: ********** Code ********** XSSFWorkbook wb = new XSSFWorkbook(); XSSFSheet sheet = new wb.createSheet("Test"); CreationHelper ch = wb.getCreationHelper(); XSSFRow row = sheet.createRow(0); XSSFCell cell = row.createCell(0); XSSFFont font = wb.createFont(); RichTextString rts = ch.createRichtTextString(""); rts.applyFont(font); cell.setCellValue(rts); ************************** The code above does not work unless I invoke ch.createRichtextString(x) where x is a non empty String. So my fix atm is: ch.createRichTextString(s.isEmpty()? "" : s); where s is the String.
Fixed in r887160 Yegor