1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace PhpOffice\PhpSpreadsheet\Writer; |
4
|
|
|
|
5
|
|
|
use PhpOffice\PhpSpreadsheet\Calculation\Calculation; |
6
|
|
|
use PhpOffice\PhpSpreadsheet\Calculation\Functions; |
7
|
|
|
use PhpOffice\PhpSpreadsheet\HashTable; |
8
|
|
|
use PhpOffice\PhpSpreadsheet\Shared\File; |
9
|
|
|
use PhpOffice\PhpSpreadsheet\Spreadsheet; |
10
|
|
|
use PhpOffice\PhpSpreadsheet\Worksheet\Drawing as WorksheetDrawing; |
11
|
|
|
use PhpOffice\PhpSpreadsheet\Worksheet\MemoryDrawing; |
12
|
|
|
use PhpOffice\PhpSpreadsheet\Writer\Exception as WriterException; |
13
|
|
|
use PhpOffice\PhpSpreadsheet\Writer\Xlsx\Chart; |
14
|
|
|
use PhpOffice\PhpSpreadsheet\Writer\Xlsx\Comments; |
15
|
|
|
use PhpOffice\PhpSpreadsheet\Writer\Xlsx\ContentTypes; |
16
|
|
|
use PhpOffice\PhpSpreadsheet\Writer\Xlsx\DocProps; |
17
|
|
|
use PhpOffice\PhpSpreadsheet\Writer\Xlsx\Drawing; |
18
|
|
|
use PhpOffice\PhpSpreadsheet\Writer\Xlsx\Rels; |
19
|
|
|
use PhpOffice\PhpSpreadsheet\Writer\Xlsx\RelsRibbon; |
20
|
|
|
use PhpOffice\PhpSpreadsheet\Writer\Xlsx\RelsVBA; |
21
|
|
|
use PhpOffice\PhpSpreadsheet\Writer\Xlsx\StringTable; |
22
|
|
|
use PhpOffice\PhpSpreadsheet\Writer\Xlsx\Style; |
23
|
|
|
use PhpOffice\PhpSpreadsheet\Writer\Xlsx\Theme; |
24
|
|
|
use PhpOffice\PhpSpreadsheet\Writer\Xlsx\Workbook; |
25
|
|
|
use PhpOffice\PhpSpreadsheet\Writer\Xlsx\Worksheet; |
26
|
|
|
use ZipArchive; |
27
|
|
|
use ZipStream\Exception\OverflowException; |
28
|
|
|
use ZipStream\Option\Archive; |
29
|
|
|
use ZipStream\ZipStream; |
30
|
|
|
|
31
|
|
|
class Xlsx extends BaseWriter |
32
|
|
|
{ |
33
|
|
|
/** |
34
|
|
|
* Office2003 compatibility. |
35
|
|
|
* |
36
|
|
|
* @var bool |
37
|
|
|
*/ |
38
|
|
|
private $office2003compatibility = false; |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* Private writer parts. |
42
|
|
|
* |
43
|
|
|
* @var Xlsx\WriterPart[] |
44
|
|
|
*/ |
45
|
|
|
private $writerParts = []; |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* Private Spreadsheet. |
49
|
|
|
* |
50
|
|
|
* @var Spreadsheet |
51
|
|
|
*/ |
52
|
|
|
private $spreadSheet; |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* Private string table. |
56
|
|
|
* |
57
|
|
|
* @var string[] |
58
|
|
|
*/ |
59
|
|
|
private $stringTable = []; |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* Private unique Conditional HashTable. |
63
|
|
|
* |
64
|
|
|
* @var HashTable |
65
|
|
|
*/ |
66
|
|
|
private $stylesConditionalHashTable; |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* Private unique Style HashTable. |
70
|
|
|
* |
71
|
|
|
* @var HashTable |
72
|
|
|
*/ |
73
|
|
|
private $styleHashTable; |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* Private unique Fill HashTable. |
77
|
|
|
* |
78
|
|
|
* @var HashTable |
79
|
|
|
*/ |
80
|
|
|
private $fillHashTable; |
81
|
|
|
|
82
|
|
|
/** |
83
|
|
|
* Private unique \PhpOffice\PhpSpreadsheet\Style\Font HashTable. |
84
|
|
|
* |
85
|
|
|
* @var HashTable |
86
|
|
|
*/ |
87
|
|
|
private $fontHashTable; |
88
|
|
|
|
89
|
|
|
/** |
90
|
|
|
* Private unique Borders HashTable. |
91
|
|
|
* |
92
|
|
|
* @var HashTable |
93
|
|
|
*/ |
94
|
|
|
private $bordersHashTable; |
95
|
|
|
|
96
|
|
|
/** |
97
|
|
|
* Private unique NumberFormat HashTable. |
98
|
|
|
* |
99
|
|
|
* @var HashTable |
100
|
|
|
*/ |
101
|
|
|
private $numFmtHashTable; |
102
|
|
|
|
103
|
|
|
/** |
104
|
|
|
* Private unique \PhpOffice\PhpSpreadsheet\Worksheet\Worksheet\BaseDrawing HashTable. |
105
|
|
|
* |
106
|
|
|
* @var HashTable |
107
|
|
|
*/ |
108
|
|
|
private $drawingHashTable; |
109
|
|
|
|
110
|
|
|
/** |
111
|
|
|
* Create a new Xlsx Writer. |
112
|
|
|
* |
113
|
|
|
* @param Spreadsheet $spreadsheet |
114
|
|
|
*/ |
115
|
107 |
|
public function __construct(Spreadsheet $spreadsheet) |
116
|
|
|
{ |
117
|
|
|
// Assign PhpSpreadsheet |
118
|
107 |
|
$this->setSpreadsheet($spreadsheet); |
119
|
|
|
|
120
|
|
|
$writerPartsArray = [ |
121
|
107 |
|
'stringtable' => StringTable::class, |
122
|
|
|
'contenttypes' => ContentTypes::class, |
123
|
|
|
'docprops' => DocProps::class, |
124
|
|
|
'rels' => Rels::class, |
125
|
|
|
'theme' => Theme::class, |
126
|
|
|
'style' => Style::class, |
127
|
|
|
'workbook' => Workbook::class, |
128
|
|
|
'worksheet' => Worksheet::class, |
129
|
|
|
'drawing' => Drawing::class, |
130
|
|
|
'comments' => Comments::class, |
131
|
|
|
'chart' => Chart::class, |
132
|
|
|
'relsvba' => RelsVBA::class, |
133
|
|
|
'relsribbonobjects' => RelsRibbon::class, |
134
|
|
|
]; |
135
|
|
|
|
136
|
|
|
// Initialise writer parts |
137
|
|
|
// and Assign their parent IWriters |
138
|
107 |
|
foreach ($writerPartsArray as $writer => $class) { |
139
|
107 |
|
$this->writerParts[$writer] = new $class($this); |
140
|
|
|
} |
141
|
|
|
|
142
|
107 |
|
$hashTablesArray = ['stylesConditionalHashTable', 'fillHashTable', 'fontHashTable', |
143
|
|
|
'bordersHashTable', 'numFmtHashTable', 'drawingHashTable', |
144
|
|
|
'styleHashTable', |
145
|
|
|
]; |
146
|
|
|
|
147
|
|
|
// Set HashTable variables |
148
|
107 |
|
foreach ($hashTablesArray as $tableName) { |
149
|
107 |
|
$this->$tableName = new HashTable(); |
150
|
|
|
} |
151
|
107 |
|
} |
152
|
|
|
|
153
|
|
|
/** |
154
|
|
|
* Get writer part. |
155
|
|
|
* |
156
|
|
|
* @param string $pPartName Writer part name |
157
|
|
|
* |
158
|
|
|
* @return \PhpOffice\PhpSpreadsheet\Writer\Xlsx\WriterPart |
159
|
|
|
*/ |
160
|
106 |
|
public function getWriterPart($pPartName) |
161
|
|
|
{ |
162
|
106 |
|
if ($pPartName != '' && isset($this->writerParts[strtolower($pPartName)])) { |
163
|
106 |
|
return $this->writerParts[strtolower($pPartName)]; |
164
|
|
|
} |
165
|
|
|
|
166
|
|
|
return null; |
167
|
|
|
} |
168
|
|
|
|
169
|
|
|
/** |
170
|
|
|
* Save PhpSpreadsheet to file. |
171
|
|
|
* |
172
|
|
|
* @param resource|string $pFilename |
173
|
|
|
* |
174
|
|
|
* @throws WriterException |
175
|
|
|
*/ |
176
|
106 |
|
public function save($pFilename) |
177
|
|
|
{ |
178
|
106 |
|
if ($this->spreadSheet !== null) { |
179
|
|
|
// garbage collect |
180
|
106 |
|
$this->spreadSheet->garbageCollect(); |
181
|
|
|
|
182
|
106 |
|
$this->openFileHandle($pFilename); |
183
|
|
|
|
184
|
106 |
|
$saveDebugLog = Calculation::getInstance($this->spreadSheet)->getDebugLog()->getWriteDebugLog(); |
185
|
106 |
|
Calculation::getInstance($this->spreadSheet)->getDebugLog()->setWriteDebugLog(false); |
186
|
106 |
|
$saveDateReturnType = Functions::getReturnDateType(); |
187
|
106 |
|
Functions::setReturnDateType(Functions::RETURNDATE_EXCEL); |
188
|
|
|
|
189
|
|
|
// Create string lookup table |
190
|
106 |
|
$this->stringTable = []; |
191
|
106 |
|
for ($i = 0; $i < $this->spreadSheet->getSheetCount(); ++$i) { |
192
|
106 |
|
$this->stringTable = $this->getWriterPart('StringTable')->createStringTable($this->spreadSheet->getSheet($i), $this->stringTable); |
|
|
|
|
193
|
|
|
} |
194
|
|
|
|
195
|
|
|
// Create styles dictionaries |
196
|
106 |
|
$this->styleHashTable->addFromSource($this->getWriterPart('Style')->allStyles($this->spreadSheet)); |
|
|
|
|
197
|
106 |
|
$this->stylesConditionalHashTable->addFromSource($this->getWriterPart('Style')->allConditionalStyles($this->spreadSheet)); |
|
|
|
|
198
|
106 |
|
$this->fillHashTable->addFromSource($this->getWriterPart('Style')->allFills($this->spreadSheet)); |
|
|
|
|
199
|
106 |
|
$this->fontHashTable->addFromSource($this->getWriterPart('Style')->allFonts($this->spreadSheet)); |
|
|
|
|
200
|
106 |
|
$this->bordersHashTable->addFromSource($this->getWriterPart('Style')->allBorders($this->spreadSheet)); |
|
|
|
|
201
|
106 |
|
$this->numFmtHashTable->addFromSource($this->getWriterPart('Style')->allNumberFormats($this->spreadSheet)); |
|
|
|
|
202
|
|
|
|
203
|
|
|
// Create drawing dictionary |
204
|
106 |
|
$this->drawingHashTable->addFromSource($this->getWriterPart('Drawing')->allDrawings($this->spreadSheet)); |
|
|
|
|
205
|
|
|
|
206
|
106 |
|
$options = new Archive(); |
207
|
106 |
|
$options->setEnableZip64(false); |
208
|
106 |
|
$options->setOutputStream($this->fileHandle); |
209
|
|
|
|
210
|
106 |
|
$zip = new ZipStream(null, $options); |
211
|
|
|
|
212
|
|
|
// Add [Content_Types].xml to ZIP file |
213
|
106 |
|
$zip->addFile('[Content_Types].xml', $this->getWriterPart('ContentTypes')->writeContentTypes($this->spreadSheet, $this->includeCharts)); |
|
|
|
|
214
|
|
|
|
215
|
|
|
//if hasMacros, add the vbaProject.bin file, Certificate file(if exists) |
216
|
106 |
|
if ($this->spreadSheet->hasMacros()) { |
217
|
1 |
|
$macrosCode = $this->spreadSheet->getMacrosCode(); |
218
|
1 |
|
if ($macrosCode !== null) { |
|
|
|
|
219
|
|
|
// we have the code ? |
220
|
1 |
|
$zip->addFile('xl/vbaProject.bin', $macrosCode); //allways in 'xl', allways named vbaProject.bin |
221
|
1 |
|
if ($this->spreadSheet->hasMacrosCertificate()) { |
222
|
|
|
//signed macros ? |
223
|
|
|
// Yes : add the certificate file and the related rels file |
224
|
|
|
$zip->addFile('xl/vbaProjectSignature.bin', $this->spreadSheet->getMacrosCertificate()); |
225
|
|
|
$zip->addFile('xl/_rels/vbaProject.bin.rels', $this->getWriterPart('RelsVBA')->writeVBARelationships($this->spreadSheet)); |
|
|
|
|
226
|
|
|
} |
227
|
|
|
} |
228
|
|
|
} |
229
|
|
|
//a custom UI in this workbook ? add it ("base" xml and additional objects (pictures) and rels) |
230
|
106 |
|
if ($this->spreadSheet->hasRibbon()) { |
231
|
|
|
$tmpRibbonTarget = $this->spreadSheet->getRibbonXMLData('target'); |
232
|
|
|
$zip->addFile($tmpRibbonTarget, $this->spreadSheet->getRibbonXMLData('data')); |
233
|
|
|
if ($this->spreadSheet->hasRibbonBinObjects()) { |
234
|
|
|
$tmpRootPath = dirname($tmpRibbonTarget) . '/'; |
235
|
|
|
$ribbonBinObjects = $this->spreadSheet->getRibbonBinObjects('data'); //the files to write |
236
|
|
|
foreach ($ribbonBinObjects as $aPath => $aContent) { |
237
|
|
|
$zip->addFile($tmpRootPath . $aPath, $aContent); |
238
|
|
|
} |
239
|
|
|
//the rels for files |
240
|
|
|
$zip->addFile($tmpRootPath . '_rels/' . basename($tmpRibbonTarget) . '.rels', $this->getWriterPart('RelsRibbonObjects')->writeRibbonRelationships($this->spreadSheet)); |
|
|
|
|
241
|
|
|
} |
242
|
|
|
} |
243
|
|
|
|
244
|
|
|
// Add relationships to ZIP file |
245
|
106 |
|
$zip->addFile('_rels/.rels', $this->getWriterPart('Rels')->writeRelationships($this->spreadSheet)); |
|
|
|
|
246
|
106 |
|
$zip->addFile('xl/_rels/workbook.xml.rels', $this->getWriterPart('Rels')->writeWorkbookRelationships($this->spreadSheet)); |
|
|
|
|
247
|
|
|
|
248
|
|
|
// Add document properties to ZIP file |
249
|
106 |
|
$zip->addFile('docProps/app.xml', $this->getWriterPart('DocProps')->writeDocPropsApp($this->spreadSheet)); |
|
|
|
|
250
|
106 |
|
$zip->addFile('docProps/core.xml', $this->getWriterPart('DocProps')->writeDocPropsCore($this->spreadSheet)); |
|
|
|
|
251
|
106 |
|
$customPropertiesPart = $this->getWriterPart('DocProps')->writeDocPropsCustom($this->spreadSheet); |
|
|
|
|
252
|
106 |
|
if ($customPropertiesPart !== null) { |
253
|
2 |
|
$zip->addFile('docProps/custom.xml', $customPropertiesPart); |
254
|
|
|
} |
255
|
|
|
|
256
|
|
|
// Add theme to ZIP file |
257
|
106 |
|
$zip->addFile('xl/theme/theme1.xml', $this->getWriterPart('Theme')->writeTheme($this->spreadSheet)); |
|
|
|
|
258
|
|
|
|
259
|
|
|
// Add string table to ZIP file |
260
|
106 |
|
$zip->addFile('xl/sharedStrings.xml', $this->getWriterPart('StringTable')->writeStringTable($this->stringTable)); |
|
|
|
|
261
|
|
|
|
262
|
|
|
// Add styles to ZIP file |
263
|
106 |
|
$zip->addFile('xl/styles.xml', $this->getWriterPart('Style')->writeStyles($this->spreadSheet)); |
|
|
|
|
264
|
|
|
|
265
|
|
|
// Add workbook to ZIP file |
266
|
106 |
|
$zip->addFile('xl/workbook.xml', $this->getWriterPart('Workbook')->writeWorkbook($this->spreadSheet, $this->preCalculateFormulas)); |
|
|
|
|
267
|
|
|
|
268
|
106 |
|
$chartCount = 0; |
269
|
|
|
// Add worksheets |
270
|
106 |
|
for ($i = 0; $i < $this->spreadSheet->getSheetCount(); ++$i) { |
271
|
106 |
|
$zip->addFile('xl/worksheets/sheet' . ($i + 1) . '.xml', $this->getWriterPart('Worksheet')->writeWorksheet($this->spreadSheet->getSheet($i), $this->stringTable, $this->includeCharts)); |
|
|
|
|
272
|
106 |
|
if ($this->includeCharts) { |
273
|
15 |
|
$charts = $this->spreadSheet->getSheet($i)->getChartCollection(); |
274
|
15 |
|
if (count($charts) > 0) { |
275
|
14 |
|
foreach ($charts as $chart) { |
276
|
14 |
|
$zip->addFile('xl/charts/chart' . ($chartCount + 1) . '.xml', $this->getWriterPart('Chart')->writeChart($chart, $this->preCalculateFormulas)); |
|
|
|
|
277
|
14 |
|
++$chartCount; |
278
|
|
|
} |
279
|
|
|
} |
280
|
|
|
} |
281
|
|
|
} |
282
|
|
|
|
283
|
106 |
|
$chartRef1 = 0; |
284
|
|
|
// Add worksheet relationships (drawings, ...) |
285
|
106 |
|
for ($i = 0; $i < $this->spreadSheet->getSheetCount(); ++$i) { |
286
|
|
|
// Add relationships |
287
|
106 |
|
$zip->addFile('xl/worksheets/_rels/sheet' . ($i + 1) . '.xml.rels', $this->getWriterPart('Rels')->writeWorksheetRelationships($this->spreadSheet->getSheet($i), ($i + 1), $this->includeCharts)); |
|
|
|
|
288
|
|
|
|
289
|
|
|
// Add unparsedLoadedData |
290
|
106 |
|
$sheetCodeName = $this->spreadSheet->getSheet($i)->getCodeName(); |
291
|
106 |
|
$unparsedLoadedData = $this->spreadSheet->getUnparsedLoadedData(); |
292
|
106 |
|
if (isset($unparsedLoadedData['sheets'][$sheetCodeName]['ctrlProps'])) { |
293
|
1 |
|
foreach ($unparsedLoadedData['sheets'][$sheetCodeName]['ctrlProps'] as $ctrlProp) { |
294
|
1 |
|
$zip->addFile($ctrlProp['filePath'], $ctrlProp['content']); |
295
|
|
|
} |
296
|
|
|
} |
297
|
106 |
|
if (isset($unparsedLoadedData['sheets'][$sheetCodeName]['printerSettings'])) { |
298
|
4 |
|
foreach ($unparsedLoadedData['sheets'][$sheetCodeName]['printerSettings'] as $ctrlProp) { |
299
|
4 |
|
$zip->addFile($ctrlProp['filePath'], $ctrlProp['content']); |
300
|
|
|
} |
301
|
|
|
} |
302
|
|
|
|
303
|
106 |
|
$drawings = $this->spreadSheet->getSheet($i)->getDrawingCollection(); |
304
|
106 |
|
$drawingCount = count($drawings); |
305
|
106 |
|
if ($this->includeCharts) { |
306
|
15 |
|
$chartCount = $this->spreadSheet->getSheet($i)->getChartCount(); |
307
|
|
|
} |
308
|
|
|
|
309
|
|
|
// Add drawing and image relationship parts |
310
|
106 |
|
if (($drawingCount > 0) || ($chartCount > 0)) { |
311
|
|
|
// Drawing relationships |
312
|
25 |
|
$zip->addFile('xl/drawings/_rels/drawing' . ($i + 1) . '.xml.rels', $this->getWriterPart('Rels')->writeDrawingRelationships($this->spreadSheet->getSheet($i), $chartRef1, $this->includeCharts)); |
|
|
|
|
313
|
|
|
|
314
|
|
|
// Drawings |
315
|
25 |
|
$zip->addFile('xl/drawings/drawing' . ($i + 1) . '.xml', $this->getWriterPart('Drawing')->writeDrawings($this->spreadSheet->getSheet($i), $this->includeCharts)); |
|
|
|
|
316
|
82 |
|
} elseif (isset($unparsedLoadedData['sheets'][$sheetCodeName]['drawingAlternateContents'])) { |
317
|
|
|
// Drawings |
318
|
1 |
|
$zip->addFile('xl/drawings/drawing' . ($i + 1) . '.xml', $this->getWriterPart('Drawing')->writeDrawings($this->spreadSheet->getSheet($i), $this->includeCharts)); |
319
|
|
|
} |
320
|
|
|
|
321
|
|
|
// Add unparsed drawings |
322
|
106 |
|
if (isset($unparsedLoadedData['sheets'][$sheetCodeName]['Drawings'])) { |
323
|
2 |
|
foreach ($unparsedLoadedData['sheets'][$sheetCodeName]['Drawings'] as $relId => $drawingXml) { |
324
|
2 |
|
$drawingFile = array_search($relId, $unparsedLoadedData['sheets'][$sheetCodeName]['drawingOriginalIds']); |
325
|
2 |
|
if ($drawingFile !== false) { |
326
|
2 |
|
$drawingFile = ltrim($drawingFile, '.'); |
327
|
2 |
|
$zip->addFile('xl' . $drawingFile, $drawingXml); |
328
|
|
|
} |
329
|
|
|
} |
330
|
|
|
} |
331
|
|
|
|
332
|
|
|
// Add comment relationship parts |
333
|
106 |
|
if (count($this->spreadSheet->getSheet($i)->getComments()) > 0) { |
334
|
|
|
// VML Comments |
335
|
10 |
|
$zip->addFile('xl/drawings/vmlDrawing' . ($i + 1) . '.vml', $this->getWriterPart('Comments')->writeVMLComments($this->spreadSheet->getSheet($i))); |
|
|
|
|
336
|
|
|
|
337
|
|
|
// Comments |
338
|
10 |
|
$zip->addFile('xl/comments' . ($i + 1) . '.xml', $this->getWriterPart('Comments')->writeComments($this->spreadSheet->getSheet($i))); |
|
|
|
|
339
|
|
|
} |
340
|
|
|
|
341
|
|
|
// Add unparsed relationship parts |
342
|
106 |
|
if (isset($unparsedLoadedData['sheets'][$sheetCodeName]['vmlDrawings'])) { |
343
|
1 |
|
foreach ($unparsedLoadedData['sheets'][$sheetCodeName]['vmlDrawings'] as $vmlDrawing) { |
344
|
1 |
|
$zip->addFile($vmlDrawing['filePath'], $vmlDrawing['content']); |
345
|
|
|
} |
346
|
|
|
} |
347
|
|
|
|
348
|
|
|
// Add header/footer relationship parts |
349
|
106 |
|
if (count($this->spreadSheet->getSheet($i)->getHeaderFooter()->getImages()) > 0) { |
350
|
|
|
// VML Drawings |
351
|
1 |
|
$zip->addFile('xl/drawings/vmlDrawingHF' . ($i + 1) . '.vml', $this->getWriterPart('Drawing')->writeVMLHeaderFooterImages($this->spreadSheet->getSheet($i))); |
|
|
|
|
352
|
|
|
|
353
|
|
|
// VML Drawing relationships |
354
|
1 |
|
$zip->addFile('xl/drawings/_rels/vmlDrawingHF' . ($i + 1) . '.vml.rels', $this->getWriterPart('Rels')->writeHeaderFooterDrawingRelationships($this->spreadSheet->getSheet($i))); |
|
|
|
|
355
|
|
|
|
356
|
|
|
// Media |
357
|
1 |
|
foreach ($this->spreadSheet->getSheet($i)->getHeaderFooter()->getImages() as $image) { |
358
|
1 |
|
$zip->addFile('xl/media/' . $image->getIndexedFilename(), file_get_contents($image->getPath())); |
359
|
|
|
} |
360
|
|
|
} |
361
|
|
|
} |
362
|
|
|
|
363
|
|
|
// Add media |
364
|
106 |
|
for ($i = 0; $i < $this->getDrawingHashTable()->count(); ++$i) { |
365
|
12 |
|
if ($this->getDrawingHashTable()->getByIndex($i) instanceof WorksheetDrawing) { |
366
|
6 |
|
$imageContents = null; |
367
|
6 |
|
$imagePath = $this->getDrawingHashTable()->getByIndex($i)->getPath(); |
|
|
|
|
368
|
6 |
|
if (strpos($imagePath, 'zip://') !== false) { |
369
|
2 |
|
$imagePath = substr($imagePath, 6); |
370
|
2 |
|
$imagePathSplitted = explode('#', $imagePath); |
371
|
|
|
|
372
|
2 |
|
$imageZip = new ZipArchive(); |
373
|
2 |
|
$imageZip->open($imagePathSplitted[0]); |
374
|
2 |
|
$imageContents = $imageZip->getFromName($imagePathSplitted[1]); |
375
|
2 |
|
$imageZip->close(); |
376
|
2 |
|
unset($imageZip); |
377
|
|
|
} else { |
378
|
5 |
|
$imageContents = file_get_contents($imagePath); |
379
|
|
|
} |
380
|
|
|
|
381
|
6 |
|
$zip->addFile('xl/media/' . str_replace(' ', '_', $this->getDrawingHashTable()->getByIndex($i)->getIndexedFilename()), $imageContents); |
|
|
|
|
382
|
6 |
|
} elseif ($this->getDrawingHashTable()->getByIndex($i) instanceof MemoryDrawing) { |
383
|
6 |
|
ob_start(); |
384
|
6 |
|
call_user_func( |
385
|
6 |
|
$this->getDrawingHashTable()->getByIndex($i)->getRenderingFunction(), |
|
|
|
|
386
|
6 |
|
$this->getDrawingHashTable()->getByIndex($i)->getImageResource() |
|
|
|
|
387
|
|
|
); |
388
|
6 |
|
$imageContents = ob_get_contents(); |
389
|
6 |
|
ob_end_clean(); |
390
|
|
|
|
391
|
6 |
|
$zip->addFile('xl/media/' . str_replace(' ', '_', $this->getDrawingHashTable()->getByIndex($i)->getIndexedFilename()), $imageContents); |
392
|
|
|
} |
393
|
|
|
} |
394
|
|
|
|
395
|
106 |
|
Functions::setReturnDateType($saveDateReturnType); |
396
|
106 |
|
Calculation::getInstance($this->spreadSheet)->getDebugLog()->setWriteDebugLog($saveDebugLog); |
397
|
|
|
|
398
|
|
|
// Close file |
399
|
|
|
try { |
400
|
106 |
|
$zip->finish(); |
401
|
|
|
} catch (OverflowException $e) { |
402
|
|
|
throw new WriterException('Could not close resource.'); |
403
|
|
|
} |
404
|
|
|
|
405
|
106 |
|
$this->maybeCloseFileHandle(); |
406
|
|
|
} else { |
407
|
|
|
throw new WriterException('PhpSpreadsheet object unassigned.'); |
408
|
|
|
} |
409
|
106 |
|
} |
410
|
|
|
|
411
|
|
|
/** |
412
|
|
|
* Get Spreadsheet object. |
413
|
|
|
* |
414
|
|
|
* @throws WriterException |
415
|
|
|
* |
416
|
|
|
* @return Spreadsheet |
417
|
|
|
*/ |
418
|
106 |
|
public function getSpreadsheet() |
419
|
|
|
{ |
420
|
106 |
|
if ($this->spreadSheet !== null) { |
421
|
106 |
|
return $this->spreadSheet; |
422
|
|
|
} |
423
|
|
|
|
424
|
|
|
throw new WriterException('No Spreadsheet object assigned.'); |
425
|
|
|
} |
426
|
|
|
|
427
|
|
|
/** |
428
|
|
|
* Set Spreadsheet object. |
429
|
|
|
* |
430
|
|
|
* @param Spreadsheet $spreadsheet PhpSpreadsheet object |
431
|
|
|
* |
432
|
|
|
* @return $this |
433
|
|
|
*/ |
434
|
107 |
|
public function setSpreadsheet(Spreadsheet $spreadsheet) |
435
|
|
|
{ |
436
|
107 |
|
$this->spreadSheet = $spreadsheet; |
437
|
|
|
|
438
|
107 |
|
return $this; |
439
|
|
|
} |
440
|
|
|
|
441
|
|
|
/** |
442
|
|
|
* Get string table. |
443
|
|
|
* |
444
|
|
|
* @return string[] |
445
|
|
|
*/ |
446
|
|
|
public function getStringTable() |
447
|
|
|
{ |
448
|
|
|
return $this->stringTable; |
449
|
|
|
} |
450
|
|
|
|
451
|
|
|
/** |
452
|
|
|
* Get Style HashTable. |
453
|
|
|
* |
454
|
|
|
* @return HashTable |
455
|
|
|
*/ |
456
|
|
|
public function getStyleHashTable() |
457
|
|
|
{ |
458
|
|
|
return $this->styleHashTable; |
459
|
|
|
} |
460
|
|
|
|
461
|
|
|
/** |
462
|
|
|
* Get Conditional HashTable. |
463
|
|
|
* |
464
|
|
|
* @return HashTable |
465
|
|
|
*/ |
466
|
106 |
|
public function getStylesConditionalHashTable() |
467
|
|
|
{ |
468
|
106 |
|
return $this->stylesConditionalHashTable; |
469
|
|
|
} |
470
|
|
|
|
471
|
|
|
/** |
472
|
|
|
* Get Fill HashTable. |
473
|
|
|
* |
474
|
|
|
* @return HashTable |
475
|
|
|
*/ |
476
|
106 |
|
public function getFillHashTable() |
477
|
|
|
{ |
478
|
106 |
|
return $this->fillHashTable; |
479
|
|
|
} |
480
|
|
|
|
481
|
|
|
/** |
482
|
|
|
* Get \PhpOffice\PhpSpreadsheet\Style\Font HashTable. |
483
|
|
|
* |
484
|
|
|
* @return HashTable |
485
|
|
|
*/ |
486
|
106 |
|
public function getFontHashTable() |
487
|
|
|
{ |
488
|
106 |
|
return $this->fontHashTable; |
489
|
|
|
} |
490
|
|
|
|
491
|
|
|
/** |
492
|
|
|
* Get Borders HashTable. |
493
|
|
|
* |
494
|
|
|
* @return HashTable |
495
|
|
|
*/ |
496
|
106 |
|
public function getBordersHashTable() |
497
|
|
|
{ |
498
|
106 |
|
return $this->bordersHashTable; |
499
|
|
|
} |
500
|
|
|
|
501
|
|
|
/** |
502
|
|
|
* Get NumberFormat HashTable. |
503
|
|
|
* |
504
|
|
|
* @return HashTable |
505
|
|
|
*/ |
506
|
106 |
|
public function getNumFmtHashTable() |
507
|
|
|
{ |
508
|
106 |
|
return $this->numFmtHashTable; |
509
|
|
|
} |
510
|
|
|
|
511
|
|
|
/** |
512
|
|
|
* Get \PhpOffice\PhpSpreadsheet\Worksheet\Worksheet\BaseDrawing HashTable. |
513
|
|
|
* |
514
|
|
|
* @return HashTable |
515
|
|
|
*/ |
516
|
106 |
|
public function getDrawingHashTable() |
517
|
|
|
{ |
518
|
106 |
|
return $this->drawingHashTable; |
519
|
|
|
} |
520
|
|
|
|
521
|
|
|
/** |
522
|
|
|
* Get Office2003 compatibility. |
523
|
|
|
* |
524
|
|
|
* @return bool |
525
|
|
|
*/ |
526
|
106 |
|
public function getOffice2003Compatibility() |
527
|
|
|
{ |
528
|
106 |
|
return $this->office2003compatibility; |
529
|
|
|
} |
530
|
|
|
|
531
|
|
|
/** |
532
|
|
|
* Set Office2003 compatibility. |
533
|
|
|
* |
534
|
|
|
* @param bool $pValue Office2003 compatibility? |
535
|
|
|
* |
536
|
|
|
* @return $this |
537
|
|
|
*/ |
538
|
|
|
public function setOffice2003Compatibility($pValue) |
539
|
|
|
{ |
540
|
|
|
$this->office2003compatibility = $pValue; |
541
|
|
|
|
542
|
|
|
return $this; |
543
|
|
|
} |
544
|
|
|
} |
545
|
|
|
|