abstract class Coordinate (View source)

Helper class to manipulate cell coordinates.

Columns indexes and rows are always based on 1, not on 0. This match the behavior that Excel users are used to, and also match the Excel functions COLUMN() and ROW().

Constants

DEFAULT_RANGE

Default range variable constant.

Methods

static string[]
coordinateFromString(string $pCoordinateString)

Coordinate from string.

static bool
coordinateIsRange(string $coord)

Checks if a coordinate represents a range of cells.

static string
absoluteReference(string $pCoordinateString)

Make string row, column or cell coordinate absolute.

static string
absoluteCoordinate(string $pCoordinateString)

Make string coordinate absolute.

static array
splitRange(string $pRange)

Split range into coordinate strings.

static string
buildRange(array $pRange)

Build range from coordinate strings.

static array
rangeBoundaries(string $pRange)

Calculate range boundaries.

static array
rangeDimension(string $pRange)

Calculate range dimension.

static array
getRangeBoundaries(string $pRange)

Calculate range boundaries.

static int
columnIndexFromString(string $pString)

Column index from string.

static string
stringFromColumnIndex(int $columnIndex)

String from column index.

static array
extractAllCellReferencesInRange(string $pRange)

Extract all cell references in range, which may be comprised of multiple cell ranges.

static array
mergeRangesInCollection(array $pCoordCollection)

Convert an associative array of single cell coordinates to values to an associative array of cell ranges to values. Only adjacent cell coordinates with the same value will be merged. If the value is an object, it must implement the method getHashCode().

Details

static string[] coordinateFromString(string $pCoordinateString)

Coordinate from string.

Parameters

string $pCoordinateString eg: 'A1'

Return Value

string[] Array containing column and row (indexes 0 and 1)

Exceptions

Exception

static bool coordinateIsRange(string $coord)

Checks if a coordinate represents a range of cells.

Parameters

string $coord eg: 'A1' or 'A1:A2' or 'A1:A2,C1:C2'

Return Value

bool Whether the coordinate represents a range of cells

static string absoluteReference(string $pCoordinateString)

Make string row, column or cell coordinate absolute.

Parameters

string $pCoordinateString e.g. 'A' or '1' or 'A1' Note that this value can be a row or column reference as well as a cell reference

Return Value

string Absolute coordinate e.g. '$A' or '$1' or '$A$1'

Exceptions

Exception

static string absoluteCoordinate(string $pCoordinateString)

Make string coordinate absolute.

Parameters

string $pCoordinateString e.g. 'A1'

Return Value

string Absolute coordinate e.g. '$A$1'

Exceptions

Exception

static array splitRange(string $pRange)

Split range into coordinate strings.

Parameters

string $pRange e.g. 'B4:D9' or 'B4:D9,H2:O11' or 'B4'

Return Value

array Array containing one or more arrays containing one or two coordinate strings e.g. ['B4','D9'] or [['B4','D9'], ['H2','O11']] or ['B4']

static string buildRange(array $pRange)

Build range from coordinate strings.

Parameters

array $pRange Array containg one or more arrays containing one or two coordinate strings

Return Value

string String representation of $pRange

Exceptions

Exception

static array rangeBoundaries(string $pRange)

Calculate range boundaries.

Parameters

string $pRange Cell range (e.g. A1:A1)

Return Value

array Range coordinates [Start Cell, End Cell] where Start Cell and End Cell are arrays (Column Number, Row Number)

static array rangeDimension(string $pRange)

Calculate range dimension.

Parameters

string $pRange Cell range (e.g. A1:A1)

Return Value

array Range dimension (width, height)

static array getRangeBoundaries(string $pRange)

Calculate range boundaries.

Parameters

string $pRange Cell range (e.g. A1:A1)

Return Value

array Range coordinates [Start Cell, End Cell] where Start Cell and End Cell are arrays [Column ID, Row Number]

static int columnIndexFromString(string $pString)

Column index from string.

Parameters

string $pString eg 'A'

Return Value

int Column index (A = 1)

static string stringFromColumnIndex(int $columnIndex)

String from column index.

Parameters

int $columnIndex Column index (A = 1)

Return Value

string

static array extractAllCellReferencesInRange(string $pRange)

Extract all cell references in range, which may be comprised of multiple cell ranges.

Parameters

string $pRange Range (e.g. A1 or A1:C10 or A1:E10 A20:E25)

Return Value

array Array containing single cell references

static array mergeRangesInCollection(array $pCoordCollection)

Convert an associative array of single cell coordinates to values to an associative array of cell ranges to values. Only adjacent cell coordinates with the same value will be merged. If the value is an object, it must implement the method getHashCode().

For example, this function converts:

[ 'A1' => 'x', 'A2' => 'x', 'A3' => 'x', 'A4' => 'y' ]

to:

[ 'A1:A3' => 'x', 'A4' => 'y' ]

Parameters

array $pCoordCollection associative array mapping coordinates to values

Return Value

array associative array mapping coordinate ranges to valuea