Top Fields Constructors Methods
org.apache.poi.ss.util

public Class AreaReference

extends Object
Class Inheritance
Imports
java.util.ArrayList, .List, .StringTokenizer, org.apache.poi.ss.SpreadsheetVersion, org.apache.poi.util.StringUtil

Field Summary

Modifier and TypeField and Description
private final CellReference
private final boolean
private final CellReference
private final SpreadsheetVersion
private static final char
CELL_DELIMITER

The character (:) that separates the two cell references in a multi-cell area reference

private static final SpreadsheetVersion
private static final char
SHEET_NAME_DELIMITER

The character (!) that separates sheet names from cell references

private static final char
SPECIAL_NAME_DELIMITER

The character (') used to quote sheet names when they contain special characters

Constructor Summary

AccessConstructor and Description
public
AreaReference(String reference, SpreadsheetVersion version)

Create an area ref from a string representation.

public
AreaReference(CellReference topLeft, CellReference botRight, SpreadsheetVersion version)

Creates an area ref from a pair of Cell References.

Method Summary

Modifier and TypeMethod and Description
public String

Returns:

the text representation of this area reference as it would appear in a formula.
formatAsString
()

Returns a text representation of this area reference.

public static AreaReference[]

Returns:

an array of contiguous area references.
generateContiguous
(SpreadsheetVersion version, String reference)

Takes a non-contiguous area reference, and returns an array of contiguous area references

public CellReference[]
getAllReferencedCells()

Returns a reference to every cell covered by this area

public CellReference

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).
getFirstCell
()

public CellReference

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).
getLastCell
()

Note - if this area reference refers to a single cell, the return value of this method will be identical to that of getFirstCell()

public static AreaReference

Returns:

An AreaReference that spans the given columns
getWholeColumn
(SpreadsheetVersion
Is the spreadsheet in format Excel97 or newer Excel versions
version
,
String
The ABC-based start-index of the columns
start
,
String
The ABC-based end-index of the columns
end
)

Construct an AreaReference which spans one more columns.

public static AreaReference

Returns:

An AreaReference that spans the given rows
getWholeRow
(SpreadsheetVersion
Is the spreadsheet in format Excel97 or newer Excel versions
version
,
String
The 1-based start-index of the rows
start
,
String
The 1-based end-index of the rows
end
)

Construct an AreaReference which spans one more rows

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?

private static boolean
public boolean

Returns:

false if this area reference involves more than one cell
isSingleCell
()

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 ?

public boolean
private static String[]

Returns:

array with one or two elements. never null
separateAreaRefs
(String reference)

Separates Area refs in two parts and returns them as separate elements in a String array, each qualified with the sheet name (if present)

private static String[]

Returns:

Area references in an array, size >= 1
splitAreaReferences
(String
Area references, i.e. A1:B2, 'Sheet1'!A1:B2
reference
)

Splits a comma-separated area references string into an array of individual references

public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait

Field Detail

_firstCellback to summary
private final CellReference _firstCell
_isSingleCellback to summary
private final boolean _isSingleCell
_lastCellback to summary
private final CellReference _lastCell
_versionback to summary
private final SpreadsheetVersion _version
CELL_DELIMITERback to summary
private static final char CELL_DELIMITER

The character (:) that separates the two cell references in a multi-cell area reference

DEFAULT_SPREADSHEET_VERSIONback to summary
private static final SpreadsheetVersion DEFAULT_SPREADSHEET_VERSION
SHEET_NAME_DELIMITERback to summary
private static final char SHEET_NAME_DELIMITER

The character (!) that separates sheet names from cell references

SPECIAL_NAME_DELIMITERback to summary
private static final char SPECIAL_NAME_DELIMITER

The character (') used to quote sheet names when they contain special characters

Constructor Detail

AreaReferenceback to summary
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)

AreaReferenceback to summary
public AreaReference(CellReference topLeft, CellReference botRight, SpreadsheetVersion version)

Creates an area ref from a pair of Cell References.

Method Detail

formatAsStringback to summary
public String formatAsString()

Returns a text representation of this area reference.

Example return values:

Example return values
ResultComment
A1:A1Single cell area reference without sheet
A1:$C$1Multi-cell area reference without sheet
Sheet1!A$1:B4Standard sheet name
'O''Brien''s Sales'!B5:C6' Sheet name with special characters
Returns:String

the text representation of this area reference as it would appear in a formula.

generateContiguousback to summary
public static AreaReference[] generateContiguous(SpreadsheetVersion version, String reference)

Takes a non-contiguous area reference, and returns an array of contiguous area references

Returns:AreaReference[]

an array of contiguous area references.

getAllReferencedCellsback to summary
public CellReference[] getAllReferencedCells()

Returns a reference to every cell covered by this area

getFirstCellback to summary
public CellReference getFirstCell()
Returns:CellReference

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).

getLastCellback to summary
public CellReference getLastCell()

Note - if this area reference refers to a single cell, the return value of this method will be identical to that of getFirstCell()

Returns:CellReference

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).

getWholeColumnback to summary
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:SpreadsheetVersion

Is the spreadsheet in format Excel97 or newer Excel versions

start:String

The ABC-based start-index of the columns

end:String

The ABC-based end-index of the columns

Returns:AreaReference

An AreaReference that spans the given columns

getWholeRowback to summary
public static AreaReference getWholeRow(SpreadsheetVersion version, String start, String end)

Construct an AreaReference which spans one more rows

Parameters
version:SpreadsheetVersion

Is the spreadsheet in format Excel97 or newer Excel versions

start:String

The 1-based start-index of the rows

end:String

The 1-based end-index of the rows

Returns:AreaReference

An AreaReference that spans the given rows

isContiguousback to summary
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 call generateContiguous(SpreadsheetVersion, String))

isPlainColumnback to summary
private static boolean isPlainColumn(String refPart)
isSingleCellback to summary
public boolean isSingleCell()
Returns:boolean

false if this area reference involves more than one cell

isWholeColumnReferenceback to summary
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 ?

isWholeColumnReferenceback to summary
public boolean isWholeColumnReference()
separateAreaRefsback to summary
private static String[] separateAreaRefs(String reference)

Separates Area refs in two parts and returns them as separate elements in a String array, each qualified with the sheet name (if present)

Returns:String[]

array with one or two elements. never null

splitAreaReferencesback to summary
private static String[] splitAreaReferences(String reference)

Splits a comma-separated area references string into an array of individual references

Parameters
reference:String

Area references, i.e. A1:B2, 'Sheet1'!A1:B2

Returns:String[]

Area references in an array, size >= 1

toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object. Satisfying this method's contract implies a non-null result must be returned.

Returns:String

a string representation of the object