ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
RowColumnInformation.php
Go to the documentation of this file.
1<?php
2
4
10
12{
18 private static function cellAddressNullOrWhitespace($cellAddress): bool
19 {
20 return $cellAddress === null || (!is_array($cellAddress) && trim($cellAddress) === '');
21 }
22
23 private static function cellColumn(?Cell $pCell): int
24 {
25 return ($pCell !== null) ? (int) Coordinate::columnIndexFromString($pCell->getColumn()) : 1;
26 }
27
45 public static function COLUMN($cellAddress = null, ?Cell $pCell = null)
46 {
47 if (self::cellAddressNullOrWhitespace($cellAddress)) {
48 return self::cellColumn($pCell);
49 }
50
51 if (is_array($cellAddress)) {
52 foreach ($cellAddress as $columnKey => $value) {
53 $columnKey = preg_replace('/[^a-z]/i', '', $columnKey);
54
55 return (int) Coordinate::columnIndexFromString($columnKey);
56 }
57
58 return self::cellColumn($pCell);
59 }
60
61 $cellAddress = $cellAddress ?? '';
62 if ($pCell != null) {
63 [,, $sheetName] = Helpers::extractWorksheet($cellAddress, $pCell);
64 [,, $cellAddress] = Helpers::extractCellAddresses($cellAddress, true, $pCell->getWorksheet(), $sheetName);
65 }
66 [, $cellAddress] = Worksheet::extractSheetTitle($cellAddress, true);
67 if (strpos($cellAddress, ':') !== false) {
68 [$startAddress, $endAddress] = explode(':', $cellAddress);
69 $startAddress = preg_replace('/[^a-z]/i', '', $startAddress);
70 $endAddress = preg_replace('/[^a-z]/i', '', $endAddress);
71
72 return range(
73 (int) Coordinate::columnIndexFromString($startAddress),
74 (int) Coordinate::columnIndexFromString($endAddress)
75 );
76 }
77
78 $cellAddress = preg_replace('/[^a-z]/i', '', $cellAddress);
79
80 return (int) Coordinate::columnIndexFromString($cellAddress);
81 }
82
96 public static function COLUMNS($cellAddress = null)
97 {
98 if (self::cellAddressNullOrWhitespace($cellAddress)) {
99 return 1;
100 }
101 if (!is_array($cellAddress)) {
102 return Functions::VALUE();
103 }
104
105 reset($cellAddress);
106 $isMatrix = (is_numeric(key($cellAddress)));
108
109 if ($isMatrix) {
110 return $rows;
111 }
112
113 return $columns;
114 }
115
116 private static function cellRow(?Cell $pCell): int
117 {
118 return ($pCell !== null) ? $pCell->getRow() : 1;
119 }
120
138 public static function ROW($cellAddress = null, ?Cell $pCell = null)
139 {
140 if (self::cellAddressNullOrWhitespace($cellAddress)) {
141 return self::cellRow($pCell);
142 }
143
144 if (is_array($cellAddress)) {
145 foreach ($cellAddress as $rowKey => $rowValue) {
146 foreach ($rowValue as $columnKey => $cellValue) {
147 return (int) preg_replace('/\D/', '', $rowKey);
148 }
149 }
150
151 return self::cellRow($pCell);
152 }
153
154 $cellAddress = $cellAddress ?? '';
155 if ($pCell !== null) {
156 [,, $sheetName] = Helpers::extractWorksheet($cellAddress, $pCell);
157 [,, $cellAddress] = Helpers::extractCellAddresses($cellAddress, true, $pCell->getWorksheet(), $sheetName);
158 }
159 [, $cellAddress] = Worksheet::extractSheetTitle($cellAddress, true);
160 if (strpos($cellAddress, ':') !== false) {
161 [$startAddress, $endAddress] = explode(':', $cellAddress);
162 $startAddress = preg_replace('/\D/', '', $startAddress);
163 $endAddress = preg_replace('/\D/', '', $endAddress);
164
165 return array_map(
166 function ($value) {
167 return [$value];
168 },
169 range($startAddress, $endAddress)
170 );
171 }
172 [$cellAddress] = explode(':', $cellAddress);
173
174 return (int) preg_replace('/\D/', '', $cellAddress);
175 }
176
190 public static function ROWS($cellAddress = null)
191 {
192 if (self::cellAddressNullOrWhitespace($cellAddress)) {
193 return 1;
194 }
195 if (!is_array($cellAddress)) {
196 return Functions::VALUE();
197 }
198
199 reset($cellAddress);
200 $isMatrix = (is_numeric(key($cellAddress)));
202
203 if ($isMatrix) {
204 return $columns;
205 }
206
207 return $rows;
208 }
209}
if(! $in) $columns
Definition: Utf8Test.php:45
An exception for terminatinating execution or to throw for unit testing.
static getMatrixDimensions(array &$matrix)
Read the dimensions of a matrix, and re-index it with straight numeric keys starting from row 0,...
static extractCellAddresses(string $cellAddress, bool $a1, Worksheet $sheet, string $sheetName='')
Definition: Helpers.php:38
static extractWorksheet(string $cellAddress, Cell $pCell)
Definition: Helpers.php:60
static COLUMN($cellAddress=null, ?Cell $pCell=null)
COLUMN.
static cellAddressNullOrWhitespace($cellAddress)
Test if cellAddress is null or whitespace string.
getColumn()
Get cell coordinate column.
Definition: Cell.php:120
getRow()
Get cell coordinate row.
Definition: Cell.php:130
Helper class to manipulate cell coordinates.
Definition: Coordinate.php:15
static columnIndexFromString($pString)
Column index from string.
Definition: Coordinate.php:265
$rows
Definition: xhr_table.php:10