From d54a1370421938bb2c92c694f56038e64d67307b Mon Sep 17 00:00:00 2001 From: "Andrew C. Oliver" Date: Fri, 11 Apr 2003 02:58:23 +0000 Subject: [PATCH] http://nagoya.apache.org/bugzilla/show_bug.cgi?id=18090 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 | 29 +++++++++++- .../org/apache/poi/hssf/model/SheetTest.java | 46 +++++++++++++++++++ 2 files changed, 73 insertions(+), 2 deletions(-) diff --git a/src/java/org/apache/poi/hssf/model/Sheet.java b/src/java/org/apache/poi/hssf/model/Sheet.java index 63127a0870..7fe527217d 100644 --- a/src/java/org/apache/poi/hssf/model/Sheet.java +++ b/src/java/org/apache/poi/hssf/model/Sheet.java @@ -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 { diff --git a/src/testcases/org/apache/poi/hssf/model/SheetTest.java b/src/testcases/org/apache/poi/hssf/model/SheetTest.java index 28d2d13b37..e10ea4109d 100644 --- a/src/testcases/org/apache/poi/hssf/model/SheetTest.java +++ b/src/testcases/org/apache/poi/hssf/model/SheetTest.java @@ -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());} + + } + } -- 2.39.5