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