|
static | convertToA1 (string $address, int $currentRowNumber=1, int $currentColumnNumber=1) |
| Converts an R1C1 format cell address to an A1 format cell address. More...
|
|
static | convertFormulaToA1 (string $formula, int $currentRowNumber=1, int $currentColumnNumber=1) |
| Converts a formula that uses R1C1/SpreadsheetXML format cell address to an A1 format cell address. More...
|
|
static | convertToR1C1 (string $address, ?int $currentRowNumber=null, ?int $currentColumnNumber=null) |
| Converts an A1 format cell address to an R1C1 format cell address. More...
|
|
Definition at line 7 of file AddressHelper.php.
◆ convertFormulaToA1()
static PhpOffice\PhpSpreadsheet\Cell\AddressHelper::convertFormulaToA1 |
( |
string |
$formula, |
|
|
int |
$currentRowNumber = 1 , |
|
|
int |
$currentColumnNumber = 1 |
|
) |
| |
|
static |
Converts a formula that uses R1C1/SpreadsheetXML format cell address to an A1 format cell address.
Definition at line 71 of file AddressHelper.php.
References $key.
Referenced by PhpOffice\PhpSpreadsheet\Reader\Xml\load().
76 if (substr($formula, 0, 3) ==
'of:') {
78 return self::convertSpreadsheetMLFormula($formula);
82 $temp = explode(
'"', $formula);
84 foreach ($temp as &$value) {
87 preg_match_all(self::R1C1_COORDINATE_REGEX, $value, $cellReferences, PREG_SET_ORDER + PREG_OFFSET_CAPTURE);
91 $cellReferences = array_reverse($cellReferences);
94 foreach ($cellReferences as $cellReference) {
95 $A1CellReference = self::convertToA1($cellReference[0][0], $currentRowNumber, $currentColumnNumber);
96 $value = substr_replace($value, $A1CellReference, $cellReference[0][1], strlen($cellReference[0][0]));
103 return implode(
'"', $temp);
◆ convertSpreadsheetMLFormula()
static PhpOffice\PhpSpreadsheet\Cell\AddressHelper::convertSpreadsheetMLFormula |
( |
string |
$formula | ) |
|
|
staticprotected |
Definition at line 52 of file AddressHelper.php.
References $key.
54 $formula = substr($formula, 3);
55 $temp = explode(
'"', $formula);
57 foreach ($temp as &$value) {
60 $value = str_replace([
'[.',
':.',
']'], [
'',
':',
''], $value);
65 return implode(
'"', $temp);
◆ convertToA1()
static PhpOffice\PhpSpreadsheet\Cell\AddressHelper::convertToA1 |
( |
string |
$address, |
|
|
int |
$currentRowNumber = 1 , |
|
|
int |
$currentColumnNumber = 1 |
|
) |
| |
|
static |
Converts an R1C1 format cell address to an A1 format cell address.
Definition at line 14 of file AddressHelper.php.
References PhpOffice\PhpSpreadsheet\Cell\Coordinate\stringFromColumnIndex().
19 $validityCheck = preg_match(
'/^(R(\[?-?\d*\]?))(C(\[?-?\d*\]?))$/i', $address, $cellReference);
21 if ($validityCheck === 0) {
22 throw new Exception(
'Invalid R1C1-format Cell Reference');
25 $rowReference = $cellReference[2];
27 if ($rowReference ===
'') {
28 $rowReference = (string) $currentRowNumber;
31 if ($rowReference[0] ===
'[') {
32 $rowReference = $currentRowNumber + (int) trim($rowReference,
'[]');
34 $columnReference = $cellReference[4];
36 if ($columnReference ===
'') {
37 $columnReference = (string) $currentColumnNumber;
40 if (is_string($columnReference) && $columnReference[0] ===
'[') {
41 $columnReference = $currentColumnNumber + (int) trim($columnReference,
'[]');
44 if ($columnReference <= 0 || $rowReference <= 0) {
45 throw new Exception(
'Invalid R1C1-format Cell Reference, Value out of range');
49 return $A1CellReference;
static stringFromColumnIndex($columnIndex)
String from column index.
◆ convertToR1C1()
static PhpOffice\PhpSpreadsheet\Cell\AddressHelper::convertToR1C1 |
( |
string |
$address, |
|
|
?int |
$currentRowNumber = null , |
|
|
?int |
$currentColumnNumber = null |
|
) |
| |
|
static |
Converts an A1 format cell address to an R1C1 format cell address.
If $currentRowNumber or $currentColumnNumber are provided, then the R1C1 address will be formatted as a relative address.
Definition at line 110 of file AddressHelper.php.
References PhpOffice\PhpSpreadsheet\Cell\Coordinate\A1_COORDINATE_REGEX, and PhpOffice\PhpSpreadsheet\Cell\Coordinate\columnIndexFromString().
117 if ($validityCheck === 0) {
118 throw new Exception(
'Invalid A1-format Cell Reference');
122 if ($cellReference[
'absolute_col'] ===
'$') {
124 $currentColumnNumber = null;
127 $rowId = (int) $cellReference[
'row_ref'];
128 if ($cellReference[
'absolute_row'] ===
'$') {
130 $currentRowNumber = null;
133 if ($currentRowNumber !== null) {
134 if ($rowId === $currentRowNumber) {
137 $rowId =
'[' . ($rowId - $currentRowNumber) .
']';
141 if ($currentColumnNumber !== null) {
142 if ($columnId === $currentColumnNumber) {
145 $columnId =
'[' . ($columnId - $currentColumnNumber) .
']';
149 $R1C1Address =
"R{$rowId}C{$columnId}";
const A1_COORDINATE_REGEX
static columnIndexFromString($pString)
Column index from string.
◆ R1C1_COORDINATE_REGEX
const PhpOffice\PhpSpreadsheet\Cell\AddressHelper::R1C1_COORDINATE_REGEX = '/(R((?:\[-?\d*\])|(?:\d*))?)(C((?:\[-?\d*\])|(?:\d*))?)/i' |
The documentation for this class was generated from the following file:
- libs/composer/vendor/phpoffice/phpspreadsheet/src/PhpSpreadsheet/Cell/AddressHelper.php