diff options
author | David North <dnorth@apache.org> | 2015-06-12 15:20:10 +0000 |
---|---|---|
committer | David North <dnorth@apache.org> | 2015-06-12 15:20:10 +0000 |
commit | 26dda73341d98dfec6026c72666640003832dcb1 (patch) | |
tree | 576d6308b779a5215ea71e660744efdb31abc96f /src/java/org/apache/poi/ss/util/AreaReference.java | |
parent | 0d55c0c7722b3eba58529f772dfbb53b2856415d (diff) | |
download | poi-26dda73341d98dfec6026c72666640003832dcb1.tar.gz poi-26dda73341d98dfec6026c72666640003832dcb1.zip |
My own patch to fix #56328
Add tests for initial patch applied by Nick in r1582892
Fix and test AreaReference#isWholeColumnReference to take account of the prevailing spreadsheet version. Fixing all users of this is a big undertaking, so for now I've left a fallback on the original behaviour for some cases.
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1685101 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/java/org/apache/poi/ss/util/AreaReference.java')
-rw-r--r-- | src/java/org/apache/poi/ss/util/AreaReference.java | 30 |
1 files changed, 22 insertions, 8 deletions
diff --git a/src/java/org/apache/poi/ss/util/AreaReference.java b/src/java/org/apache/poi/ss/util/AreaReference.java index d593888730..b0a69135a8 100644 --- a/src/java/org/apache/poi/ss/util/AreaReference.java +++ b/src/java/org/apache/poi/ss/util/AreaReference.java @@ -35,13 +35,23 @@ public class AreaReference { private final CellReference _firstCell; private final CellReference _lastCell; private final boolean _isSingleCell; + private SpreadsheetVersion _version; /** + * @deprecated Prefer supplying a version. + */ + @Deprecated + public AreaReference(String reference) { + this(reference, SpreadsheetVersion.EXCEL97); + } + + /** * Create an area ref from a string representation. Sheet names containing special characters should be * delimited and escaped as per normal syntax rules for formulas.<br/> * The area reference must be contiguous (i.e. represent a single rectangle, not a union of rectangles) */ - public AreaReference(String reference) { + public AreaReference(String reference, SpreadsheetVersion version) { + _version = version; if(! isContiguous(reference)) { throw new IllegalArgumentException( "References passed to the AreaReference must be contiguous, " + @@ -169,30 +179,34 @@ public class AreaReference { return false; } - public static AreaReference getWholeRow(String start, String end) { - return new AreaReference("$A" + start + ":$IV" + end); + public static AreaReference getWholeRow(SpreadsheetVersion version, String start, String end) { + return new AreaReference("$A" + start + ":$" + version.getLastColumnName() + end, version); } - public static AreaReference getWholeColumn(String start, String end) { - return new AreaReference(start + "$1:" + end + "$65536"); + public static AreaReference getWholeColumn(SpreadsheetVersion version, String start, String end) { + return new AreaReference(start + "$1:" + end + "$" + version.getMaxRows(), version); } /** * Is the reference for a whole-column reference, * such as C:C or D:G ? */ - public static boolean isWholeColumnReference(CellReference topLeft, CellReference botRight) { + public static boolean isWholeColumnReference(SpreadsheetVersion version, CellReference topLeft, CellReference botRight) { + if (null == version) { + version = SpreadsheetVersion.EXCEL97; // how the code used to behave. + } + // These are represented as something like // C$1:C$65535 or D$1:F$0 // i.e. absolute from 1st row to 0th one if(topLeft.getRow() == 0 && topLeft.isRowAbsolute() && - botRight.getRow() == SpreadsheetVersion.EXCEL97.getLastRowIndex() && botRight.isRowAbsolute()) { + botRight.getRow() == version.getLastRowIndex() && botRight.isRowAbsolute()) { return true; } return false; } public boolean isWholeColumnReference() { - return isWholeColumnReference(_firstCell, _lastCell); + return isWholeColumnReference(_version, _firstCell, _lastCell); } /** |