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 / Cell / RowRange.php

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

95 lines 2.0 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\Cell;
4
5 use TablePress\PhpOffice\PhpSpreadsheet\Worksheet\Worksheet;
6 use Stringable;
7
8 /**
9 * @implements AddressRange<int>
10 */
11 class RowRange implements AddressRange
12 {
13 protected ?Worksheet $worksheet;
14
15 protected int $from;
16
17 protected int $to;
18
19 public function __construct(int $from, ?int $to = null, ?Worksheet $worksheet = null)
20 {
21 $this->validateFromTo($from, $to ?? $from);
22 $this->worksheet = $worksheet;
23 }
24
25 public function __destruct()
26 {
27 $this->worksheet = null;
28 }
29
30 /** @param array{int, int} $array */
31 public static function fromArray(array $array, ?Worksheet $worksheet = null): self
32 {
33 [$from, $to] = $array;
34
35 return new self($from, $to, $worksheet);
36 }
37
38 private function validateFromTo(int $from, int $to): void
39 {
40 // Identify actual top and bottom values (in case we've been given bottom and top)
41 $this->from = min($from, $to);
42 $this->to = max($from, $to);
43 }
44
45 public function from(): int
46 {
47 return $this->from;
48 }
49
50 public function to(): int
51 {
52 return $this->to;
53 }
54
55 public function rowCount(): int
56 {
57 return $this->to - $this->from + 1;
58 }
59
60 public function shiftRight(int $offset = 1): self
61 {
62 $newFrom = $this->from + $offset;
63 $newFrom = ($newFrom < 1) ? 1 : $newFrom;
64
65 $newTo = $this->to + $offset;
66 $newTo = ($newTo < 1) ? 1 : $newTo;
67
68 return new self($newFrom, $newTo, $this->worksheet);
69 }
70
71 public function shiftLeft(int $offset = 1): self
72 {
73 return $this->shiftRight(0 - $offset);
74 }
75
76 public function toCellRange(): CellRange
77 {
78 return new CellRange(
79 CellAddress::fromColumnAndRow(Coordinate::columnIndexFromString('A'), $this->from, $this->worksheet),
80 CellAddress::fromColumnAndRow(Coordinate::columnIndexFromString(AddressRange::MAX_COLUMN), $this->to)
81 );
82 }
83
84 public function __toString(): string
85 {
86 if ($this->worksheet !== null) {
87 $title = str_replace("'", "''", $this->worksheet->getTitle());
88
89 return "'{$title}'!{$this->from}:{$this->to}";
90 }
91
92 return "{$this->from}:{$this->to}";
93 }
94 }
95