ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
SheetViews.php
Go to the documentation of this file.
1<?php
2
4
7use SimpleXMLElement;
8
10{
12
13 private $worksheet;
14
15 public function __construct(SimpleXMLElement $sheetViewXml, Worksheet $workSheet)
16 {
17 $this->sheetViewXml = $sheetViewXml;
18 $this->worksheet = $workSheet;
19 }
20
21 public function load(): void
22 {
23 $this->zoomScale();
24 $this->view();
25 $this->gridLines();
26 $this->headers();
27 $this->direction();
28 $this->showZeros();
29
30 if (isset($this->sheetViewXml->pane)) {
31 $this->pane();
32 }
33 if (isset($this->sheetViewXml->selection, $this->sheetViewXml->selection['sqref'])) {
34 $this->selection();
35 }
36 }
37
38 private function zoomScale(): void
39 {
40 if (isset($this->sheetViewXml['zoomScale'])) {
41 $zoomScale = (int) ($this->sheetViewXml['zoomScale']);
42 if ($zoomScale <= 0) {
43 // setZoomScale will throw an Exception if the scale is less than or equals 0
44 // that is OK when manually creating documents, but we should be able to read all documents
45 $zoomScale = 100;
46 }
47
48 $this->worksheet->getSheetView()->setZoomScale($zoomScale);
49 }
50
51 if (isset($this->sheetViewXml['zoomScaleNormal'])) {
52 $zoomScaleNormal = (int) ($this->sheetViewXml['zoomScaleNormal']);
53 if ($zoomScaleNormal <= 0) {
54 // setZoomScaleNormal will throw an Exception if the scale is less than or equals 0
55 // that is OK when manually creating documents, but we should be able to read all documents
56 $zoomScaleNormal = 100;
57 }
58
59 $this->worksheet->getSheetView()->setZoomScaleNormal($zoomScaleNormal);
60 }
61 }
62
63 private function view(): void
64 {
65 if (isset($this->sheetViewXml['view'])) {
66 $this->worksheet->getSheetView()->setView((string) $this->sheetViewXml['view']);
67 }
68 }
69
70 private function gridLines(): void
71 {
72 if (isset($this->sheetViewXml['showGridLines'])) {
73 $this->worksheet->setShowGridLines(
74 self::boolean((string) $this->sheetViewXml['showGridLines'])
75 );
76 }
77 }
78
79 private function headers(): void
80 {
81 if (isset($this->sheetViewXml['showRowColHeaders'])) {
82 $this->worksheet->setShowRowColHeaders(
83 self::boolean((string) $this->sheetViewXml['showRowColHeaders'])
84 );
85 }
86 }
87
88 private function direction(): void
89 {
90 if (isset($this->sheetViewXml['rightToLeft'])) {
91 $this->worksheet->setRightToLeft(
92 self::boolean((string) $this->sheetViewXml['rightToLeft'])
93 );
94 }
95 }
96
97 private function showZeros(): void
98 {
99 if (isset($this->sheetViewXml['showZeros'])) {
100 $this->worksheet->getSheetView()->setShowZeros(
101 self::boolean((string) $this->sheetViewXml['showZeros'])
102 );
103 }
104 }
105
106 private function pane(): void
107 {
108 $xSplit = 0;
109 $ySplit = 0;
110 $topLeftCell = null;
111
112 if (isset($this->sheetViewXml->pane['xSplit'])) {
113 $xSplit = (int) ($this->sheetViewXml->pane['xSplit']);
114 }
115
116 if (isset($this->sheetViewXml->pane['ySplit'])) {
117 $ySplit = (int) ($this->sheetViewXml->pane['ySplit']);
118 }
119
120 if (isset($this->sheetViewXml->pane['topLeftCell'])) {
121 $topLeftCell = (string) $this->sheetViewXml->pane['topLeftCell'];
122 }
123
124 $this->worksheet->freezePane(
125 Coordinate::stringFromColumnIndex($xSplit + 1) . ($ySplit + 1),
126 $topLeftCell
127 );
128 }
129
130 private function selection(): void
131 {
132 $sqref = (string) $this->sheetViewXml->selection['sqref'];
133 $sqref = explode(' ', $sqref);
134 $sqref = $sqref[0];
135
136 $this->worksheet->setSelectedCells($sqref);
137 }
138}
An exception for terminatinating execution or to throw for unit testing.
Helper class to manipulate cell coordinates.
Definition: Coordinate.php:15
static stringFromColumnIndex($columnIndex)
String from column index.
Definition: Coordinate.php:313
__construct(SimpleXMLElement $sheetViewXml, Worksheet $workSheet)
Definition: SheetViews.php:15