poi-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ye...@apache.org
Subject svn commit: r1136330 - in /poi/trunk/src: documentation/content/xdocs/status.xml java/org/apache/poi/hssf/usermodel/HSSFSheet.java ooxml/java/org/apache/poi/xssf/usermodel/XSSFSheet.java testcases/org/apache/poi/ss/usermodel/BaseTestBugzillaIssues.java
Date Thu, 16 Jun 2011 08:57:55 GMT
Author: yegor
Date: Thu Jun 16 08:57:55 2011
New Revision: 1136330

URL: http://svn.apache.org/viewvc?rev=1136330&view=rev
Log:
Bug 50681 - Fixed autosizing columns beyond 255 character limit

Modified:
    poi/trunk/src/documentation/content/xdocs/status.xml
    poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFSheet.java
    poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSheet.java
    poi/trunk/src/testcases/org/apache/poi/ss/usermodel/BaseTestBugzillaIssues.java

Modified: poi/trunk/src/documentation/content/xdocs/status.xml
URL: http://svn.apache.org/viewvc/poi/trunk/src/documentation/content/xdocs/status.xml?rev=1136330&r1=1136329&r2=1136330&view=diff
==============================================================================
--- poi/trunk/src/documentation/content/xdocs/status.xml (original)
+++ poi/trunk/src/documentation/content/xdocs/status.xml Thu Jun 16 08:57:55 2011
@@ -34,6 +34,7 @@
 
     <changes>
         <release version="3.8-beta4" date="2011-??-??">
+           <action dev="poi-developers" type="add">50681 - Fixed autosizing columns
beyond 255 character limit </action>
            <action dev="poi-developers" type="add">51374 - Fixed incorrect setting
of lastPrinted OOXML core property </action>
            <action dev="poi-developers" type="add">51351 - Word to XSL-FO converter</action>
            <action dev="poi-developers" type="add">50458 - Fixed missing shapeId in
XSSF drawings </action>

Modified: poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFSheet.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFSheet.java?rev=1136330&r1=1136329&r2=1136330&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFSheet.java (original)
+++ poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFSheet.java Thu Jun 16 08:57:55 2011
@@ -1764,7 +1764,16 @@ public final class HSSFSheet implements 
      */
     public void autoSizeColumn(int column, boolean useMergedCells) {
         double width = SheetUtil.getColumnWidth(this, column, useMergedCells);
-        if(width != -1) setColumnWidth(column, (int) (256*width));
+
+        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));
+        }
+
     }
 
     /**

Modified: poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSheet.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSheet.java?rev=1136330&r1=1136329&r2=1136330&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSheet.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSheet.java Thu Jun 16 08:57:55
2011
@@ -381,10 +381,15 @@ public class XSSFSheet extends POIXMLDoc
      */
     public void autoSizeColumn(int column, boolean useMergedCells) {
         double width = SheetUtil.getColumnWidth(this, column, useMergedCells);
-        if(width != -1){
+
+        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));
             columnHelper.setColBestFit(column, true);
-            columnHelper.setCustomWidth(column, true);
-            columnHelper.setColWidth(column, width);
         }
     }
 

Modified: poi/trunk/src/testcases/org/apache/poi/ss/usermodel/BaseTestBugzillaIssues.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/ss/usermodel/BaseTestBugzillaIssues.java?rev=1136330&r1=1136329&r2=1136330&view=diff
==============================================================================
--- poi/trunk/src/testcases/org/apache/poi/ss/usermodel/BaseTestBugzillaIssues.java (original)
+++ poi/trunk/src/testcases/org/apache/poi/ss/usermodel/BaseTestBugzillaIssues.java Thu Jun
16 08:57:55 2011
@@ -306,4 +306,24 @@ public abstract class BaseTestBugzillaIs
         fmla.append(")");
         return fmla.toString();
     }
+
+    public final void testAutoSize_bug506819() {
+        Workbook wb = _testDataProvider.createWorkbook();
+        Sheet sheet = wb.createSheet("Sheet1");
+        Row row = sheet.createRow(0);
+        Cell cell0 = row.createCell(0);
+
+        String longValue = "www.hostname.com, www.hostname.com, " +
+                "www.hostname.com, www.hostname.com, www.hostname.com, " +
+                "www.hostname.com, www.hostname.com, www.hostname.com, " +
+                "www.hostname.com, www.hostname.com, www.hostname.com, " +
+                "www.hostname.com, www.hostname.com, www.hostname.com, " +
+                "www.hostname.com, www.hostname.com, www.hostname.com, www.hostname.com";
+
+        cell0.setCellValue(longValue);
+
+        sheet.autoSizeColumn(0);
+        assertEquals(255*256, sheet.getColumnWidth(0)); // maximum column width is 255 characters
+        sheet.setColumnWidth(0, sheet.getColumnWidth(0)); // Bug 506819 reports exception
at this point
+    }
 }



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org


Mime
View raw message