28 $objWriter =
new XMLWriter(XMLWriter::STORAGE_MEMORY);
32 $objWriter->startDocument(
'1.0',
'UTF-8',
'yes');
35 $objWriter->startElement(
'xdr:wsDr');
36 $objWriter->writeAttribute(
'xmlns:xdr',
'http://schemas.openxmlformats.org/drawingml/2006/spreadsheetDrawing');
37 $objWriter->writeAttribute(
'xmlns:a',
'http://schemas.openxmlformats.org/drawingml/2006/main');
41 $iterator = $pWorksheet->getDrawingCollection()->getIterator();
42 while ($iterator->valid()) {
44 $pDrawing = $iterator->current();
46 $hlinkClickId = $pDrawing->getHyperlink() === null ? null : ++
$i;
48 $this->
writeDrawing($objWriter, $pDrawing, $pRelationId, $hlinkClickId);
55 $chartCount = $pWorksheet->getChartCount();
57 if ($chartCount > 0) {
58 for (
$c = 0;
$c < $chartCount; ++
$c) {
65 $unparsedLoadedData = $pWorksheet->getParent()->getUnparsedLoadedData();
66 if (isset($unparsedLoadedData[
'sheets'][$pWorksheet->getCodeName()][
'drawingAlternateContents'])) {
67 foreach ($unparsedLoadedData[
'sheets'][$pWorksheet->getCodeName()][
'drawingAlternateContents'] as $drawingAlternateContent) {
68 $objWriter->writeRaw($drawingAlternateContent);
72 $objWriter->endElement();
75 return $objWriter->getData();
86 $tl = $pChart->getTopLeftPosition();
88 $br = $pChart->getBottomRightPosition();
91 $objWriter->startElement(
'xdr:twoCellAnchor');
93 $objWriter->startElement(
'xdr:from');
94 $objWriter->writeElement(
'xdr:col', $tlColRow[0] - 1);
95 $objWriter->writeElement(
'xdr:colOff', \
PhpOffice\PhpSpreadsheet\Shared\Drawing::pixelsToEMU($tl[
'xOffset']));
96 $objWriter->writeElement(
'xdr:row', $tlColRow[1] - 1);
97 $objWriter->writeElement(
'xdr:rowOff', \
PhpOffice\PhpSpreadsheet\Shared\Drawing::pixelsToEMU($tl[
'yOffset']));
98 $objWriter->endElement();
99 $objWriter->startElement(
'xdr:to');
100 $objWriter->writeElement(
'xdr:col', $brColRow[0] - 1);
101 $objWriter->writeElement(
'xdr:colOff', \
PhpOffice\PhpSpreadsheet\Shared\Drawing::pixelsToEMU($br[
'xOffset']));
102 $objWriter->writeElement(
'xdr:row', $brColRow[1] - 1);
103 $objWriter->writeElement(
'xdr:rowOff', \
PhpOffice\PhpSpreadsheet\Shared\Drawing::pixelsToEMU($br[
'yOffset']));
104 $objWriter->endElement();
106 $objWriter->startElement(
'xdr:graphicFrame');
107 $objWriter->writeAttribute(
'macro',
'');
108 $objWriter->startElement(
'xdr:nvGraphicFramePr');
109 $objWriter->startElement(
'xdr:cNvPr');
110 $objWriter->writeAttribute(
'name',
'Chart ' . $pRelationId);
111 $objWriter->writeAttribute(
'id', 1025 * $pRelationId);
112 $objWriter->endElement();
113 $objWriter->startElement(
'xdr:cNvGraphicFramePr');
114 $objWriter->startElement(
'a:graphicFrameLocks');
115 $objWriter->endElement();
116 $objWriter->endElement();
117 $objWriter->endElement();
119 $objWriter->startElement(
'xdr:xfrm');
120 $objWriter->startElement(
'a:off');
121 $objWriter->writeAttribute(
'x',
'0');
122 $objWriter->writeAttribute(
'y',
'0');
123 $objWriter->endElement();
124 $objWriter->startElement(
'a:ext');
125 $objWriter->writeAttribute(
'cx',
'0');
126 $objWriter->writeAttribute(
'cy',
'0');
127 $objWriter->endElement();
128 $objWriter->endElement();
130 $objWriter->startElement(
'a:graphic');
131 $objWriter->startElement(
'a:graphicData');
132 $objWriter->writeAttribute(
'uri',
'http://schemas.openxmlformats.org/drawingml/2006/chart');
133 $objWriter->startElement(
'c:chart');
134 $objWriter->writeAttribute(
'xmlns:c',
'http://schemas.openxmlformats.org/drawingml/2006/chart');
135 $objWriter->writeAttribute(
'xmlns:r',
'http://schemas.openxmlformats.org/officeDocument/2006/relationships');
136 $objWriter->writeAttribute(
'r:id',
'rId' . $pRelationId);
137 $objWriter->endElement();
138 $objWriter->endElement();
139 $objWriter->endElement();
140 $objWriter->endElement();
142 $objWriter->startElement(
'xdr:clientData');
143 $objWriter->endElement();
145 $objWriter->endElement();
157 if ($pRelationId >= 0) {
159 $objWriter->startElement(
'xdr:oneCellAnchor');
164 $objWriter->startElement(
'xdr:from');
165 $objWriter->writeElement(
'xdr:col', $aCoordinates[0] - 1);
166 $objWriter->writeElement(
'xdr:colOff', \
PhpOffice\PhpSpreadsheet\Shared\Drawing::pixelsToEMU($pDrawing->
getOffsetX()));
167 $objWriter->writeElement(
'xdr:row', $aCoordinates[1] - 1);
168 $objWriter->writeElement(
'xdr:rowOff', \
PhpOffice\PhpSpreadsheet\Shared\Drawing::pixelsToEMU($pDrawing->
getOffsetY()));
169 $objWriter->endElement();
172 $objWriter->startElement(
'xdr:ext');
173 $objWriter->writeAttribute(
'cx', \
PhpOffice\PhpSpreadsheet\Shared\Drawing::pixelsToEMU($pDrawing->
getWidth()));
174 $objWriter->writeAttribute(
'cy', \
PhpOffice\PhpSpreadsheet\Shared\Drawing::pixelsToEMU($pDrawing->
getHeight()));
175 $objWriter->endElement();
178 $objWriter->startElement(
'xdr:pic');
181 $objWriter->startElement(
'xdr:nvPicPr');
184 $objWriter->startElement(
'xdr:cNvPr');
185 $objWriter->writeAttribute(
'id', $pRelationId);
186 $objWriter->writeAttribute(
'name', $pDrawing->
getName());
192 $objWriter->endElement();
195 $objWriter->startElement(
'xdr:cNvPicPr');
198 $objWriter->startElement(
'a:picLocks');
199 $objWriter->writeAttribute(
'noChangeAspect',
'1');
200 $objWriter->endElement();
202 $objWriter->endElement();
204 $objWriter->endElement();
207 $objWriter->startElement(
'xdr:blipFill');
210 $objWriter->startElement(
'a:blip');
211 $objWriter->writeAttribute(
'xmlns:r',
'http://schemas.openxmlformats.org/officeDocument/2006/relationships');
212 $objWriter->writeAttribute(
'r:embed',
'rId' . $pRelationId);
213 $objWriter->endElement();
216 $objWriter->startElement(
'a:stretch');
217 $objWriter->writeElement(
'a:fillRect', null);
218 $objWriter->endElement();
220 $objWriter->endElement();
223 $objWriter->startElement(
'xdr:spPr');
226 $objWriter->startElement(
'a:xfrm');
227 $objWriter->writeAttribute(
'rot', \
PhpOffice\PhpSpreadsheet\Shared\Drawing::degreesToAngle($pDrawing->
getRotation()));
228 $objWriter->endElement();
231 $objWriter->startElement(
'a:prstGeom');
232 $objWriter->writeAttribute(
'prst',
'rect');
235 $objWriter->writeElement(
'a:avLst', null);
237 $objWriter->endElement();
239 if ($pDrawing->
getShadow()->getVisible()) {
241 $objWriter->startElement(
'a:effectLst');
244 $objWriter->startElement(
'a:outerShdw');
245 $objWriter->writeAttribute(
'blurRad', \
PhpOffice\PhpSpreadsheet\Shared\Drawing::pixelsToEMU($pDrawing->
getShadow()->getBlurRadius()));
246 $objWriter->writeAttribute(
'dist', \
PhpOffice\PhpSpreadsheet\Shared\Drawing::pixelsToEMU($pDrawing->
getShadow()->getDistance()));
247 $objWriter->writeAttribute(
'dir', \
PhpOffice\PhpSpreadsheet\Shared\Drawing::degreesToAngle($pDrawing->
getShadow()->getDirection()));
248 $objWriter->writeAttribute(
'algn', $pDrawing->
getShadow()->getAlignment());
249 $objWriter->writeAttribute(
'rotWithShape',
'0');
252 $objWriter->startElement(
'a:srgbClr');
253 $objWriter->writeAttribute(
'val', $pDrawing->
getShadow()->getColor()->getRGB());
256 $objWriter->startElement(
'a:alpha');
257 $objWriter->writeAttribute(
'val', $pDrawing->
getShadow()->getAlpha() * 1000);
258 $objWriter->endElement();
260 $objWriter->endElement();
262 $objWriter->endElement();
264 $objWriter->endElement();
266 $objWriter->endElement();
268 $objWriter->endElement();
271 $objWriter->writeElement(
'xdr:clientData', null);
273 $objWriter->endElement();
291 $objWriter =
new XMLWriter(XMLWriter::STORAGE_MEMORY);
295 $objWriter->startDocument(
'1.0',
'UTF-8',
'yes');
298 $images = $pWorksheet->getHeaderFooter()->getImages();
301 $objWriter->startElement(
'xml');
302 $objWriter->writeAttribute(
'xmlns:v',
'urn:schemas-microsoft-com:vml');
303 $objWriter->writeAttribute(
'xmlns:o',
'urn:schemas-microsoft-com:office:office');
304 $objWriter->writeAttribute(
'xmlns:x',
'urn:schemas-microsoft-com:office:excel');
307 $objWriter->startElement(
'o:shapelayout');
308 $objWriter->writeAttribute(
'v:ext',
'edit');
311 $objWriter->startElement(
'o:idmap');
312 $objWriter->writeAttribute(
'v:ext',
'edit');
313 $objWriter->writeAttribute(
'data',
'1');
314 $objWriter->endElement();
316 $objWriter->endElement();
319 $objWriter->startElement(
'v:shapetype');
320 $objWriter->writeAttribute(
'id',
'_x0000_t75');
321 $objWriter->writeAttribute(
'coordsize',
'21600,21600');
322 $objWriter->writeAttribute(
'o:spt',
'75');
323 $objWriter->writeAttribute(
'o:preferrelative',
't');
324 $objWriter->writeAttribute(
'path',
'm@4@5l@4@11@9@11@9@5xe');
325 $objWriter->writeAttribute(
'filled',
'f');
326 $objWriter->writeAttribute(
'stroked',
'f');
329 $objWriter->startElement(
'v:stroke');
330 $objWriter->writeAttribute(
'joinstyle',
'miter');
331 $objWriter->endElement();
334 $objWriter->startElement(
'v:formulas');
337 $objWriter->startElement(
'v:f');
338 $objWriter->writeAttribute(
'eqn',
'if lineDrawn pixelLineWidth 0');
339 $objWriter->endElement();
342 $objWriter->startElement(
'v:f');
343 $objWriter->writeAttribute(
'eqn',
'sum @0 1 0');
344 $objWriter->endElement();
347 $objWriter->startElement(
'v:f');
348 $objWriter->writeAttribute(
'eqn',
'sum 0 0 @1');
349 $objWriter->endElement();
352 $objWriter->startElement(
'v:f');
353 $objWriter->writeAttribute(
'eqn',
'prod @2 1 2');
354 $objWriter->endElement();
357 $objWriter->startElement(
'v:f');
358 $objWriter->writeAttribute(
'eqn',
'prod @3 21600 pixelWidth');
359 $objWriter->endElement();
362 $objWriter->startElement(
'v:f');
363 $objWriter->writeAttribute(
'eqn',
'prod @3 21600 pixelHeight');
364 $objWriter->endElement();
367 $objWriter->startElement(
'v:f');
368 $objWriter->writeAttribute(
'eqn',
'sum @0 0 1');
369 $objWriter->endElement();
372 $objWriter->startElement(
'v:f');
373 $objWriter->writeAttribute(
'eqn',
'prod @6 1 2');
374 $objWriter->endElement();
377 $objWriter->startElement(
'v:f');
378 $objWriter->writeAttribute(
'eqn',
'prod @7 21600 pixelWidth');
379 $objWriter->endElement();
382 $objWriter->startElement(
'v:f');
383 $objWriter->writeAttribute(
'eqn',
'sum @8 21600 0');
384 $objWriter->endElement();
387 $objWriter->startElement(
'v:f');
388 $objWriter->writeAttribute(
'eqn',
'prod @7 21600 pixelHeight');
389 $objWriter->endElement();
392 $objWriter->startElement(
'v:f');
393 $objWriter->writeAttribute(
'eqn',
'sum @10 21600 0');
394 $objWriter->endElement();
396 $objWriter->endElement();
399 $objWriter->startElement(
'v:path');
400 $objWriter->writeAttribute(
'o:extrusionok',
'f');
401 $objWriter->writeAttribute(
'gradientshapeok',
't');
402 $objWriter->writeAttribute(
'o:connecttype',
'rect');
403 $objWriter->endElement();
406 $objWriter->startElement(
'o:lock');
407 $objWriter->writeAttribute(
'v:ext',
'edit');
408 $objWriter->writeAttribute(
'aspectratio',
't');
409 $objWriter->endElement();
411 $objWriter->endElement();
414 foreach ($images as
$key => $value) {
418 $objWriter->endElement();
421 return $objWriter->getData();
434 preg_match(
'{(\d+)}', md5($pReference),
$m);
435 $id = 1500 + ((int) substr(
$m[1], 0, 2) * 1);
438 $width = $pImage->getWidth();
439 $height = $pImage->getHeight();
440 $marginLeft = $pImage->getOffsetX();
441 $marginTop = $pImage->getOffsetY();
444 $objWriter->startElement(
'v:shape');
445 $objWriter->writeAttribute(
'id', $pReference);
446 $objWriter->writeAttribute(
'o:spid',
'_x0000_s' .
$id);
447 $objWriter->writeAttribute(
'type',
'#_x0000_t75');
448 $objWriter->writeAttribute(
'style',
"position:absolute;margin-left:{$marginLeft}px;margin-top:{$marginTop}px;width:{$width}px;height:{$height}px;z-index:1");
451 $objWriter->startElement(
'v:imagedata');
452 $objWriter->writeAttribute(
'o:relid',
'rId' . $pReference);
453 $objWriter->writeAttribute(
'o:title', $pImage->getName());
454 $objWriter->endElement();
457 $objWriter->startElement(
'o:lock');
458 $objWriter->writeAttribute(
'v:ext',
'edit');
459 $objWriter->writeAttribute(
'textRotation',
't');
460 $objWriter->endElement();
462 $objWriter->endElement();
477 for (
$i = 0;
$i < $sheetCount; ++
$i) {
479 $iterator = $spreadsheet->
getSheet(
$i)->getDrawingCollection()->getIterator();
480 while ($iterator->valid()) {
481 $aDrawings[] = $iterator->current();
495 if ($hlinkClickId === null) {
499 $objWriter->startElement(
'a:hlinkClick');
500 $objWriter->writeAttribute(
'xmlns:r',
'http://schemas.openxmlformats.org/officeDocument/2006/relationships');
501 $objWriter->writeAttribute(
'r:id',
'rId' . $hlinkClickId);
502 $objWriter->endElement();
getSheet($pIndex)
Get sheet by index.
if(!array_key_exists('StateId', $_REQUEST)) $id
writeDrawing(XMLWriter $objWriter, BaseDrawing $pDrawing, $pRelationId=-1, $hlinkClickId=null)
Write drawings to XML format.
writeVMLHeaderFooterImages(\PhpOffice\PhpSpreadsheet\Worksheet\Worksheet $pWorksheet)
Write VML header/footer images to XML format.
getDiskCachingDirectory()
Get disk caching directory.
writeChart(XMLWriter $objWriter, \PhpOffice\PhpSpreadsheet\Chart\Chart $pChart, $pRelationId=-1)
Write drawings to XML format.
getParentWriter()
Get parent Xlsx object.
getDescription()
Get Description.
writeVMLHeaderFooterImage(XMLWriter $objWriter, $pReference, HeaderFooterDrawing $pImage)
Write VML comment to XML format.
static indexesFromString(string $coordinates)
Get indexes from a string coordinates.
getRotation()
Get Rotation.
getCoordinates()
Get Coordinates.
getUseDiskCaching()
Get use disk caching where possible?
allDrawings(Spreadsheet $spreadsheet)
Get an array of all drawings.
writeHyperLinkDrawing(XMLWriter $objWriter, $hlinkClickId)
getSheetCount()
Get sheet count.