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
This commit is contained in:
parent
b4783debb6
commit
07912d07d5
@ -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
|
||||
{
|
||||
|
@ -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());}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user