1
|
|
|
<?php |
2
|
|
|
namespace Ellumilel\Xl\Worksheets; |
3
|
|
|
|
4
|
|
|
/** |
5
|
|
|
* @link https://msdn.microsoft.com/en-us/library/bb264572(v=office.12).aspx |
6
|
|
|
* |
7
|
|
|
* Class SheetXml |
8
|
|
|
* @package Ellumilel\Xl\Worksheet |
9
|
|
|
* @author Denis Tikhonov <[email protected]> |
10
|
|
|
*/ |
11
|
|
|
class SheetXml |
12
|
|
|
{ |
13
|
|
|
/** @var string */ |
14
|
|
|
private $xml = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n"; |
15
|
|
|
/** @var string */ |
16
|
|
|
private $urlOpenXmlFormat = 'http://schemas.openxmlformats.org/spreadsheetml/2006/main'; |
17
|
|
|
/** @var string */ |
18
|
|
|
private $urlSchemaFormat = 'http://schemas.openxmlformats.org/officeDocument/2006'; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* @return string |
22
|
|
|
*/ |
23
|
|
|
public function getXml() |
24
|
|
|
{ |
25
|
|
|
return $this->xml; |
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* @return string |
30
|
|
|
*/ |
31
|
|
|
public function getSheetPr() |
32
|
|
|
{ |
33
|
|
|
$sPr = '<sheetPr filterMode="false">'; |
34
|
|
|
$sPr .= '<pageSetUpPr fitToPage="false"/>'; |
35
|
|
|
$sPr .= '</sheetPr>'; |
36
|
|
|
|
37
|
|
|
return $sPr; |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* @return string |
42
|
|
|
*/ |
43
|
|
|
public function getWorksheet() |
44
|
|
|
{ |
45
|
|
|
$wSheet = '<worksheet xmlns="'.$this->urlOpenXmlFormat.'" xmlns:r="'.$this->urlSchemaFormat.'/relationships">'; |
46
|
|
|
|
47
|
|
|
return $wSheet; |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* @param string $selectedTab |
52
|
|
|
* |
53
|
|
|
* @return string |
54
|
|
|
*/ |
55
|
|
|
public function getSheetViews($selectedTab) |
56
|
|
|
{ |
57
|
|
|
$sViews = '<sheetViews>'; |
58
|
|
|
$sViews .= '<sheetView colorId="64" defaultGridColor="true" rightToLeft="false" showFormulas="false"'; |
59
|
|
|
$sViews .= ' showGridLines="true" showOutlineSymbols="true" showRowColHeaders="true" showZeros="true"'; |
60
|
|
|
$sViews .= ' tabSelected="'.$selectedTab.'" topLeftCell="A1" view="normal" windowProtection="false"'; |
61
|
|
|
$sViews .= ' workbookViewId="0" zoomScale="100" zoomScaleNormal="100" zoomScalePageLayoutView="100">'; |
62
|
|
|
$sViews .= '<selection activeCell="A1" activeCellId="0" pane="topLeft" sqref="A1"/>'; |
63
|
|
|
$sViews .= '</sheetView>'; |
64
|
|
|
$sViews .= '</sheetViews>'; |
65
|
|
|
|
66
|
|
|
return $sViews; |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* @return string |
71
|
|
|
*/ |
72
|
|
|
public function getCools() |
73
|
|
|
{ |
74
|
|
|
$sCols = '<cols>'; |
75
|
|
|
$sCols .= '<col collapsed="false" hidden="false" max="1025" min="1" style="0" width="11.5"/>'; |
76
|
|
|
$sCols .= '</cols>'; |
77
|
|
|
|
78
|
|
|
return $sCols; |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* @param string $maxCell |
83
|
|
|
* |
84
|
|
|
* @return string |
85
|
|
|
*/ |
86
|
|
|
public function getDimension($maxCell) |
87
|
|
|
{ |
88
|
|
|
$sCols = '<dimension ref="A1:'.$maxCell.'"/>'; |
89
|
|
|
|
90
|
|
|
return $sCols; |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
/** |
94
|
|
|
* @todo refactor |
95
|
|
|
* |
96
|
|
|
* @return string |
97
|
|
|
*/ |
98
|
|
|
public function getHeaderFooter() |
99
|
|
|
{ |
100
|
|
|
$hf = '<headerFooter differentFirst="false" differentOddEven="false">'; |
101
|
|
|
$hf .= '<oddHeader>&C&"Times New Roman,Regular"&12&A</oddHeader>'; |
102
|
|
|
$hf .= '<oddFooter>&C&"Times New Roman,Regular"&12Page &P</oddFooter>'; |
103
|
|
|
$hf .= '</headerFooter>'; |
104
|
|
|
|
105
|
|
|
return $hf; |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
/** |
109
|
|
|
* @return string |
110
|
|
|
*/ |
111
|
|
|
public function getPageSetup() |
112
|
|
|
{ |
113
|
|
|
return '<pageSetup blackAndWhite="false" cellComments="none" copies="1" draft="false" firstPageNumber="1" |
114
|
|
|
fitToHeight="1" fitToWidth="1" horizontalDpi="300" orientation="portrait" pageOrder="downThenOver" |
115
|
|
|
paperSize="1" scale="100" useFirstPageNumber="true" usePrinterDefaults="false" verticalDpi="300"/>'; |
116
|
|
|
} |
117
|
|
|
|
118
|
|
|
/** |
119
|
|
|
* @return string |
120
|
|
|
*/ |
121
|
|
|
public function getPageMargins() |
122
|
|
|
{ |
123
|
|
|
return '<pageMargins left="0.5" right="0.5" top="1.0" bottom="1.0" header="0.5" footer="0.5"/>'; |
124
|
|
|
} |
125
|
|
|
|
126
|
|
|
/** |
127
|
|
|
* @return string |
128
|
|
|
*/ |
129
|
|
|
public function getPrintOptions() |
130
|
|
|
{ |
131
|
|
|
return '<printOptions headings="false" gridLines="false" gridLinesSet="true" horizontalCentered="false" |
132
|
|
|
verticalCentered="false"/>'; |
133
|
|
|
} |
134
|
|
|
|
135
|
|
|
/** |
136
|
|
|
* @param array $mergeCells |
137
|
|
|
* |
138
|
|
|
* @return string |
139
|
|
|
*/ |
140
|
|
|
public function getMergeCells(array $mergeCells) |
141
|
|
|
{ |
142
|
|
|
$mc = '<mergeCells>'; |
143
|
|
|
foreach ($mergeCells as $range) { |
144
|
|
|
$mc .= '<mergeCell ref="'.$range.'"/>'; |
145
|
|
|
} |
146
|
|
|
$mc .= '</mergeCells>'; |
147
|
|
|
|
148
|
|
|
return $mc; |
149
|
|
|
} |
150
|
|
|
} |
151
|
|
|
|