for (k = 0; k < columnSizes.size(); k++)
{
ci = ( ColumnInfoRecord ) columnSizes.get(k);
- if ((ci.getFirstColumn() >= column)
+ if ((ci.getFirstColumn() <= column)
&& (column <= ci.getLastColumn()))
{
break;
for (k = 0; k < columnSizes.size(); k++)
{
ci = ( ColumnInfoRecord ) columnSizes.get(k);
- if ((ci.getFirstColumn() >= column)
+ if ((ci.getFirstColumn() <= column)
&& (column <= ci.getLastColumn()))
{
break;
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
{
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
*/
//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());}
+
+ }
+
}