https://issues.apache.org/bugzilla/show_bug.cgi?id=47082
Muhammed <[email protected]> changed: What |Removed |Added ---------------------------------------------------------------------------- Status|RESOLVED |REOPENED Resolution|WONTFIX | --- Comment #8 from Muhammed <[email protected]> 2009-04-28 22:39:24 PST --- I have a workaround for this. If I replace all whitespaces with some character(say āIā ā the one which take least width), autoSize seems to be working fine. For those who uses jdk 1.4 & 1.5, is it possible to provide a patch like this? See the line below - txt = txt.replaceAll(" ", "i"); public void autoSizeColumn(short column, boolean useMergedCells) { AttributedString str; TextLayout layout; /** * Excel measures columns in units of 1/256th of a character width * but the docs say nothing about what particular character is used. * '0' looks to be a good choice. */ char defaultChar = '0'; /** * This is the multiple that the font height is scaled by when determining the * boundary of rotated text. */ double fontHeightMultiple = 2.0; FontRenderContext frc = new FontRenderContext(null, true, true); HSSFWorkbook wb = new HSSFWorkbook(book); HSSFFont defaultFont = wb.getFontAt((short) 0); str = new AttributedString("" + defaultChar); copyAttributes(defaultFont, str, 0, 1); layout = new TextLayout(str.getIterator(), frc); int defaultCharWidth = (int)layout.getAdvance(); double width = -1; rows: for (Iterator it = rowIterator(); it.hasNext();) { HSSFRow row = (HSSFRow) it.next(); HSSFCell cell = row.getCell(column); if (cell == null) { continue; } int colspan = 1; for (int i = 0 ; i < getNumMergedRegions(); i++) { CellRangeAddress region = getMergedRegion(i); if (containsCell(region, row.getRowNum(), column)) { if (!useMergedCells) { // If we're not using merged cells, skip this one and move on to the next. continue rows; } cell = row.getCell(region.getFirstColumn()); colspan = 1 + region.getLastColumn() - region.getFirstColumn(); } } HSSFCellStyle style = cell.getCellStyle(); HSSFFont font = wb.getFontAt(style.getFontIndex()); if (cell.getCellType() == HSSFCell.CELL_TYPE_STRING) { HSSFRichTextString rt = cell.getRichStringCellValue(); String[] lines = rt.getString().split("\\n"); for (int i = 0; i < lines.length; i++) { String txt = lines[i] + defaultChar; txt = txt.replaceAll(" ", "i"); ... ... -- Configure bugmail: https://issues.apache.org/bugzilla/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- You are the assignee for the bug. --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
