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

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

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