Bug 54904 - autoSizeColumn doesn't work with new JDK/JRE 1.6.45 or 1.7.21
Summary: autoSizeColumn doesn't work with new JDK/JRE 1.6.45 or 1.7.21
Status: RESOLVED INVALID
Alias: None
Product: POI
Classification: Unclassified
Component: XSSF (show other bugs)
Version: 3.9-FINAL
Hardware: PC All
: P2 normal (vote)
Target Milestone: ---
Assignee: POI Developers List
URL:
Keywords:
Depends on:
Blocks: 57469
  Show dependency tree
 
Reported: 2013-04-29 13:47 UTC by jens.popp
Modified: 2015-07-24 12:22 UTC (History)
0 users



Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description jens.popp 2013-04-29 13:47:22 UTC
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
Comment 1 Nick Burch 2013-04-29 13:57:15 UTC
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)
Comment 2 anonymous 2013-05-13 09:40:57 UTC
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);
...
Comment 3 jens.popp 2013-05-23 07:35:41 UTC
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
Comment 4 jens.popp 2013-05-23 07:40:42 UTC
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());
}