From 2f8a62abc70189703947d1e8df38206cd0f32a15 Mon Sep 17 00:00:00 2001 From: Yegor Kozlov Date: Mon, 5 May 2008 13:59:11 +0000 Subject: [PATCH] take into account indentation in HSSFSheet.autosizeColumn git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@653484 13f79535-47bb-0310-9956-ffa450edef68 --- src/documentation/content/xdocs/changes.xml | 2 +- .../org/apache/poi/hssf/usermodel/HSSFSheet.java | 12 +++++++----- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/documentation/content/xdocs/changes.xml b/src/documentation/content/xdocs/changes.xml index fee7028097..150b41ff9d 100644 --- a/src/documentation/content/xdocs/changes.xml +++ b/src/documentation/content/xdocs/changes.xml @@ -43,7 +43,7 @@ 44914 - Fix/suppress warning message "WARN. Unread n bytes of record 0xNN" 44892 - made HSSFWorkbook.getSheet(String) case insensitive 44886] - Correctly process PICT metafile in EscherMetafileBlip - 44893 - Correctly handle merged regions in HSSFSheet.autoSizeColumn + 44893 - Take into account indentation in HSSFSheet.autoSizeColumn 44857 - Avoid OOM on unknown escher records when EscherMetafileBlip is incorrect diff --git a/src/java/org/apache/poi/hssf/usermodel/HSSFSheet.java b/src/java/org/apache/poi/hssf/usermodel/HSSFSheet.java index b6d8d5723f..b56122688e 100644 --- a/src/java/org/apache/poi/hssf/usermodel/HSSFSheet.java +++ b/src/java/org/apache/poi/hssf/usermodel/HSSFSheet.java @@ -1710,6 +1710,8 @@ public final class HSSFSheet { HSSFCellStyle style = cell.getCellStyle(); HSSFFont font = wb.getFontAt(style.getFontIndex()); + //the number of spaces to indent the text in the cell + int indention = style.getIndention(); if (cell.getCellType() == HSSFCell.CELL_TYPE_STRING) { HSSFRichTextString rt = cell.getRichStringCellValue(); @@ -1742,9 +1744,9 @@ public final class HSSFSheet { trans.concatenate( AffineTransform.getScaleInstance(1, fontHeightMultiple) ); - width = Math.max(width, layout.getOutline(trans).getBounds().getWidth() / defaultCharWidth); + width = Math.max(width, layout.getOutline(trans).getBounds().getWidth() / defaultCharWidth + indention); } else { - width = Math.max(width, layout.getBounds().getWidth() / defaultCharWidth); + width = Math.max(width, layout.getBounds().getWidth() / defaultCharWidth + indention); } } } else { @@ -1787,15 +1789,15 @@ public final class HSSFSheet { trans.concatenate( AffineTransform.getScaleInstance(1, fontHeightMultiple) ); - width = Math.max(width, layout.getOutline(trans).getBounds().getWidth() / defaultCharWidth); + width = Math.max(width, layout.getOutline(trans).getBounds().getWidth() / defaultCharWidth + indention); } else { - width = Math.max(width, layout.getBounds().getWidth() / defaultCharWidth); + width = Math.max(width, layout.getBounds().getWidth() / defaultCharWidth + indention); } } } if (width != -1) { - if (width > Short.MAX_VALUE) { //width can be bigger that Short.MAX_VALUE! + if (width > Short.MAX_VALUE) { //calculated width can be greater that Short.MAX_VALUE! width = Short.MAX_VALUE; } sheet.setColumnWidth(column, (short) (width * 256)); -- 2.39.5