ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
SheetViewOptions.php
Go to the documentation of this file.
1 <?php
2 
4 
7 
9 {
10  private $worksheet;
11 
12  private $worksheetXml;
13 
14  public function __construct(Worksheet $workSheet, ?SimpleXMLElement $worksheetXml = null)
15  {
16  $this->worksheet = $workSheet;
17  $this->worksheetXml = $worksheetXml;
18  }
19 
23  public function load($readDataOnly = false): void
24  {
25  if ($this->worksheetXml === null) {
26  return;
27  }
28 
29  if (isset($this->worksheetXml->sheetPr)) {
30  $this->tabColor($this->worksheetXml->sheetPr);
31  $this->codeName($this->worksheetXml->sheetPr);
32  $this->outlines($this->worksheetXml->sheetPr);
33  $this->pageSetup($this->worksheetXml->sheetPr);
34  }
35 
36  if (isset($this->worksheetXml->sheetFormatPr)) {
37  $this->sheetFormat($this->worksheetXml->sheetFormatPr);
38  }
39 
40  if (!$readDataOnly && isset($this->worksheetXml->printOptions)) {
41  $this->printOptions($this->worksheetXml->printOptions);
42  }
43  }
44 
45  private function tabColor(SimpleXMLElement $sheetPr): void
46  {
47  if (isset($sheetPr->tabColor, $sheetPr->tabColor['rgb'])) {
48  $this->worksheet->getTabColor()->setARGB((string) $sheetPr->tabColor['rgb']);
49  }
50  }
51 
52  private function codeName(SimpleXMLElement $sheetPr): void
53  {
54  if (isset($sheetPr['codeName'])) {
55  $this->worksheet->setCodeName((string) $sheetPr['codeName'], false);
56  }
57  }
58 
59  private function outlines(SimpleXMLElement $sheetPr): void
60  {
61  if (isset($sheetPr->outlinePr)) {
62  if (
63  isset($sheetPr->outlinePr['summaryRight']) &&
64  !self::boolean((string) $sheetPr->outlinePr['summaryRight'])
65  ) {
66  $this->worksheet->setShowSummaryRight(false);
67  } else {
68  $this->worksheet->setShowSummaryRight(true);
69  }
70 
71  if (
72  isset($sheetPr->outlinePr['summaryBelow']) &&
73  !self::boolean((string) $sheetPr->outlinePr['summaryBelow'])
74  ) {
75  $this->worksheet->setShowSummaryBelow(false);
76  } else {
77  $this->worksheet->setShowSummaryBelow(true);
78  }
79  }
80  }
81 
82  private function pageSetup(SimpleXMLElement $sheetPr): void
83  {
84  if (isset($sheetPr->pageSetUpPr)) {
85  if (
86  isset($sheetPr->pageSetUpPr['fitToPage']) &&
87  !self::boolean((string) $sheetPr->pageSetUpPr['fitToPage'])
88  ) {
89  $this->worksheet->getPageSetup()->setFitToPage(false);
90  } else {
91  $this->worksheet->getPageSetup()->setFitToPage(true);
92  }
93  }
94  }
95 
96  private function sheetFormat(SimpleXMLElement $sheetFormatPr): void
97  {
98  if (
99  isset($sheetFormatPr['customHeight']) &&
100  self::boolean((string) $sheetFormatPr['customHeight']) &&
101  isset($sheetFormatPr['defaultRowHeight'])
102  ) {
103  $this->worksheet->getDefaultRowDimension()
104  ->setRowHeight((float) $sheetFormatPr['defaultRowHeight']);
105  }
106 
107  if (isset($sheetFormatPr['defaultColWidth'])) {
108  $this->worksheet->getDefaultColumnDimension()
109  ->setWidth((float) $sheetFormatPr['defaultColWidth']);
110  }
111 
112  if (
113  isset($sheetFormatPr['zeroHeight']) &&
114  ((string) $sheetFormatPr['zeroHeight'] === '1')
115  ) {
116  $this->worksheet->getDefaultRowDimension()->setZeroHeight(true);
117  }
118  }
119 
120  private function printOptions(SimpleXMLElement $printOptions): void
121  {
122  if (self::boolean((string) $printOptions['gridLinesSet'])) {
123  $this->worksheet->setShowGridlines(true);
124  }
125  if (self::boolean((string) $printOptions['gridLines'])) {
126  $this->worksheet->setPrintGridlines(true);
127  }
128  if (self::boolean((string) $printOptions['horizontalCentered'])) {
129  $this->worksheet->getPageSetup()->setHorizontalCentered(true);
130  }
131  if (self::boolean((string) $printOptions['verticalCentered'])) {
132  $this->worksheet->getPageSetup()->setVerticalCentered(true);
133  }
134  }
135 }
__construct(Worksheet $workSheet, ?SimpleXMLElement $worksheetXml=null)