From bf989ca39ec8172b869df6ffc3e4f273155c0386 Mon Sep 17 00:00:00 2001 From: Nick Burch Date: Tue, 8 Jan 2008 16:20:48 +0000 Subject: [PATCH] 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 --- src/documentation/content/xdocs/changes.xml | 1 + .../content/xdocs/hssf/quick-guide.xml | 6 +- src/documentation/content/xdocs/status.xml | 1 + .../apache/poi/hssf/usermodel/HSSFSheet.java | 10 +++ .../apache/poi/hssf/util/AreaReference.java | 29 +++++++- .../apache/poi/hssf/util/CellReference.java | 4 ++ .../poi/hssf/util/TestAreaReference.java | 68 ++++++++++++++++++- 7 files changed, 114 insertions(+), 5 deletions(-) diff --git a/src/documentation/content/xdocs/changes.xml b/src/documentation/content/xdocs/changes.xml index b5d60ad17f..d0f4f0e642 100644 --- a/src/documentation/content/xdocs/changes.xml +++ b/src/documentation/content/xdocs/changes.xml @@ -36,6 +36,7 @@ + Support getting all the cells referenced by an AreaReference, not just the corner ones 43510 - Add support for named ranges in formulas, including non-contiguous named ranges 43937 - Add support for hiding and un-hiding sheets, and checking their current hidden status 44167 - Fix for non-contiguous named ranges diff --git a/src/documentation/content/xdocs/hssf/quick-guide.xml b/src/documentation/content/xdocs/hssf/quick-guide.xml index a7ca260c7a..b2f729fedc 100644 --- a/src/documentation/content/xdocs/hssf/quick-guide.xml +++ b/src/documentation/content/xdocs/hssf/quick-guide.xml @@ -1151,7 +1151,7 @@ Examples: // retrieve the cell at the named range and test its contents AreaReference aref = new AreaReference(aNamedCell.getReference()); - CellReference[] crefs = aref.getCells(); + CellReference[] crefs = aref.getAllReferencedCells(); for (int i=0; i<crefs.length; i++) { HSSFSheet s = wb.getSheet(crefs[i].getSheetName()); HSSFRow r = sheet.getRow(crefs[i].getRow()); @@ -1177,13 +1177,15 @@ Examples: // another for D12 to D14 AreaReference[] arefs = AreaReference.generateContiguous(aNamedCell.getReference()); for (int i=0; i<arefs.length; i++) { + // Only get the corners of the Area + // (use arefs[i].getAllReferencedCells() to get all cells) CellReference[] crefs = arefs[i].getCells(); for (int j=0; j<crefs.length; j++) { // Check it turns into real stuff HSSFSheet s = wb.getSheet(crefs[j].getSheetName()); HSSFRow r = s.getRow(crefs[j].getRow()); HSSFCell c = r.getCell(crefs[j].getCol()); - // extract the cell contents based on cell type etc. + // Do something with this corner cell } } diff --git a/src/documentation/content/xdocs/status.xml b/src/documentation/content/xdocs/status.xml index 58d6df9aa6..f4d7c1b07a 100644 --- a/src/documentation/content/xdocs/status.xml +++ b/src/documentation/content/xdocs/status.xml @@ -33,6 +33,7 @@ + Support getting all the cells referenced by an AreaReference, not just the corner ones 43510 - Add support for named ranges in formulas, including non-contiguous named ranges 43937 - Add support for hiding and un-hiding sheets, and checking their current hidden status 44167 - Fix for non-contiguous named ranges 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