aboutsummaryrefslogtreecommitdiffstats
path: root/src/java/org/apache/poi/hssf
diff options
context:
space:
mode:
authorNick Burch <nick@apache.org>2008-01-08 16:20:48 +0000
committerNick Burch <nick@apache.org>2008-01-08 16:20:48 +0000
commitbf989ca39ec8172b869df6ffc3e4f273155c0386 (patch)
treeea2eadf00fd28e0d165fe9c8355f3ccb72428e4e /src/java/org/apache/poi/hssf
parent33dbe52e16f8ccaf5f9203e419c910a8a0741472 (diff)
downloadpoi-bf989ca39ec8172b869df6ffc3e4f273155c0386.tar.gz
poi-bf989ca39ec8172b869df6ffc3e4f273155c0386.zip
Add a new method onto AreaReference to get all the cells referenced, not just the corners. Includes tests for this
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@610048 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/java/org/apache/poi/hssf')
-rw-r--r--src/java/org/apache/poi/hssf/usermodel/HSSFSheet.java10
-rw-r--r--src/java/org/apache/poi/hssf/util/AreaReference.java29
-rw-r--r--src/java/org/apache/poi/hssf/util/CellReference.java4
3 files changed, 42 insertions, 1 deletions
diff --git a/src/java/org/apache/poi/hssf/usermodel/HSSFSheet.java b/src/java/org/apache/poi/hssf/usermodel/HSSFSheet.java
index ba9ff72a7e..b0d8222865 100644
--- a/src/java/org/apache/poi/hssf/usermodel/HSSFSheet.java
+++ b/src/java/org/apache/poi/hssf/usermodel/HSSFSheet.java
@@ -1212,6 +1212,16 @@ public class HSSFSheet
}
if ( endRow == lastrow || endRow + n > lastrow ) lastrow = Math.min( endRow + n, 65535 );
if ( startRow == firstrow || startRow + n < firstrow ) firstrow = Math.max( startRow + n, 0 );
+
+ // Update any formulas on this sheet that point to
+ // rows which have been moved
+
+ // Update any named ranges defined for this workbook
+ // that point to this sheet and had rows they reference
+ // moved
+ for(int i=0; i<workbook.getNumberOfNames(); i++) {
+ HSSFName name = workbook.getNameAt(i);
+ }
}
protected void insertChartRecords( List records )
diff --git a/src/java/org/apache/poi/hssf/util/AreaReference.java b/src/java/org/apache/poi/hssf/util/AreaReference.java
index ae83431983..8169378e76 100644
--- a/src/java/org/apache/poi/hssf/util/AreaReference.java
+++ b/src/java/org/apache/poi/hssf/util/AreaReference.java
@@ -79,10 +79,37 @@ private int dim;
public int getDim() {
return dim;
}
- /** return the cell references that define this area */
+ /**
+ * Return the cell references that define this area
+ * (i.e. the two corners)
+ */
public CellReference[] getCells() {
return cells;
}
+ /**
+ * Returns a reference to every cell covered by this area
+ */
+ public CellReference[] getAllReferencedCells() {
+ // Special case for single cell reference
+ if(cells.length == 1) {
+ return cells;
+ }
+ // Interpolate between the two
+ int minRow = Math.min(cells[0].getRow(), cells[1].getRow());
+ int maxRow = Math.max(cells[0].getRow(), cells[1].getRow());
+ int minCol = Math.min(cells[0].getCol(), cells[1].getCol());
+ int maxCol = Math.max(cells[0].getCol(), cells[1].getCol());
+
+ ArrayList refs = new ArrayList();
+ for(int row=minRow; row<=maxRow; row++) {
+ for(int col=minCol; col<=maxCol; col++) {
+ CellReference ref = new CellReference(row, col, cells[0].isRowAbsolute(), cells[0].isColAbsolute());
+ ref.setSheetName(cells[0].getSheetName());
+ refs.add(ref);
+ }
+ }
+ return (CellReference[])refs.toArray(new CellReference[refs.size()]);
+ }
public String toString() {
StringBuffer retval = new StringBuffer();
diff --git a/src/java/org/apache/poi/hssf/util/CellReference.java b/src/java/org/apache/poi/hssf/util/CellReference.java
index 0bc1cee2e3..def58472a8 100644
--- a/src/java/org/apache/poi/hssf/util/CellReference.java
+++ b/src/java/org/apache/poi/hssf/util/CellReference.java
@@ -69,6 +69,10 @@ public class CellReference {
public boolean isRowAbsolute(){return rowAbs;}
public boolean isColAbsolute(){return colAbs;}
public String getSheetName(){return sheetName;}
+
+ protected void setSheetName(String sheetName) {
+ this.sheetName = sheetName;
+ }
/**
* takes in a column reference portion of a CellRef and converts it from