Since the last update of the JRE the autoSizeColumn method in org.apache.poi.xssf.usermodel.XSSFSheet doesn't work anymore. It uses the method getCellWidth in org.apache.poi.ss.util.SheetUtil. This method uses the getBounds() Method of java.awt.font.TextLayout. And this delivers different values for JDK 1.6.43 and JDK 1.6.45
This sounds like it might be a JRE bug not a POI bug, in which case you'd need to report it to OpenJDK or Oracle (depending on who's JRE you use)
I had the same effect. It vanished when I set the font name to "Arial" explicitly in the CellStyle I use for the header row of my table. ... Font font = workbook.createFont(); font.setFontName("Arial"); style.setFont(font); ...
The problem is only with the fonts Calibri and Cambria. Exchanging the fontmanager.dll in jre/bin with an older version also solves the problem. So it is a JRE problem with Oracle JRE 1.6.0_45 and 1.7.0_21. I filed a bug at oracle (30.4.) but it is still invisible (at least for me) http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=9002214
To test your JRE use this bit of code. It prints the font name and a number. If the number is 0.0 than autosize won't work for that font. final java.awt.GraphicsEnvironment gEnv = java.awt.GraphicsEnvironment.getLocalGraphicsEnvironment(); final String envfonts[] = gEnv.getAvailableFontFamilyNames(); for(String font : envfonts) { final String txt = "Test"; final java.text.AttributedString str = new java.text.AttributedString(txt); str.addAttribute(java.awt.font.TextAttribute.FAMILY, font, 0, txt.length()); str.addAttribute(java.awt.font.TextAttribute.SIZE, (float) 14.0); str.addAttribute(java.awt.font.TextAttribute.WEIGHT, java.awt.font.TextAttribute.WEIGHT_BOLD, 0, txt.length()); final java.awt.font.FontRenderContext fontRenderContext = new java.awt.font.FontRenderContext(null, true, true); final java.awt.font.TextLayout layout = new java.awt.font.TextLayout(str.getIterator(), fontRenderContext); System.out.println(font + " : " + layout.getBounds().getWidth()); }