Workbook wb = new XSSFWorkbook(); CreationHelper createHelper = wb.getCreationHelper(); Sheet sheet = wb.createSheet(); Row row = sheet.createRow(0); CellStyle cellStyle = wb.createCellStyle(); cellStyle.setDataFormat((short) 14); Cell cell = row.createCell(0); cell.setCellType(Cell.CELL_TYPE_NUMERIC); cell.setCellValue(new Date("13-jan-2013")); cell.setCellStyle(cellStyle); cell = row.createCell(1); cell.setCellType(Cell.CELL_TYPE_STRING); cell.setCellValue("13-jan-2013"); cell.setCellStyle(cellStyle); sheet.autoSizeColumn(0, false); sheet.autoSizeColumn(1, false); In the above example I am adding 2 cells to different columns. One has string type value and other has date type value. Value is same "13-jan-2013" When I call autosizecolumn in both columns, first ccolumn doesnt exapnd to fit in the data whereas 2nd column expands properly. I noticed this thing : Internally autosizecolumn is using SheetUtil.getColumnWidth to get current max width of column. It is returning a value of 8 something. Previously autosizecolumn was using ColumnHelper.getColumnWidth method and used to return 12 for same data ("13-jan-2013"). This is why in previous version autosizecolumn was working properly for even date type fields
Do you have the correct fonts installed on your system and available to Java? POI uses the fonts to work out how wide columns are, and it can't get it right if Java doesn't have the fonts you're using available. Are they all correctly there?
The same code if I run with 3.7 version runs fine and it properly autosizes the column But in 3.9 version it doesnt and internal implemented method returns lesser value of max column width. Both examples I have run on same system. Plus we have also run on other testing systems So I don't think fonts are the issue
Any progress on this bug?
i don't see a bug here. you are formatting the Date Cell with format id 14 which seems to be locale dependent. i tried this snippet XSSFDataFormat format = wb.createDataFormat(); cellStyle.setDataFormat(format.getFormat("dd-MMM-yyyy")); and both Colums are properly sized.