I generated one excel file using below program. When I open excel in Office 2010, then column selected for autoSizeColumn is hiding. If I remove the autoSizecolumn, then it works normally. public class Automation { public static void main(String[] args) { XSSFWorkbook workbook = new XSSFWorkbook(); XSSFSheet sheet = workbook.createSheet("students"); XSSFRow row = sheet.createRow(1); XSSFCell cell = row.createCell(1); cell.setCellValue("sandeepzzzzzzzzzzzzzzzzzzzzzzzzz"); sheet.autoSizeColumn(1); try { FileOutputStream fileOut = new FileOutputStream("workbook.xlsx"); workbook.write(fileOut); fileOut.close(); }catch(Exception e) { } } }
Is the column hidden, or just set to a zero width?
Column is hiding. After I select the columns and Right click -> Unhide, then I'm able to see the result. (In reply to Nick Burch from comment #1) > Is the column hidden, or just set to a zero width?
I'm getting the same behavior using Excel 2013 and poi 3.9 If you set a numeric value (even as a String) then the column is auto-sized correctly, for example: cell.setCellValue("12345678987654321");
I am seeing the same behavior with JDK 1.6.0_45.
Tried with latest trunk and OpenOffice/LibreOffice, but could not reproduce, will try on Windows with Excel as well.
I have seen this behavior with POI-3.9 as well. Updating to POI-3.10 has resolved this issue for me. The columns are not hidden but just have no width. The trick is to select all columns and then choose Show (last entry of context menu) to make them visible again.
I tried it with Excel 2013, the column is autosized correctly when using POI 3.11-beta2/trunk. Therefore I am resolving this for now, please reopen with detailed version information if you still see this problem with recent versions of POI.
Hi, I never succeded to reproduce on a dev environment however this seems to always happen on some customers production environment using POI 3.9 and with different JVM versions. I found a Stack Overflow topic that seems to be related to this bug (stackoverflow.com/a/14389179/1069454) Is there a known list of steps/conditions required to reproduce this issue? Could you also please clarify if the issue was reproduced at some point and fixed in 3.11 or if it was never reproduced by POI team. From the status (WORKSFORME) I guess it was never reproduced by POI team right?
I was able to reproduce the problem using poi 3.9.0, 3.10 and 3.11-beta2 on windows 7 with oracle jre 7u21. This works fine with jre 7u67 on windows 7. I was not able to reproduce on ubuntu with oracle jre 7u21.
Debugging shows that using oracle jre 7u21 layout.getBounds().getWidth() returns 0 in org.apache.poi.ss.util.SheetUtil.getCellWidth(Cell, int, DataFormatter, boolean) This may be related to this jdk bug https://bugs.openjdk.java.net/browse/JDK-8013716. The problem can be mitigated by detecting when auto sizing fails and using a minimal width: sheet.autoSizeColumn(0) if (sheet.getColumnWidth(0) == 0) { // autosize failed use MIN_WIDTH sheet.setColumnWidth(0, MIN_WIDTH); }
Upgrading to a non-broken JVM is probably the right fix here!
I also think that we rather should require an recently patched version of Java, therefore closing this WONTFIX for now. There are many security related and many bug fixes in those newer patchlevels, so upgrading is generally a good idea.