]> source.dussan.org Git - poi.git/commitdiff
improved autosizing columns in SXSSF, see Bug 51356
authorYegor Kozlov <yegor@apache.org>
Sat, 18 Jun 2011 08:39:03 +0000 (08:39 +0000)
committerYegor Kozlov <yegor@apache.org>
Sat, 18 Jun 2011 08:39:03 +0000 (08:39 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1137138 13f79535-47bb-0310-9956-ffa450edef68

src/ooxml/java/org/apache/poi/xssf/streaming/SXSSFSheet.java

index e5e27cdfe11329d1aa4bac13ba5a340883f35653..a7e7d1ce2cd902b69d089970114ced9abddf8bba 100644 (file)
@@ -1069,8 +1069,14 @@ public class SXSSFSheet implements Sheet, Cloneable
     public void autoSizeColumn(int column, boolean useMergedCells)
     {
         double width = SheetUtil.getColumnWidth(this, column, useMergedCells);
-        if(width != -1){
-            setColumnWidth(column, (int)(width*256));
+
+        if (width != -1) {
+            width *= 256;
+            int maxColumnWidth = 255*256; // The maximum column width for an individual cell is 255 characters
+            if (width > maxColumnWidth) {
+                width = maxColumnWidth;
+            }
+            setColumnWidth(column, (int)(width));
         }
     }