Package org.apache.poi.ss.util
Class AreaReference
- java.lang.Object
-
- org.apache.poi.ss.util.AreaReference
-
public class AreaReference extends Object
-
-
Constructor Summary
Constructors Constructor Description AreaReference(String reference, SpreadsheetVersion version)
Create an area ref from a string representation.AreaReference(CellReference topLeft, CellReference botRight, SpreadsheetVersion version)
Creates an area ref from a pair of Cell References.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description String
formatAsString()
Returns a text representation of this area reference.static AreaReference[]
generateContiguous(SpreadsheetVersion version, String reference)
Takes a non-contiguous area reference, and returns an array of contiguous area referencesCellReference[]
getAllReferencedCells()
Returns a reference to every cell covered by this areaCellReference
getFirstCell()
CellReference
getLastCell()
Note - if this area reference refers to a single cell, the return value of this method will be identical to that ofgetFirstCell()
static AreaReference
getWholeColumn(SpreadsheetVersion version, String start, String end)
Construct an AreaReference which spans one more columns.static AreaReference
getWholeRow(SpreadsheetVersion version, String start, String end)
Construct an AreaReference which spans one more rowsstatic boolean
isContiguous(String reference)
Is the reference for a contiguous (i.e.boolean
isSingleCell()
boolean
isWholeColumnReference()
static boolean
isWholeColumnReference(SpreadsheetVersion version, CellReference topLeft, CellReference botRight)
Is the reference for a whole-column reference, such as C:C or D:G ?boolean
isWholeRowReference()
e.g.static boolean
isWholeRowReference(SpreadsheetVersion version, CellReference topLeft, CellReference botRight)
String
toString()
-
-
-
Constructor Detail
-
AreaReference
public AreaReference(String reference, SpreadsheetVersion version)
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.
The area reference must be contiguous (i.e. represent a single rectangle, not a union of rectangles)
-
AreaReference
public AreaReference(CellReference topLeft, CellReference botRight, SpreadsheetVersion version)
Creates an area ref from a pair of Cell References.
-
-
Method Detail
-
isContiguous
public static boolean isContiguous(String reference)
Is the reference for a contiguous (i.e. unbroken) area, or is it made up of several different parts? (If it is, you will need to callgenerateContiguous(SpreadsheetVersion, String)
)
-
getWholeRow
public static AreaReference getWholeRow(SpreadsheetVersion version, String start, String end)
Construct an AreaReference which spans one more rows- Parameters:
version
- Is the spreadsheet in format Excel97 or newer Excel versionsstart
- The 1-based start-index of the rowsend
- The 1-based end-index of the rows- Returns:
- An AreaReference that spans the given rows
-
getWholeColumn
public static AreaReference getWholeColumn(SpreadsheetVersion version, String start, String end)
Construct an AreaReference which spans one more columns. Columns are specified in the Excel format, i.e. "A" is the first column "B" the seconds, ... "AA", ..- Parameters:
version
- Is the spreadsheet in format Excel97 or newer Excel versionsstart
- The ABC-based start-index of the columnsend
- The ABC-based end-index of the columns- Returns:
- An AreaReference that spans the given columns
-
isWholeColumnReference
public static boolean isWholeColumnReference(SpreadsheetVersion version, CellReference topLeft, CellReference botRight)
Is the reference for a whole-column reference, such as C:C or D:G ?
-
isWholeRowReference
public boolean isWholeRowReference()
e.g. 1:1 or 3:6- Returns:
-
isWholeRowReference
public static boolean isWholeRowReference(SpreadsheetVersion version, CellReference topLeft, CellReference botRight)
-
generateContiguous
public static AreaReference[] generateContiguous(SpreadsheetVersion version, String reference)
Takes a non-contiguous area reference, and returns an array of contiguous area references- Returns:
- an array of contiguous area references.
-
isWholeColumnReference
public boolean isWholeColumnReference()
-
isSingleCell
public boolean isSingleCell()
- Returns:
false
if this area reference involves more than one cell
-
getFirstCell
public CellReference getFirstCell()
- Returns:
- the first cell reference which defines this area. Usually this cell is in the upper left corner of the area (but this is not a requirement).
-
getLastCell
public CellReference getLastCell()
Note - if this area reference refers to a single cell, the return value of this method will be identical to that ofgetFirstCell()
- Returns:
- the second cell reference which defines this area. For multi-cell areas, this is cell diagonally opposite the 'first cell'. Usually this cell is in the lower right corner of the area (but this is not a requirement).
-
getAllReferencedCells
public CellReference[] getAllReferencedCells()
Returns a reference to every cell covered by this area
-
formatAsString
public String formatAsString()
Returns a text representation of this area reference.Example return values:
Example return values Result Comment A1:A1 Single cell area reference without sheet A1:$C$1 Multi-cell area reference without sheet Sheet1!A$1:B4 Standard sheet name 'O''Brien''s Sales'!B5:C6' Sheet name with special characters - Returns:
- the text representation of this area reference as it would appear in a formula.
-
-