PluginProbe
TablePress – Tables in WordPress made easy / 3.4
TablePress – Tables in WordPress made easy v3.4
3.4 3.3.4 3.3.3 3.3.2 3.3.1 trunk 1.12 1.14 1.9.2 2.0.4 2.1.7 2.1.8 2.2 2.2.1 2.2.2 2.2.3 2.2.4 2.2.5 2.3 2.3.1 2.3.2 2.4 2.4.1 2.4.2 2.4.3 All 45 releases
tablepress / libraries / vendor / PhpSpreadsheet / Worksheet / Column.php

Column.php in TablePress – Tables in WordPress made easy 3.4, at libraries/vendor/PhpSpreadsheet/Worksheet/Column.php

111 lines 3.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace TablePress\PhpOffice\PhpSpreadsheet\Worksheet;
4
5 class Column
6 {
7 private Worksheet $worksheet;
8
9 /**
10 * Column index.
11 */
12 private string $columnIndex;
13
14 /**
15 * Create a new column.
16 */
17 public function __construct(Worksheet $worksheet, string $columnIndex = 'A')
18 {
19 // Set parent and column index
20 $this->worksheet = $worksheet;
21 $this->columnIndex = $columnIndex;
22 }
23
24 /**
25 * Destructor.
26 */
27 public function __destruct()
28 {
29 unset($this->worksheet);
30 }
31
32 /**
33 * Get column index as string eg: 'A'.
34 */
35 public function getColumnIndex(): string
36 {
37 return $this->columnIndex;
38 }
39
40 /**
41 * Get cell iterator.
42 *
43 * @param int $startRow The row number at which to start iterating
44 * @param ?int $endRow Optionally, the row number at which to stop iterating
45 */
46 public function getCellIterator(int $startRow = 1, ?int $endRow = null, bool $iterateOnlyExistingCells = false): ColumnCellIterator
47 {
48 return new ColumnCellIterator($this->worksheet, $this->columnIndex, $startRow, $endRow, $iterateOnlyExistingCells);
49 }
50
51 /**
52 * Get row iterator. Synonym for getCellIterator().
53 *
54 * @param int $startRow The row number at which to start iterating
55 * @param ?int $endRow Optionally, the row number at which to stop iterating
56 */
57 public function getRowIterator(int $startRow = 1, ?int $endRow = null, bool $iterateOnlyExistingCells = false): ColumnCellIterator
58 {
59 return $this->getCellIterator($startRow, $endRow, $iterateOnlyExistingCells);
60 }
61
62 /**
63 * Returns a boolean true if the column contains no cells. By default, this means that no cell records exist in the
64 * collection for this column. false will be returned otherwise.
65 * This rule can be modified by passing a $definitionOfEmptyFlags value:
66 * 1 - CellIterator::TREAT_NULL_VALUE_AS_EMPTY_CELL If the only cells in the collection are null value
67 * cells, then the column will be considered empty.
68 * 2 - CellIterator::TREAT_EMPTY_STRING_AS_EMPTY_CELL If the only cells in the collection are empty
69 * string value cells, then the column will be considered empty.
70 * 3 - CellIterator::TREAT_NULL_VALUE_AS_EMPTY_CELL | CellIterator::TREAT_EMPTY_STRING_AS_EMPTY_CELL
71 * If the only cells in the collection are null value or empty string value cells, then the column
72 * will be considered empty.
73 *
74 * @param int $definitionOfEmptyFlags
75 * Possible Flag Values are:
76 * CellIterator::TREAT_NULL_VALUE_AS_EMPTY_CELL
77 * CellIterator::TREAT_EMPTY_STRING_AS_EMPTY_CELL
78 * @param int $startRow The row number at which to start checking if cells are empty
79 * @param ?int $endRow Optionally, the row number at which to stop checking if cells are empty
80 */
81 public function isEmpty(int $definitionOfEmptyFlags = 0, int $startRow = 1, ?int $endRow = null): bool
82 {
83 $nullValueCellIsEmpty = (bool) ($definitionOfEmptyFlags & CellIterator::TREAT_NULL_VALUE_AS_EMPTY_CELL);
84 $emptyStringCellIsEmpty = (bool) ($definitionOfEmptyFlags & CellIterator::TREAT_EMPTY_STRING_AS_EMPTY_CELL);
85
86 $cellIterator = $this->getCellIterator($startRow, $endRow);
87 $cellIterator->setIterateOnlyExistingCells(true);
88 foreach ($cellIterator as $cell) {
89 $value = $cell->getValue();
90 if ($value === null && $nullValueCellIsEmpty === true) {
91 continue;
92 }
93 if ($value === '' && $emptyStringCellIsEmpty === true) {
94 continue;
95 }
96
97 return false;
98 }
99
100 return true;
101 }
102
103 /**
104 * Returns bound worksheet.
105 */
106 public function getWorksheet(): Worksheet
107 {
108 return $this->worksheet;
109 }
110 }
111