visualizer
/
vendor
/
phpoffice
/
phpspreadsheet
/
src
/
PhpSpreadsheet
/
Reader
/
Xlsx
/
SheetViews.php
SheetViews.php in Visualizer – Tables & Charts Manager with Built-in AI Generator 3.4.5, at vendor/phpoffice/phpspreadsheet/src/PhpSpreadsheet/Reader/Xlsx/SheetViews.php
| 1 | <?php |
| 2 | |
| 3 | namespace PhpOffice\PhpSpreadsheet\Reader\Xlsx; |
| 4 | |
| 5 | use PhpOffice\PhpSpreadsheet\Cell\Coordinate; |
| 6 | use PhpOffice\PhpSpreadsheet\Worksheet\Worksheet; |
| 7 | |
| 8 | class SheetViews extends BaseParserClass |
| 9 | { |
| 10 | private $sheetViewXml; |
| 11 | |
| 12 | private $worksheet; |
| 13 | |
| 14 | public function __construct(\SimpleXMLElement $sheetViewXml, Worksheet $workSheet) |
| 15 | { |
| 16 | $this->sheetViewXml = $sheetViewXml; |
| 17 | $this->worksheet = $workSheet; |
| 18 | } |
| 19 | |
| 20 | public function load() |
| 21 | { |
| 22 | $this->zoomScale(); |
| 23 | $this->view(); |
| 24 | $this->gridLines(); |
| 25 | $this->headers(); |
| 26 | $this->direction(); |
| 27 | |
| 28 | if (isset($this->sheetViewXml->pane)) { |
| 29 | $this->pane(); |
| 30 | } |
| 31 | if (isset($this->sheetViewXml->selection, $this->sheetViewXml->selection['sqref'])) { |
| 32 | $this->selection(); |
| 33 | } |
| 34 | } |
| 35 | |
| 36 | private function zoomScale() |
| 37 | { |
| 38 | if (isset($this->sheetViewXml['zoomScale'])) { |
| 39 | $zoomScale = (int) ($this->sheetViewXml['zoomScale']); |
| 40 | if ($zoomScale <= 0) { |
| 41 | // setZoomScale will throw an Exception if the scale is less than or equals 0 |
| 42 | // that is OK when manually creating documents, but we should be able to read all documents |
| 43 | $zoomScale = 100; |
| 44 | } |
| 45 | |
| 46 | $this->worksheet->getSheetView()->setZoomScale($zoomScale); |
| 47 | } |
| 48 | |
| 49 | if (isset($this->sheetViewXml['zoomScaleNormal'])) { |
| 50 | $zoomScaleNormal = (int) ($this->sheetViewXml['zoomScaleNormal']); |
| 51 | if ($zoomScaleNormal <= 0) { |
| 52 | // setZoomScaleNormal will throw an Exception if the scale is less than or equals 0 |
| 53 | // that is OK when manually creating documents, but we should be able to read all documents |
| 54 | $zoomScaleNormal = 100; |
| 55 | } |
| 56 | |
| 57 | $this->worksheet->getSheetView()->setZoomScaleNormal($zoomScaleNormal); |
| 58 | } |
| 59 | } |
| 60 | |
| 61 | private function view() |
| 62 | { |
| 63 | if (isset($this->sheetViewXml['view'])) { |
| 64 | $this->worksheet->getSheetView()->setView((string) $this->sheetViewXml['view']); |
| 65 | } |
| 66 | } |
| 67 | |
| 68 | private function gridLines() |
| 69 | { |
| 70 | if (isset($this->sheetViewXml['showGridLines'])) { |
| 71 | $this->worksheet->setShowGridLines( |
| 72 | self::boolean((string) $this->sheetViewXml['showGridLines']) |
| 73 | ); |
| 74 | } |
| 75 | } |
| 76 | |
| 77 | private function headers() |
| 78 | { |
| 79 | if (isset($this->sheetViewXml['showRowColHeaders'])) { |
| 80 | $this->worksheet->setShowRowColHeaders( |
| 81 | self::boolean((string) $this->sheetViewXml['showRowColHeaders']) |
| 82 | ); |
| 83 | } |
| 84 | } |
| 85 | |
| 86 | private function direction() |
| 87 | { |
| 88 | if (isset($this->sheetViewXml['rightToLeft'])) { |
| 89 | $this->worksheet->setRightToLeft( |
| 90 | self::boolean((string) $this->sheetViewXml['rightToLeft']) |
| 91 | ); |
| 92 | } |
| 93 | } |
| 94 | |
| 95 | private function pane() |
| 96 | { |
| 97 | $xSplit = 0; |
| 98 | $ySplit = 0; |
| 99 | $topLeftCell = null; |
| 100 | |
| 101 | if (isset($this->sheetViewXml->pane['xSplit'])) { |
| 102 | $xSplit = (int) ($this->sheetViewXml->pane['xSplit']); |
| 103 | } |
| 104 | |
| 105 | if (isset($this->sheetViewXml->pane['ySplit'])) { |
| 106 | $ySplit = (int) ($this->sheetViewXml->pane['ySplit']); |
| 107 | } |
| 108 | |
| 109 | if (isset($this->sheetViewXml->pane['topLeftCell'])) { |
| 110 | $topLeftCell = (string) $this->sheetViewXml->pane['topLeftCell']; |
| 111 | } |
| 112 | |
| 113 | $this->worksheet->freezePane( |
| 114 | Coordinate::stringFromColumnIndex($xSplit + 1) . ($ySplit + 1), |
| 115 | $topLeftCell |
| 116 | ); |
| 117 | } |
| 118 | |
| 119 | private function selection() |
| 120 | { |
| 121 | $sqref = (string) $this->sheetViewXml->selection['sqref']; |
| 122 | $sqref = explode(' ', $sqref); |
| 123 | $sqref = $sqref[0]; |
| 124 | |
| 125 | $this->worksheet->setSelectedCells($sqref); |
| 126 | } |
| 127 | } |
| 128 |