PluginProbe
wpDataTables – WordPress Data Table, Dynamic Tables & Table Charts Plugin / 6.5.1.7
wpDataTables – WordPress Data Table, Dynamic Tables & Table Charts Plugin v6.5.1.7
6.5.1.7 6.5.1.6 6.5.1.5 6.5.1.4 6.5.1.3 6.5.1.2 6.5.1.1 6.5.0.9 6.5.0.8 6.5.0.7 6.5.0.6 trunk 3.4.2.40 3.4.2.41 3.4.2.42 3.4.2.43 3.4.2.44 3.4.2.45 3.4.2.46 3.4.2.47 3.4.2.48 3.4.2.49 3.4.2.50 6.3.2 6.3.3.1 All 47 releases
wpdatatables / lib / phpoffice / phpspreadsheet / src / PhpSpreadsheet / Cell / ColumnRange.php

ColumnRange.php in wpDataTables – WordPress Data Table, Dynamic Tables & Table Charts Plugin 6.5.1.7, at lib/phpoffice/phpspreadsheet/src/PhpSpreadsheet/Cell/ColumnRange.php

126 lines 3.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace PhpOffice\PhpSpreadsheet\Cell;
4
5 use PhpOffice\PhpSpreadsheet\Worksheet\Worksheet;
6
7 class ColumnRange implements AddressRange
8 {
9 /**
10 * @var ?Worksheet
11 */
12 protected $worksheet;
13
14 /**
15 * @var int
16 */
17 protected $from;
18
19 /**
20 * @var int
21 */
22 protected $to;
23
24 public function __construct(string $from, ?string $to = null, ?Worksheet $worksheet = null)
25 {
26 $this->validateFromTo(
27 Coordinate::columnIndexFromString($from),
28 Coordinate::columnIndexFromString($to ?? $from)
29 );
30 $this->worksheet = $worksheet;
31 }
32
33 public static function fromColumnIndexes(int $from, int $to, ?Worksheet $worksheet = null): self
34 {
35 return new self(Coordinate::stringFromColumnIndex($from), Coordinate::stringFromColumnIndex($to), $worksheet);
36 }
37
38 /**
39 * @param array<int|string> $array
40 */
41 public static function fromArray(array $array, ?Worksheet $worksheet = null): self
42 {
43 array_walk(
44 $array,
45 function (&$column): void {
46 $column = is_numeric($column) ? Coordinate::stringFromColumnIndex((int) $column) : $column;
47 }
48 );
49 /** @var string $from */
50 /** @var string $to */
51 [$from, $to] = $array;
52
53 return new self($from, $to, $worksheet);
54 }
55
56 private function validateFromTo(int $from, int $to): void
57 {
58 // Identify actual top and bottom values (in case we've been given bottom and top)
59 $this->from = min($from, $to);
60 $this->to = max($from, $to);
61 }
62
63 public function columnCount(): int
64 {
65 return $this->to - $this->from + 1;
66 }
67
68 public function shiftDown(int $offset = 1): self
69 {
70 $newFrom = $this->from + $offset;
71 $newFrom = ($newFrom < 1) ? 1 : $newFrom;
72
73 $newTo = $this->to + $offset;
74 $newTo = ($newTo < 1) ? 1 : $newTo;
75
76 return self::fromColumnIndexes($newFrom, $newTo, $this->worksheet);
77 }
78
79 public function shiftUp(int $offset = 1): self
80 {
81 return $this->shiftDown(0 - $offset);
82 }
83
84 public function from(): string
85 {
86 return Coordinate::stringFromColumnIndex($this->from);
87 }
88
89 public function to(): string
90 {
91 return Coordinate::stringFromColumnIndex($this->to);
92 }
93
94 public function fromIndex(): int
95 {
96 return $this->from;
97 }
98
99 public function toIndex(): int
100 {
101 return $this->to;
102 }
103
104 public function toCellRange(): CellRange
105 {
106 return new CellRange(
107 CellAddress::fromColumnAndRow($this->from, 1, $this->worksheet),
108 CellAddress::fromColumnAndRow($this->to, AddressRange::MAX_ROW)
109 );
110 }
111
112 public function __toString(): string
113 {
114 $from = $this->from();
115 $to = $this->to();
116
117 if ($this->worksheet !== null) {
118 $title = str_replace("'", "''", $this->worksheet->getTitle());
119
120 return "'{$title}'!{$from}:{$to}";
121 }
122
123 return "{$from}:{$to}";
124 }
125 }
126