Drawing.php 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598
  1. <?php
  2. /**
  3. * PHPExcel
  4. *
  5. * Copyright (c) 2006 - 2013 PHPExcel
  6. *
  7. * This library is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU Lesser General Public
  9. * License as published by the Free Software Foundation; either
  10. * version 2.1 of the License, or (at your option) any later version.
  11. *
  12. * This library is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. * Lesser General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU Lesser General Public
  18. * License along with this library; if not, write to the Free Software
  19. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  20. *
  21. * @category PHPExcel
  22. * @package PHPExcel_Writer_Excel2007
  23. * @copyright Copyright (c) 2006 - 2013 PHPExcel (http://www.codeplex.com/PHPExcel)
  24. * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
  25. * @version 1.7.9, 2013-06-02
  26. */
  27. /**
  28. * PHPExcel_Writer_Excel2007_Drawing
  29. *
  30. * @category PHPExcel
  31. * @package PHPExcel_Writer_Excel2007
  32. * @copyright Copyright (c) 2006 - 2013 PHPExcel (http://www.codeplex.com/PHPExcel)
  33. */
  34. class PHPExcel_Writer_Excel2007_Drawing extends PHPExcel_Writer_Excel2007_WriterPart
  35. {
  36. /**
  37. * Write drawings to XML format
  38. *
  39. * @param PHPExcel_Worksheet $pWorksheet
  40. * @param int &$chartRef Chart ID
  41. * @param boolean $includeCharts Flag indicating if we should include drawing details for charts
  42. * @return string XML Output
  43. * @throws PHPExcel_Writer_Exception
  44. */
  45. public function writeDrawings(PHPExcel_Worksheet $pWorksheet = null, &$chartRef, $includeCharts = FALSE)
  46. {
  47. // Create XML writer
  48. $objWriter = null;
  49. if ($this->getParentWriter()->getUseDiskCaching()) {
  50. $objWriter = new PHPExcel_Shared_XMLWriter(PHPExcel_Shared_XMLWriter::STORAGE_DISK, $this->getParentWriter()->getDiskCachingDirectory());
  51. } else {
  52. $objWriter = new PHPExcel_Shared_XMLWriter(PHPExcel_Shared_XMLWriter::STORAGE_MEMORY);
  53. }
  54. // XML header
  55. $objWriter->startDocument('1.0','UTF-8','yes');
  56. // xdr:wsDr
  57. $objWriter->startElement('xdr:wsDr');
  58. $objWriter->writeAttribute('xmlns:xdr', 'http://schemas.openxmlformats.org/drawingml/2006/spreadsheetDrawing');
  59. $objWriter->writeAttribute('xmlns:a', 'http://schemas.openxmlformats.org/drawingml/2006/main');
  60. // Loop through images and write drawings
  61. $i = 1;
  62. $iterator = $pWorksheet->getDrawingCollection()->getIterator();
  63. while ($iterator->valid()) {
  64. $this->_writeDrawing($objWriter, $iterator->current(), $i);
  65. $iterator->next();
  66. ++$i;
  67. }
  68. if ($includeCharts) {
  69. $chartCount = $pWorksheet->getChartCount();
  70. // Loop through charts and write the chart position
  71. if ($chartCount > 0) {
  72. for ($c = 0; $c < $chartCount; ++$c) {
  73. $this->_writeChart($objWriter, $pWorksheet->getChartByIndex($c), $c+$i);
  74. }
  75. }
  76. }
  77. $objWriter->endElement();
  78. // Return
  79. return $objWriter->getData();
  80. }
  81. /**
  82. * Write drawings to XML format
  83. *
  84. * @param PHPExcel_Shared_XMLWriter $objWriter XML Writer
  85. * @param PHPExcel_Chart $pChart
  86. * @param int $pRelationId
  87. * @throws PHPExcel_Writer_Exception
  88. */
  89. public function _writeChart(PHPExcel_Shared_XMLWriter $objWriter = null, PHPExcel_Chart $pChart = null, $pRelationId = -1)
  90. {
  91. $tl = $pChart->getTopLeftPosition();
  92. $tl['colRow'] = PHPExcel_Cell::coordinateFromString($tl['cell']);
  93. $br = $pChart->getBottomRightPosition();
  94. $br['colRow'] = PHPExcel_Cell::coordinateFromString($br['cell']);
  95. $objWriter->startElement('xdr:twoCellAnchor');
  96. $objWriter->startElement('xdr:from');
  97. $objWriter->writeElement('xdr:col', PHPExcel_Cell::columnIndexFromString($tl['colRow'][0]) - 1);
  98. $objWriter->writeElement('xdr:colOff', PHPExcel_Shared_Drawing::pixelsToEMU($tl['xOffset']));
  99. $objWriter->writeElement('xdr:row', $tl['colRow'][1] - 1);
  100. $objWriter->writeElement('xdr:rowOff', PHPExcel_Shared_Drawing::pixelsToEMU($tl['yOffset']));
  101. $objWriter->endElement();
  102. $objWriter->startElement('xdr:to');
  103. $objWriter->writeElement('xdr:col', PHPExcel_Cell::columnIndexFromString($br['colRow'][0]) - 1);
  104. $objWriter->writeElement('xdr:colOff', PHPExcel_Shared_Drawing::pixelsToEMU($br['xOffset']));
  105. $objWriter->writeElement('xdr:row', $br['colRow'][1] - 1);
  106. $objWriter->writeElement('xdr:rowOff', PHPExcel_Shared_Drawing::pixelsToEMU($br['yOffset']));
  107. $objWriter->endElement();
  108. $objWriter->startElement('xdr:graphicFrame');
  109. $objWriter->writeAttribute('macro', '');
  110. $objWriter->startElement('xdr:nvGraphicFramePr');
  111. $objWriter->startElement('xdr:cNvPr');
  112. $objWriter->writeAttribute('name', 'Chart '.$pRelationId);
  113. $objWriter->writeAttribute('id', 1025 * $pRelationId);
  114. $objWriter->endElement();
  115. $objWriter->startElement('xdr:cNvGraphicFramePr');
  116. $objWriter->startElement('a:graphicFrameLocks');
  117. $objWriter->endElement();
  118. $objWriter->endElement();
  119. $objWriter->endElement();
  120. $objWriter->startElement('xdr:xfrm');
  121. $objWriter->startElement('a:off');
  122. $objWriter->writeAttribute('x', '0');
  123. $objWriter->writeAttribute('y', '0');
  124. $objWriter->endElement();
  125. $objWriter->startElement('a:ext');
  126. $objWriter->writeAttribute('cx', '0');
  127. $objWriter->writeAttribute('cy', '0');
  128. $objWriter->endElement();
  129. $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();
  141. $objWriter->startElement('xdr:clientData');
  142. $objWriter->endElement();
  143. $objWriter->endElement();
  144. }
  145. /**
  146. * Write drawings to XML format
  147. *
  148. * @param PHPExcel_Shared_XMLWriter $objWriter XML Writer
  149. * @param PHPExcel_Worksheet_BaseDrawing $pDrawing
  150. * @param int $pRelationId
  151. * @throws PHPExcel_Writer_Exception
  152. */
  153. public function _writeDrawing(PHPExcel_Shared_XMLWriter $objWriter = null, PHPExcel_Worksheet_BaseDrawing $pDrawing = null, $pRelationId = -1)
  154. {
  155. if ($pRelationId >= 0) {
  156. // xdr:oneCellAnchor
  157. $objWriter->startElement('xdr:oneCellAnchor');
  158. // Image location
  159. $aCoordinates = PHPExcel_Cell::coordinateFromString($pDrawing->getCoordinates());
  160. $aCoordinates[0] = PHPExcel_Cell::columnIndexFromString($aCoordinates[0]);
  161. // xdr:from
  162. $objWriter->startElement('xdr:from');
  163. $objWriter->writeElement('xdr:col', $aCoordinates[0] - 1);
  164. $objWriter->writeElement('xdr:colOff', PHPExcel_Shared_Drawing::pixelsToEMU($pDrawing->getOffsetX()));
  165. $objWriter->writeElement('xdr:row', $aCoordinates[1] - 1);
  166. $objWriter->writeElement('xdr:rowOff', PHPExcel_Shared_Drawing::pixelsToEMU($pDrawing->getOffsetY()));
  167. $objWriter->endElement();
  168. // xdr:ext
  169. $objWriter->startElement('xdr:ext');
  170. $objWriter->writeAttribute('cx', PHPExcel_Shared_Drawing::pixelsToEMU($pDrawing->getWidth()));
  171. $objWriter->writeAttribute('cy', PHPExcel_Shared_Drawing::pixelsToEMU($pDrawing->getHeight()));
  172. $objWriter->endElement();
  173. // xdr:pic
  174. $objWriter->startElement('xdr:pic');
  175. // xdr:nvPicPr
  176. $objWriter->startElement('xdr:nvPicPr');
  177. // xdr:cNvPr
  178. $objWriter->startElement('xdr:cNvPr');
  179. $objWriter->writeAttribute('id', $pRelationId);
  180. $objWriter->writeAttribute('name', $pDrawing->getName());
  181. $objWriter->writeAttribute('descr', $pDrawing->getDescription());
  182. $objWriter->endElement();
  183. // xdr:cNvPicPr
  184. $objWriter->startElement('xdr:cNvPicPr');
  185. // a:picLocks
  186. $objWriter->startElement('a:picLocks');
  187. $objWriter->writeAttribute('noChangeAspect', '1');
  188. $objWriter->endElement();
  189. $objWriter->endElement();
  190. $objWriter->endElement();
  191. // xdr:blipFill
  192. $objWriter->startElement('xdr:blipFill');
  193. // a:blip
  194. $objWriter->startElement('a:blip');
  195. $objWriter->writeAttribute('xmlns:r', 'http://schemas.openxmlformats.org/officeDocument/2006/relationships');
  196. $objWriter->writeAttribute('r:embed', 'rId' . $pRelationId);
  197. $objWriter->endElement();
  198. // a:stretch
  199. $objWriter->startElement('a:stretch');
  200. $objWriter->writeElement('a:fillRect', null);
  201. $objWriter->endElement();
  202. $objWriter->endElement();
  203. // xdr:spPr
  204. $objWriter->startElement('xdr:spPr');
  205. // a:xfrm
  206. $objWriter->startElement('a:xfrm');
  207. $objWriter->writeAttribute('rot', PHPExcel_Shared_Drawing::degreesToAngle($pDrawing->getRotation()));
  208. $objWriter->endElement();
  209. // a:prstGeom
  210. $objWriter->startElement('a:prstGeom');
  211. $objWriter->writeAttribute('prst', 'rect');
  212. // a:avLst
  213. $objWriter->writeElement('a:avLst', null);
  214. $objWriter->endElement();
  215. // // a:solidFill
  216. // $objWriter->startElement('a:solidFill');
  217. // // a:srgbClr
  218. // $objWriter->startElement('a:srgbClr');
  219. // $objWriter->writeAttribute('val', 'FFFFFF');
  220. ///* SHADE
  221. // // a:shade
  222. // $objWriter->startElement('a:shade');
  223. // $objWriter->writeAttribute('val', '85000');
  224. // $objWriter->endElement();
  225. //*/
  226. // $objWriter->endElement();
  227. // $objWriter->endElement();
  228. /*
  229. // a:ln
  230. $objWriter->startElement('a:ln');
  231. $objWriter->writeAttribute('w', '88900');
  232. $objWriter->writeAttribute('cap', 'sq');
  233. // a:solidFill
  234. $objWriter->startElement('a:solidFill');
  235. // a:srgbClr
  236. $objWriter->startElement('a:srgbClr');
  237. $objWriter->writeAttribute('val', 'FFFFFF');
  238. $objWriter->endElement();
  239. $objWriter->endElement();
  240. // a:miter
  241. $objWriter->startElement('a:miter');
  242. $objWriter->writeAttribute('lim', '800000');
  243. $objWriter->endElement();
  244. $objWriter->endElement();
  245. */
  246. if ($pDrawing->getShadow()->getVisible()) {
  247. // a:effectLst
  248. $objWriter->startElement('a:effectLst');
  249. // a:outerShdw
  250. $objWriter->startElement('a:outerShdw');
  251. $objWriter->writeAttribute('blurRad', PHPExcel_Shared_Drawing::pixelsToEMU($pDrawing->getShadow()->getBlurRadius()));
  252. $objWriter->writeAttribute('dist', PHPExcel_Shared_Drawing::pixelsToEMU($pDrawing->getShadow()->getDistance()));
  253. $objWriter->writeAttribute('dir', PHPExcel_Shared_Drawing::degreesToAngle($pDrawing->getShadow()->getDirection()));
  254. $objWriter->writeAttribute('algn', $pDrawing->getShadow()->getAlignment());
  255. $objWriter->writeAttribute('rotWithShape', '0');
  256. // a:srgbClr
  257. $objWriter->startElement('a:srgbClr');
  258. $objWriter->writeAttribute('val', $pDrawing->getShadow()->getColor()->getRGB());
  259. // a:alpha
  260. $objWriter->startElement('a:alpha');
  261. $objWriter->writeAttribute('val', $pDrawing->getShadow()->getAlpha() * 1000);
  262. $objWriter->endElement();
  263. $objWriter->endElement();
  264. $objWriter->endElement();
  265. $objWriter->endElement();
  266. }
  267. /*
  268. // a:scene3d
  269. $objWriter->startElement('a:scene3d');
  270. // a:camera
  271. $objWriter->startElement('a:camera');
  272. $objWriter->writeAttribute('prst', 'orthographicFront');
  273. $objWriter->endElement();
  274. // a:lightRig
  275. $objWriter->startElement('a:lightRig');
  276. $objWriter->writeAttribute('rig', 'twoPt');
  277. $objWriter->writeAttribute('dir', 't');
  278. // a:rot
  279. $objWriter->startElement('a:rot');
  280. $objWriter->writeAttribute('lat', '0');
  281. $objWriter->writeAttribute('lon', '0');
  282. $objWriter->writeAttribute('rev', '0');
  283. $objWriter->endElement();
  284. $objWriter->endElement();
  285. $objWriter->endElement();
  286. */
  287. /*
  288. // a:sp3d
  289. $objWriter->startElement('a:sp3d');
  290. // a:bevelT
  291. $objWriter->startElement('a:bevelT');
  292. $objWriter->writeAttribute('w', '25400');
  293. $objWriter->writeAttribute('h', '19050');
  294. $objWriter->endElement();
  295. // a:contourClr
  296. $objWriter->startElement('a:contourClr');
  297. // a:srgbClr
  298. $objWriter->startElement('a:srgbClr');
  299. $objWriter->writeAttribute('val', 'FFFFFF');
  300. $objWriter->endElement();
  301. $objWriter->endElement();
  302. $objWriter->endElement();
  303. */
  304. $objWriter->endElement();
  305. $objWriter->endElement();
  306. // xdr:clientData
  307. $objWriter->writeElement('xdr:clientData', null);
  308. $objWriter->endElement();
  309. } else {
  310. throw new PHPExcel_Writer_Exception("Invalid parameters passed.");
  311. }
  312. }
  313. /**
  314. * Write VML header/footer images to XML format
  315. *
  316. * @param PHPExcel_Worksheet $pWorksheet
  317. * @return string XML Output
  318. * @throws PHPExcel_Writer_Exception
  319. */
  320. public function writeVMLHeaderFooterImages(PHPExcel_Worksheet $pWorksheet = null)
  321. {
  322. // Create XML writer
  323. $objWriter = null;
  324. if ($this->getParentWriter()->getUseDiskCaching()) {
  325. $objWriter = new PHPExcel_Shared_XMLWriter(PHPExcel_Shared_XMLWriter::STORAGE_DISK, $this->getParentWriter()->getDiskCachingDirectory());
  326. } else {
  327. $objWriter = new PHPExcel_Shared_XMLWriter(PHPExcel_Shared_XMLWriter::STORAGE_MEMORY);
  328. }
  329. // XML header
  330. $objWriter->startDocument('1.0','UTF-8','yes');
  331. // Header/footer images
  332. $images = $pWorksheet->getHeaderFooter()->getImages();
  333. // xml
  334. $objWriter->startElement('xml');
  335. $objWriter->writeAttribute('xmlns:v', 'urn:schemas-microsoft-com:vml');
  336. $objWriter->writeAttribute('xmlns:o', 'urn:schemas-microsoft-com:office:office');
  337. $objWriter->writeAttribute('xmlns:x', 'urn:schemas-microsoft-com:office:excel');
  338. // o:shapelayout
  339. $objWriter->startElement('o:shapelayout');
  340. $objWriter->writeAttribute('v:ext', 'edit');
  341. // o:idmap
  342. $objWriter->startElement('o:idmap');
  343. $objWriter->writeAttribute('v:ext', 'edit');
  344. $objWriter->writeAttribute('data', '1');
  345. $objWriter->endElement();
  346. $objWriter->endElement();
  347. // v:shapetype
  348. $objWriter->startElement('v:shapetype');
  349. $objWriter->writeAttribute('id', '_x0000_t75');
  350. $objWriter->writeAttribute('coordsize', '21600,21600');
  351. $objWriter->writeAttribute('o:spt', '75');
  352. $objWriter->writeAttribute('o:preferrelative', 't');
  353. $objWriter->writeAttribute('path', 'm@4@5l@4@11@9@11@9@5xe');
  354. $objWriter->writeAttribute('filled', 'f');
  355. $objWriter->writeAttribute('stroked', 'f');
  356. // v:stroke
  357. $objWriter->startElement('v:stroke');
  358. $objWriter->writeAttribute('joinstyle', 'miter');
  359. $objWriter->endElement();
  360. // v:formulas
  361. $objWriter->startElement('v:formulas');
  362. // v:f
  363. $objWriter->startElement('v:f');
  364. $objWriter->writeAttribute('eqn', 'if lineDrawn pixelLineWidth 0');
  365. $objWriter->endElement();
  366. // v:f
  367. $objWriter->startElement('v:f');
  368. $objWriter->writeAttribute('eqn', 'sum @0 1 0');
  369. $objWriter->endElement();
  370. // v:f
  371. $objWriter->startElement('v:f');
  372. $objWriter->writeAttribute('eqn', 'sum 0 0 @1');
  373. $objWriter->endElement();
  374. // v:f
  375. $objWriter->startElement('v:f');
  376. $objWriter->writeAttribute('eqn', 'prod @2 1 2');
  377. $objWriter->endElement();
  378. // v:f
  379. $objWriter->startElement('v:f');
  380. $objWriter->writeAttribute('eqn', 'prod @3 21600 pixelWidth');
  381. $objWriter->endElement();
  382. // v:f
  383. $objWriter->startElement('v:f');
  384. $objWriter->writeAttribute('eqn', 'prod @3 21600 pixelHeight');
  385. $objWriter->endElement();
  386. // v:f
  387. $objWriter->startElement('v:f');
  388. $objWriter->writeAttribute('eqn', 'sum @0 0 1');
  389. $objWriter->endElement();
  390. // v:f
  391. $objWriter->startElement('v:f');
  392. $objWriter->writeAttribute('eqn', 'prod @6 1 2');
  393. $objWriter->endElement();
  394. // v:f
  395. $objWriter->startElement('v:f');
  396. $objWriter->writeAttribute('eqn', 'prod @7 21600 pixelWidth');
  397. $objWriter->endElement();
  398. // v:f
  399. $objWriter->startElement('v:f');
  400. $objWriter->writeAttribute('eqn', 'sum @8 21600 0');
  401. $objWriter->endElement();
  402. // v:f
  403. $objWriter->startElement('v:f');
  404. $objWriter->writeAttribute('eqn', 'prod @7 21600 pixelHeight');
  405. $objWriter->endElement();
  406. // v:f
  407. $objWriter->startElement('v:f');
  408. $objWriter->writeAttribute('eqn', 'sum @10 21600 0');
  409. $objWriter->endElement();
  410. $objWriter->endElement();
  411. // v:path
  412. $objWriter->startElement('v:path');
  413. $objWriter->writeAttribute('o:extrusionok', 'f');
  414. $objWriter->writeAttribute('gradientshapeok', 't');
  415. $objWriter->writeAttribute('o:connecttype', 'rect');
  416. $objWriter->endElement();
  417. // o:lock
  418. $objWriter->startElement('o:lock');
  419. $objWriter->writeAttribute('v:ext', 'edit');
  420. $objWriter->writeAttribute('aspectratio', 't');
  421. $objWriter->endElement();
  422. $objWriter->endElement();
  423. // Loop through images
  424. foreach ($images as $key => $value) {
  425. $this->_writeVMLHeaderFooterImage($objWriter, $key, $value);
  426. }
  427. $objWriter->endElement();
  428. // Return
  429. return $objWriter->getData();
  430. }
  431. /**
  432. * Write VML comment to XML format
  433. *
  434. * @param PHPExcel_Shared_XMLWriter $objWriter XML Writer
  435. * @param string $pReference Reference
  436. * @param PHPExcel_Worksheet_HeaderFooterDrawing $pImage Image
  437. * @throws PHPExcel_Writer_Exception
  438. */
  439. public function _writeVMLHeaderFooterImage(PHPExcel_Shared_XMLWriter $objWriter = null, $pReference = '', PHPExcel_Worksheet_HeaderFooterDrawing $pImage = null)
  440. {
  441. // Calculate object id
  442. preg_match('{(\d+)}', md5($pReference), $m);
  443. $id = 1500 + (substr($m[1], 0, 2) * 1);
  444. // Calculate offset
  445. $width = $pImage->getWidth();
  446. $height = $pImage->getHeight();
  447. $marginLeft = $pImage->getOffsetX();
  448. $marginTop = $pImage->getOffsetY();
  449. // v:shape
  450. $objWriter->startElement('v:shape');
  451. $objWriter->writeAttribute('id', $pReference);
  452. $objWriter->writeAttribute('o:spid', '_x0000_s' . $id);
  453. $objWriter->writeAttribute('type', '#_x0000_t75');
  454. $objWriter->writeAttribute('style', "position:absolute;margin-left:{$marginLeft}px;margin-top:{$marginTop}px;width:{$width}px;height:{$height}px;z-index:1");
  455. // v:imagedata
  456. $objWriter->startElement('v:imagedata');
  457. $objWriter->writeAttribute('o:relid', 'rId' . $pReference);
  458. $objWriter->writeAttribute('o:title', $pImage->getName());
  459. $objWriter->endElement();
  460. // o:lock
  461. $objWriter->startElement('o:lock');
  462. $objWriter->writeAttribute('v:ext', 'edit');
  463. $objWriter->writeAttribute('rotation', 't');
  464. $objWriter->endElement();
  465. $objWriter->endElement();
  466. }
  467. /**
  468. * Get an array of all drawings
  469. *
  470. * @param PHPExcel $pPHPExcel
  471. * @return PHPExcel_Worksheet_Drawing[] All drawings in PHPExcel
  472. * @throws PHPExcel_Writer_Exception
  473. */
  474. public function allDrawings(PHPExcel $pPHPExcel = null)
  475. {
  476. // Get an array of all drawings
  477. $aDrawings = array();
  478. // Loop through PHPExcel
  479. $sheetCount = $pPHPExcel->getSheetCount();
  480. for ($i = 0; $i < $sheetCount; ++$i) {
  481. // Loop through images and add to array
  482. $iterator = $pPHPExcel->getSheet($i)->getDrawingCollection()->getIterator();
  483. while ($iterator->valid()) {
  484. $aDrawings[] = $iterator->current();
  485. $iterator->next();
  486. }
  487. }
  488. return $aDrawings;
  489. }
  490. }