]> source.dussan.org Git - poi.git/commitdiff
http://nagoya.apache.org/bugzilla/show_bug.cgi?id=18090
authorAndrew C. Oliver <acoliver@apache.org>
Fri, 11 Apr 2003 02:58:23 +0000 (02:58 +0000)
committerAndrew C. Oliver <acoliver@apache.org>
Fri, 11 Apr 2003 02:58:23 +0000 (02:58 +0000)
PR:
Obtained from:
Submitted by:
Reviewed by:

git-svn-id: https://svn.apache.org/repos/asf/jakarta/poi/trunk@353056 13f79535-47bb-0310-9956-ffa450edef68

src/java/org/apache/poi/hssf/model/Sheet.java
src/testcases/org/apache/poi/hssf/model/SheetTest.java

index 63127a08701afee49525d7f4a19097808f44d862..7fe527217db139c871973993838b6d93bb46e96f 100644 (file)
@@ -1856,7 +1856,7 @@ public class Sheet implements Model
             for (k = 0; k < columnSizes.size(); k++)
             {
                 ci = ( ColumnInfoRecord ) columnSizes.get(k);
-                if ((ci.getFirstColumn() >= column)
+                if ((ci.getFirstColumn() <= column)
                         && (column <= ci.getLastColumn()))
                 {
                     break;
@@ -1895,7 +1895,7 @@ public class Sheet implements Model
         for (k = 0; k < columnSizes.size(); k++)
         {
             ci = ( ColumnInfoRecord ) columnSizes.get(k);
-            if ((ci.getFirstColumn() >= column)
+            if ((ci.getFirstColumn() <= column)
                     && (column <= ci.getLastColumn()))
             {
                 break;
@@ -1939,6 +1939,31 @@ public class Sheet implements Model
                 records.add((1 + getDimsLoc() - columnSizes.size()) + k, nci);
                 dimsloc++;
             }
+            else{
+                //split to 3 records
+                short lastcolumn = ci.getLastColumn();
+                ci.setLastColumn(( short ) (column - 1));
+
+                ColumnInfoRecord nci = ( ColumnInfoRecord ) createColInfo();
+                nci.setFirstColumn(column);
+                nci.setLastColumn(column);
+                nci.setOptions(ci.getOptions());
+                nci.setXFIndex(ci.getXFIndex());
+                nci.setColumnWidth(width);
+                columnSizes.add(k, nci);
+                records.add((1 + getDimsLoc() - columnSizes.size()) + k, nci);
+                dimsloc++;
+
+                nci = ( ColumnInfoRecord ) createColInfo();
+                nci.setFirstColumn((short)(column+1));
+                nci.setLastColumn(lastcolumn);
+                nci.setOptions(ci.getOptions());
+                nci.setXFIndex(ci.getXFIndex());
+                nci.setColumnWidth(ci.getColumnWidth());
+                columnSizes.add(k, nci);
+                records.add((1 + getDimsLoc() - columnSizes.size()) + k, nci);
+                dimsloc++;
+            }
         }
         else
         {
index 28d2d13b37ce15ff17e5d82c59e79898f0123c1e..e10ea4109dba80fc02c622f7bf3e5ac3555647c1 100644 (file)
@@ -1,7 +1,13 @@
 package org.apache.poi.hssf.model;
 
+import java.lang.reflect.Field;
+import java.util.ArrayList;
+import java.util.List;
+
 import junit.framework.TestCase;
 
+import org.apache.poi.hssf.record.ColumnInfoRecord;
+
 /**
  * @author Tony Poppleton
  */
@@ -73,6 +79,46 @@ public class SheetTest extends TestCase
                //TODO
        }
 
+       public void testGetCellWidth()
+       {
+               try{
+                       Sheet sheet = Sheet.createSheet();
+                       ColumnInfoRecord nci = ( ColumnInfoRecord ) sheet.createColInfo();
+       
+                       //prepare test model
+                       nci.setFirstColumn((short)5);
+                       nci.setLastColumn((short)10);
+                       nci.setColumnWidth((short)100);
+                       Field f = Sheet.class.getDeclaredField("columnSizes");
+                       f.setAccessible(true);
+                       List columnSizes = new ArrayList();
+                       f.set(sheet,columnSizes);
+                       columnSizes.add(nci);
+                       sheet.records.add(1 + sheet.dimsloc, nci);
+                       sheet.dimsloc++;
+       
+                       assertEquals((short)100,sheet.getColumnWidth((short)5));
+                       assertEquals((short)100,sheet.getColumnWidth((short)6));
+                       assertEquals((short)100,sheet.getColumnWidth((short)7));
+                       assertEquals((short)100,sheet.getColumnWidth((short)8));
+                       assertEquals((short)100,sheet.getColumnWidth((short)9));
+                       assertEquals((short)100,sheet.getColumnWidth((short)10));
+
+                       sheet.setColumnWidth((short)6,(short)200);
+
+                       assertEquals((short)100,sheet.getColumnWidth((short)5));
+                       assertEquals((short)200,sheet.getColumnWidth((short)6));
+                       assertEquals((short)100,sheet.getColumnWidth((short)7));
+                       assertEquals((short)100,sheet.getColumnWidth((short)8));
+                       assertEquals((short)100,sheet.getColumnWidth((short)9));
+                       assertEquals((short)100,sheet.getColumnWidth((short)10));
+                       
+
+               }
+               catch(Exception e){e.printStackTrace();fail(e.getMessage());}
+
+       }
+
 }