diff options
author | PJ Fanning <fanningpj@apache.org> | 2017-06-28 22:11:26 +0000 |
---|---|---|
committer | PJ Fanning <fanningpj@apache.org> | 2017-06-28 22:11:26 +0000 |
commit | 5d4a4a7f28047195f0f2cd349ffa474a1a4b0297 (patch) | |
tree | d883c20bd796548703cbd1ecb8c863b01daa8eb0 /src/java/org/apache | |
parent | c80988698fa2acea720b7ed8e1c09b71b23b56f8 (diff) | |
download | poi-5d4a4a7f28047195f0f2cd349ffa474a1a4b0297.tar.gz poi-5d4a4a7f28047195f0f2cd349ffa474a1a4b0297.zip |
Ensure SpreadsheetVersion is set for AreaReferences
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1800208 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/java/org/apache')
9 files changed, 97 insertions, 27 deletions
diff --git a/src/java/org/apache/poi/hssf/usermodel/HSSFCreationHelper.java b/src/java/org/apache/poi/hssf/usermodel/HSSFCreationHelper.java index 027a11f22d..754930f13b 100644 --- a/src/java/org/apache/poi/hssf/usermodel/HSSFCreationHelper.java +++ b/src/java/org/apache/poi/hssf/usermodel/HSSFCreationHelper.java @@ -20,6 +20,8 @@ package org.apache.poi.hssf.usermodel; import org.apache.poi.common.usermodel.HyperlinkType; import org.apache.poi.hssf.record.common.ExtendedColor; import org.apache.poi.ss.usermodel.CreationHelper; +import org.apache.poi.ss.util.AreaReference; +import org.apache.poi.ss.util.CellReference; import org.apache.poi.util.Internal; public class HSSFCreationHelper implements CreationHelper { @@ -75,4 +77,21 @@ public class HSSFCreationHelper implements CreationHelper { public HSSFClientAnchor createClientAnchor(){ return new HSSFClientAnchor(); } + + /** + * {@inheritDoc} + */ + @Override + public AreaReference createAreaReference(String reference) { + return new AreaReference(reference, workbook.getSpreadsheetVersion()); + } + + /** + * {@inheritDoc} + */ + @Override + public AreaReference createAreaReference(CellReference topLeft, CellReference bottomRight) { + return new AreaReference(topLeft, bottomRight, workbook.getSpreadsheetVersion()); + } + } diff --git a/src/java/org/apache/poi/hssf/util/AreaReference.java b/src/java/org/apache/poi/hssf/util/AreaReference.java index 3474abff7b..3e3b26e229 100644 --- a/src/java/org/apache/poi/hssf/util/AreaReference.java +++ b/src/java/org/apache/poi/hssf/util/AreaReference.java @@ -17,6 +17,8 @@ package org.apache.poi.hssf.util; +import org.apache.poi.ss.SpreadsheetVersion; + /** * @deprecated POI 3.15 beta 3. Use {@link org.apache.poi.ss.util.AreaReference} instead. */ @@ -28,7 +30,7 @@ public final class AreaReference extends org.apache.poi.ss.util.AreaReference { * The area reference must be contiguous (i.e. represent a single rectangle, not a union of rectangles) */ public AreaReference(String reference) { - super(reference); + super(reference, SpreadsheetVersion.EXCEL97); } /** diff --git a/src/java/org/apache/poi/ss/formula/FormulaParser.java b/src/java/org/apache/poi/ss/formula/FormulaParser.java index cdfc3536db..7af8668b2e 100644 --- a/src/java/org/apache/poi/ss/formula/FormulaParser.java +++ b/src/java/org/apache/poi/ss/formula/FormulaParser.java @@ -817,7 +817,7 @@ public final class FormulaParser { CellReference topLeft = new CellReference(actualStartRow, actualStartCol); CellReference bottomRight = new CellReference(actualEndRow, actualEndCol); SheetIdentifier sheetIden = new SheetIdentifier( null, new NameIdentifier(sheetName, true)); - Ptg ptg = _book.get3DReferencePtg(new AreaReference(topLeft, bottomRight), sheetIden); + Ptg ptg = _book.get3DReferencePtg(new AreaReference(topLeft, bottomRight, _ssVersion), sheetIden); return new ParseNode(ptg); } @@ -997,7 +997,7 @@ public final class FormulaParser { if (part1.isColumn()) { return AreaReference.getWholeColumn(_ssVersion, part1.getRep(), part2.getRep()); } - return new AreaReference(part1.getCellReference(), part2.getCellReference()); + return new AreaReference(part1.getCellReference(), part2.getCellReference(), _ssVersion); } /** diff --git a/src/java/org/apache/poi/ss/formula/ptg/Area3DPtg.java b/src/java/org/apache/poi/ss/formula/ptg/Area3DPtg.java index 7bf64c0675..3eeddadc7d 100644 --- a/src/java/org/apache/poi/ss/formula/ptg/Area3DPtg.java +++ b/src/java/org/apache/poi/ss/formula/ptg/Area3DPtg.java @@ -17,6 +17,7 @@ package org.apache.poi.ss.formula.ptg; +import org.apache.poi.ss.SpreadsheetVersion; import org.apache.poi.ss.formula.ExternSheetReferenceToken; import org.apache.poi.ss.formula.FormulaRenderingWorkbook; import org.apache.poi.ss.formula.WorkbookDependentFormula; @@ -41,7 +42,7 @@ public final class Area3DPtg extends AreaPtgBase implements WorkbookDependentFor public Area3DPtg(String arearef, int externIdx) { - super(new AreaReference(arearef)); + super(new AreaReference(arearef, SpreadsheetVersion.EXCEL97)); setExternSheetIndex(externIdx); } diff --git a/src/java/org/apache/poi/ss/formula/ptg/Area3DPxg.java b/src/java/org/apache/poi/ss/formula/ptg/Area3DPxg.java index 2916211b64..abb2dfaede 100644 --- a/src/java/org/apache/poi/ss/formula/ptg/Area3DPxg.java +++ b/src/java/org/apache/poi/ss/formula/ptg/Area3DPxg.java @@ -17,6 +17,7 @@ package org.apache.poi.ss.formula.ptg; +import org.apache.poi.ss.SpreadsheetVersion; import org.apache.poi.ss.formula.SheetIdentifier; import org.apache.poi.ss.formula.SheetNameFormatter; import org.apache.poi.ss.formula.SheetRangeIdentifier; @@ -37,7 +38,7 @@ public final class Area3DPxg extends AreaPtgBase implements Pxg3D { private String lastSheetName; public Area3DPxg(int externalWorkbookNumber, SheetIdentifier sheetName, String arearef) { - this(externalWorkbookNumber, sheetName, new AreaReference(arearef)); + this(externalWorkbookNumber, sheetName, new AreaReference(arearef, SpreadsheetVersion.EXCEL2007)); } public Area3DPxg(int externalWorkbookNumber, SheetIdentifier sheetName, AreaReference arearef) { super(arearef); @@ -51,7 +52,7 @@ public final class Area3DPxg extends AreaPtgBase implements Pxg3D { } public Area3DPxg(SheetIdentifier sheetName, String arearef) { - this(sheetName, new AreaReference(arearef)); + this(sheetName, new AreaReference(arearef, SpreadsheetVersion.EXCEL2007)); } public Area3DPxg(SheetIdentifier sheetName, AreaReference arearef) { this(-1, sheetName, arearef); diff --git a/src/java/org/apache/poi/ss/formula/ptg/AreaPtg.java b/src/java/org/apache/poi/ss/formula/ptg/AreaPtg.java index a0bb8f696e..81cac4e043 100644 --- a/src/java/org/apache/poi/ss/formula/ptg/AreaPtg.java +++ b/src/java/org/apache/poi/ss/formula/ptg/AreaPtg.java @@ -17,8 +17,10 @@ package org.apache.poi.ss.formula.ptg; +import org.apache.poi.ss.SpreadsheetVersion; import org.apache.poi.ss.util.AreaReference; import org.apache.poi.util.LittleEndianInput; +import org.apache.poi.util.Removal; /** * Specifies a rectangular area of cells A1:A4 for instance. @@ -30,15 +32,24 @@ public final class AreaPtg extends Area2DPtgBase { public AreaPtg(int firstRow, int lastRow, int firstColumn, int lastColumn, boolean firstRowRelative, boolean lastRowRelative, boolean firstColRelative, boolean lastColRelative) { super(firstRow, lastRow, firstColumn, lastColumn, firstRowRelative, lastRowRelative, firstColRelative, lastColRelative); } + public AreaPtg(LittleEndianInput in) { super(in); } - public AreaPtg(String arearef) { - super(new AreaReference(arearef)); - } - public AreaPtg(AreaReference areaRef) { - super(areaRef); - } + + /** + * @deprecated use {@link #AreaPtg(<code>AreaReference</code>)} instead + */ + @Deprecated() + @Removal(version="3.19") + public AreaPtg(String arearef) { + this(new AreaReference(arearef, SpreadsheetVersion.EXCEL97)); + } + + public AreaPtg(AreaReference arearef) { + super(arearef); + } + @Override protected byte getSid() { return sid; diff --git a/src/java/org/apache/poi/ss/formula/ptg/AreaPtgBase.java b/src/java/org/apache/poi/ss/formula/ptg/AreaPtgBase.java index 816287620c..21c19ccd14 100644 --- a/src/java/org/apache/poi/ss/formula/ptg/AreaPtgBase.java +++ b/src/java/org/apache/poi/ss/formula/ptg/AreaPtgBase.java @@ -287,7 +287,7 @@ public abstract class AreaPtgBase extends OperandPtg implements AreaI { CellReference botRight = new CellReference(getLastRow(),getLastColumn(),!isLastRowRelative(),!isLastColRelative()); if(AreaReference.isWholeColumnReference(SpreadsheetVersion.EXCEL97, topLeft, botRight)) { - return (new AreaReference(topLeft, botRight)).formatAsString(); + return (new AreaReference(topLeft, botRight, SpreadsheetVersion.EXCEL97)).formatAsString(); } return topLeft.formatAsString() + ":" + botRight.formatAsString(); } diff --git a/src/java/org/apache/poi/ss/usermodel/CreationHelper.java b/src/java/org/apache/poi/ss/usermodel/CreationHelper.java index 36cfb1deab..004025db10 100644 --- a/src/java/org/apache/poi/ss/usermodel/CreationHelper.java +++ b/src/java/org/apache/poi/ss/usermodel/CreationHelper.java @@ -17,6 +17,8 @@ package org.apache.poi.ss.usermodel; import org.apache.poi.common.usermodel.HyperlinkType; +import org.apache.poi.ss.util.AreaReference; +import org.apache.poi.ss.util.CellReference; /** * An object that handles instantiating concrete @@ -66,4 +68,22 @@ public interface CreationHelper { * @see org.apache.poi.ss.usermodel.Drawing */ ClientAnchor createClientAnchor(); + + /** + * Creates an AreaReference. + * + * @param reference cell reference + * @return an AreaReference instance + */ + AreaReference createAreaReference(String reference); + + /** + * Creates an area ref from a pair of Cell References.. + * + * @param topLeft cell reference + * @param bottomRight cell reference + * @return an AreaReference instance + */ + AreaReference createAreaReference(CellReference topLeft, CellReference bottomRight); + } diff --git a/src/java/org/apache/poi/ss/util/AreaReference.java b/src/java/org/apache/poi/ss/util/AreaReference.java index 7e637b84f2..30e3335369 100644 --- a/src/java/org/apache/poi/ss/util/AreaReference.java +++ b/src/java/org/apache/poi/ss/util/AreaReference.java @@ -22,6 +22,7 @@ import java.util.List; import java.util.StringTokenizer; import org.apache.poi.ss.SpreadsheetVersion; +import org.apache.poi.util.Removal; public class AreaReference { @@ -37,15 +38,6 @@ public class AreaReference { private final CellReference _lastCell; private final boolean _isSingleCell; private final SpreadsheetVersion _version; // never null - - /** - * @deprecated POI 3.13 beta 1. Prefer supplying a version. - */ - @Deprecated - public AreaReference(String reference) { - this(reference, DEFAULT_SPREADSHEET_VERSION); - // generateContiguous must be updated before this can be deleted. - } /** * Create an area ref from a string representation. Sheet names containing special characters should be @@ -116,9 +108,19 @@ public class AreaReference { /** * Creates an area ref from a pair of Cell References. + * @deprecated use {@link #new AreaReference(<code>CellReference</code>, <code>CellReference</code>, <code>SpreadsheetVersion</code>)} instead */ + @Deprecated + @Removal(version="3.19") public AreaReference(CellReference topLeft, CellReference botRight) { - _version = DEFAULT_SPREADSHEET_VERSION; + this(topLeft, botRight, DEFAULT_SPREADSHEET_VERSION); + } + + /** + * Creates an area ref from a pair of Cell References. + */ + public AreaReference(CellReference topLeft, CellReference botRight, SpreadsheetVersion version) { + _version = (null != version) ? version : DEFAULT_SPREADSHEET_VERSION; boolean swapRows = topLeft.getRow() > botRight.getRow(); boolean swapCols = topLeft.getCol() > botRight.getCol(); if (swapRows || swapCols) { @@ -166,7 +168,7 @@ public class AreaReference { * unbroken) area, or is it made up of * several different parts? * (If it is, you will need to call - * {@link #generateContiguous(String)}) + * {@link #generateContiguous(<code>SpreadsheetVersion</code>, String)}) */ public static boolean isContiguous(String reference) { // If there's a sheet name, strip it off @@ -216,15 +218,29 @@ public class AreaReference { } /** - * Takes a non-contiguous area reference, and - * returns an array of contiguous area references. + * Takes a non-contiguous area reference, and returns an array of contiguous area references + * @return an array of contiguous area references. + * @deprecated use {@link #generateContiguous(<code>SpreadsheetVersion</code>, String)} instead */ + @Deprecated + @Removal(version="3.19") public static AreaReference[] generateContiguous(String reference) { + return generateContiguous(DEFAULT_SPREADSHEET_VERSION, reference); + } + + /** + * Takes a non-contiguous area reference, and returns an array of contiguous area references + * @return an array of contiguous area references. + */ + public static AreaReference[] generateContiguous(SpreadsheetVersion version, String reference) { + if (null == version) { + version = DEFAULT_SPREADSHEET_VERSION; // how the code used to behave. + } List<AreaReference> refs = new ArrayList<AreaReference>(); StringTokenizer st = new StringTokenizer(reference, ","); while(st.hasMoreTokens()) { refs.add( - new AreaReference(st.nextToken()) + new AreaReference(st.nextToken(), version) ); } return refs.toArray(new AreaReference[refs.size()]); |