PageRenderTime 71ms CodeModel.GetById 29ms RepoModel.GetById 0ms app.codeStats 1ms

/lib/phpexcel/PHPExcel/Writer/HTML.php

https://bitbucket.org/moodle/moodle
PHP | 1596 lines | 919 code | 210 blank | 467 comment | 180 complexity | 1846b2be407156d30848a48ef6c5134d MD5 | raw file
Possible License(s): Apache-2.0, LGPL-2.1, BSD-3-Clause, MIT, GPL-3.0

Large files files are truncated, but you can click here to view the full file

  1. <?php
  2. /**
  3. * PHPExcel_Writer_HTML
  4. *
  5. * Copyright (c) 2006 - 2015 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_HTML
  23. * @copyright Copyright (c) 2006 - 2015 PHPExcel (http://www.codeplex.com/PHPExcel)
  24. * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
  25. * @version ##VERSION##, ##DATE##
  26. */
  27. class PHPExcel_Writer_HTML extends PHPExcel_Writer_Abstract implements PHPExcel_Writer_IWriter
  28. {
  29. /**
  30. * PHPExcel object
  31. *
  32. * @var PHPExcel
  33. */
  34. protected $phpExcel;
  35. /**
  36. * Sheet index to write
  37. *
  38. * @var int
  39. */
  40. private $sheetIndex = 0;
  41. /**
  42. * Images root
  43. *
  44. * @var string
  45. */
  46. private $imagesRoot = '.';
  47. /**
  48. * embed images, or link to images
  49. *
  50. * @var boolean
  51. */
  52. private $embedImages = false;
  53. /**
  54. * Use inline CSS?
  55. *
  56. * @var boolean
  57. */
  58. private $useInlineCss = false;
  59. /**
  60. * Array of CSS styles
  61. *
  62. * @var array
  63. */
  64. private $cssStyles;
  65. /**
  66. * Array of column widths in points
  67. *
  68. * @var array
  69. */
  70. private $columnWidths;
  71. /**
  72. * Default font
  73. *
  74. * @var PHPExcel_Style_Font
  75. */
  76. private $defaultFont;
  77. /**
  78. * Flag whether spans have been calculated
  79. *
  80. * @var boolean
  81. */
  82. private $spansAreCalculated = false;
  83. /**
  84. * Excel cells that should not be written as HTML cells
  85. *
  86. * @var array
  87. */
  88. private $isSpannedCell = array();
  89. /**
  90. * Excel cells that are upper-left corner in a cell merge
  91. *
  92. * @var array
  93. */
  94. private $isBaseCell = array();
  95. /**
  96. * Excel rows that should not be written as HTML rows
  97. *
  98. * @var array
  99. */
  100. private $isSpannedRow = array();
  101. /**
  102. * Is the current writer creating PDF?
  103. *
  104. * @var boolean
  105. */
  106. protected $isPdf = false;
  107. /**
  108. * Generate the Navigation block
  109. *
  110. * @var boolean
  111. */
  112. private $generateSheetNavigationBlock = true;
  113. /**
  114. * Create a new PHPExcel_Writer_HTML
  115. *
  116. * @param PHPExcel $phpExcel PHPExcel object
  117. */
  118. public function __construct(PHPExcel $phpExcel)
  119. {
  120. $this->phpExcel = $phpExcel;
  121. $this->defaultFont = $this->phpExcel->getDefaultStyle()->getFont();
  122. }
  123. /**
  124. * Save PHPExcel to file
  125. *
  126. * @param string $pFilename
  127. * @throws PHPExcel_Writer_Exception
  128. */
  129. public function save($pFilename = null)
  130. {
  131. // garbage collect
  132. $this->phpExcel->garbageCollect();
  133. $saveDebugLog = PHPExcel_Calculation::getInstance($this->phpExcel)->getDebugLog()->getWriteDebugLog();
  134. PHPExcel_Calculation::getInstance($this->phpExcel)->getDebugLog()->setWriteDebugLog(false);
  135. $saveArrayReturnType = PHPExcel_Calculation::getArrayReturnType();
  136. PHPExcel_Calculation::setArrayReturnType(PHPExcel_Calculation::RETURN_ARRAY_AS_VALUE);
  137. // Build CSS
  138. $this->buildCSS(!$this->useInlineCss);
  139. // Open file
  140. $fileHandle = fopen($pFilename, 'wb+');
  141. if ($fileHandle === false) {
  142. throw new PHPExcel_Writer_Exception("Could not open file $pFilename for writing.");
  143. }
  144. // Write headers
  145. fwrite($fileHandle, $this->generateHTMLHeader(!$this->useInlineCss));
  146. // Write navigation (tabs)
  147. if ((!$this->isPdf) && ($this->generateSheetNavigationBlock)) {
  148. fwrite($fileHandle, $this->generateNavigation());
  149. }
  150. // Write data
  151. fwrite($fileHandle, $this->generateSheetData());
  152. // Write footer
  153. fwrite($fileHandle, $this->generateHTMLFooter());
  154. // Close file
  155. fclose($fileHandle);
  156. PHPExcel_Calculation::setArrayReturnType($saveArrayReturnType);
  157. PHPExcel_Calculation::getInstance($this->phpExcel)->getDebugLog()->setWriteDebugLog($saveDebugLog);
  158. }
  159. /**
  160. * Map VAlign
  161. *
  162. * @param string $vAlign Vertical alignment
  163. * @return string
  164. */
  165. private function mapVAlign($vAlign)
  166. {
  167. switch ($vAlign) {
  168. case PHPExcel_Style_Alignment::VERTICAL_BOTTOM:
  169. return 'bottom';
  170. case PHPExcel_Style_Alignment::VERTICAL_TOP:
  171. return 'top';
  172. case PHPExcel_Style_Alignment::VERTICAL_CENTER:
  173. case PHPExcel_Style_Alignment::VERTICAL_JUSTIFY:
  174. return 'middle';
  175. default:
  176. return 'baseline';
  177. }
  178. }
  179. /**
  180. * Map HAlign
  181. *
  182. * @param string $hAlign Horizontal alignment
  183. * @return string|false
  184. */
  185. private function mapHAlign($hAlign)
  186. {
  187. switch ($hAlign) {
  188. case PHPExcel_Style_Alignment::HORIZONTAL_GENERAL:
  189. return false;
  190. case PHPExcel_Style_Alignment::HORIZONTAL_LEFT:
  191. return 'left';
  192. case PHPExcel_Style_Alignment::HORIZONTAL_RIGHT:
  193. return 'right';
  194. case PHPExcel_Style_Alignment::HORIZONTAL_CENTER:
  195. case PHPExcel_Style_Alignment::HORIZONTAL_CENTER_CONTINUOUS:
  196. return 'center';
  197. case PHPExcel_Style_Alignment::HORIZONTAL_JUSTIFY:
  198. return 'justify';
  199. default:
  200. return false;
  201. }
  202. }
  203. /**
  204. * Map border style
  205. *
  206. * @param int $borderStyle Sheet index
  207. * @return string
  208. */
  209. private function mapBorderStyle($borderStyle)
  210. {
  211. switch ($borderStyle) {
  212. case PHPExcel_Style_Border::BORDER_NONE:
  213. return 'none';
  214. case PHPExcel_Style_Border::BORDER_DASHDOT:
  215. return '1px dashed';
  216. case PHPExcel_Style_Border::BORDER_DASHDOTDOT:
  217. return '1px dotted';
  218. case PHPExcel_Style_Border::BORDER_DASHED:
  219. return '1px dashed';
  220. case PHPExcel_Style_Border::BORDER_DOTTED:
  221. return '1px dotted';
  222. case PHPExcel_Style_Border::BORDER_DOUBLE:
  223. return '3px double';
  224. case PHPExcel_Style_Border::BORDER_HAIR:
  225. return '1px solid';
  226. case PHPExcel_Style_Border::BORDER_MEDIUM:
  227. return '2px solid';
  228. case PHPExcel_Style_Border::BORDER_MEDIUMDASHDOT:
  229. return '2px dashed';
  230. case PHPExcel_Style_Border::BORDER_MEDIUMDASHDOTDOT:
  231. return '2px dotted';
  232. case PHPExcel_Style_Border::BORDER_MEDIUMDASHED:
  233. return '2px dashed';
  234. case PHPExcel_Style_Border::BORDER_SLANTDASHDOT:
  235. return '2px dashed';
  236. case PHPExcel_Style_Border::BORDER_THICK:
  237. return '3px solid';
  238. case PHPExcel_Style_Border::BORDER_THIN:
  239. return '1px solid';
  240. default:
  241. // map others to thin
  242. return '1px solid';
  243. }
  244. }
  245. /**
  246. * Get sheet index
  247. *
  248. * @return int
  249. */
  250. public function getSheetIndex()
  251. {
  252. return $this->sheetIndex;
  253. }
  254. /**
  255. * Set sheet index
  256. *
  257. * @param int $pValue Sheet index
  258. * @return PHPExcel_Writer_HTML
  259. */
  260. public function setSheetIndex($pValue = 0)
  261. {
  262. $this->sheetIndex = $pValue;
  263. return $this;
  264. }
  265. /**
  266. * Get sheet index
  267. *
  268. * @return boolean
  269. */
  270. public function getGenerateSheetNavigationBlock()
  271. {
  272. return $this->generateSheetNavigationBlock;
  273. }
  274. /**
  275. * Set sheet index
  276. *
  277. * @param boolean $pValue Flag indicating whether the sheet navigation block should be generated or not
  278. * @return PHPExcel_Writer_HTML
  279. */
  280. public function setGenerateSheetNavigationBlock($pValue = true)
  281. {
  282. $this->generateSheetNavigationBlock = (bool) $pValue;
  283. return $this;
  284. }
  285. /**
  286. * Write all sheets (resets sheetIndex to NULL)
  287. */
  288. public function writeAllSheets()
  289. {
  290. $this->sheetIndex = null;
  291. return $this;
  292. }
  293. /**
  294. * Generate HTML header
  295. *
  296. * @param boolean $pIncludeStyles Include styles?
  297. * @return string
  298. * @throws PHPExcel_Writer_Exception
  299. */
  300. public function generateHTMLHeader($pIncludeStyles = false)
  301. {
  302. // PHPExcel object known?
  303. if (is_null($this->phpExcel)) {
  304. throw new PHPExcel_Writer_Exception('Internal PHPExcel object not set to an instance of an object.');
  305. }
  306. // Construct HTML
  307. $properties = $this->phpExcel->getProperties();
  308. $html = '<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">' . PHP_EOL;
  309. $html .= '<!-- Generated by PHPExcel - http://www.phpexcel.net -->' . PHP_EOL;
  310. $html .= '<html>' . PHP_EOL;
  311. $html .= ' <head>' . PHP_EOL;
  312. $html .= ' <meta http-equiv="Content-Type" content="text/html; charset=utf-8">' . PHP_EOL;
  313. if ($properties->getTitle() > '') {
  314. $html .= ' <title>' . htmlspecialchars($properties->getTitle()) . '</title>' . PHP_EOL;
  315. }
  316. if ($properties->getCreator() > '') {
  317. $html .= ' <meta name="author" content="' . htmlspecialchars($properties->getCreator()) . '" />' . PHP_EOL;
  318. }
  319. if ($properties->getTitle() > '') {
  320. $html .= ' <meta name="title" content="' . htmlspecialchars($properties->getTitle()) . '" />' . PHP_EOL;
  321. }
  322. if ($properties->getDescription() > '') {
  323. $html .= ' <meta name="description" content="' . htmlspecialchars($properties->getDescription()) . '" />' . PHP_EOL;
  324. }
  325. if ($properties->getSubject() > '') {
  326. $html .= ' <meta name="subject" content="' . htmlspecialchars($properties->getSubject()) . '" />' . PHP_EOL;
  327. }
  328. if ($properties->getKeywords() > '') {
  329. $html .= ' <meta name="keywords" content="' . htmlspecialchars($properties->getKeywords()) . '" />' . PHP_EOL;
  330. }
  331. if ($properties->getCategory() > '') {
  332. $html .= ' <meta name="category" content="' . htmlspecialchars($properties->getCategory()) . '" />' . PHP_EOL;
  333. }
  334. if ($properties->getCompany() > '') {
  335. $html .= ' <meta name="company" content="' . htmlspecialchars($properties->getCompany()) . '" />' . PHP_EOL;
  336. }
  337. if ($properties->getManager() > '') {
  338. $html .= ' <meta name="manager" content="' . htmlspecialchars($properties->getManager()) . '" />' . PHP_EOL;
  339. }
  340. if ($pIncludeStyles) {
  341. $html .= $this->generateStyles(true);
  342. }
  343. $html .= ' </head>' . PHP_EOL;
  344. $html .= '' . PHP_EOL;
  345. $html .= ' <body>' . PHP_EOL;
  346. return $html;
  347. }
  348. /**
  349. * Generate sheet data
  350. *
  351. * @return string
  352. * @throws PHPExcel_Writer_Exception
  353. */
  354. public function generateSheetData()
  355. {
  356. // PHPExcel object known?
  357. if (is_null($this->phpExcel)) {
  358. throw new PHPExcel_Writer_Exception('Internal PHPExcel object not set to an instance of an object.');
  359. }
  360. // Ensure that Spans have been calculated?
  361. if (!$this->spansAreCalculated) {
  362. $this->calculateSpans();
  363. }
  364. // Fetch sheets
  365. $sheets = array();
  366. if (is_null($this->sheetIndex)) {
  367. $sheets = $this->phpExcel->getAllSheets();
  368. } else {
  369. $sheets[] = $this->phpExcel->getSheet($this->sheetIndex);
  370. }
  371. // Construct HTML
  372. $html = '';
  373. // Loop all sheets
  374. $sheetId = 0;
  375. foreach ($sheets as $sheet) {
  376. // Write table header
  377. $html .= $this->generateTableHeader($sheet);
  378. // Get worksheet dimension
  379. $dimension = explode(':', $sheet->calculateWorksheetDimension());
  380. $dimension[0] = PHPExcel_Cell::coordinateFromString($dimension[0]);
  381. $dimension[0][0] = PHPExcel_Cell::columnIndexFromString($dimension[0][0]) - 1;
  382. $dimension[1] = PHPExcel_Cell::coordinateFromString($dimension[1]);
  383. $dimension[1][0] = PHPExcel_Cell::columnIndexFromString($dimension[1][0]) - 1;
  384. // row min,max
  385. $rowMin = $dimension[0][1];
  386. $rowMax = $dimension[1][1];
  387. // calculate start of <tbody>, <thead>
  388. $tbodyStart = $rowMin;
  389. $theadStart = $theadEnd = 0; // default: no <thead> no </thead>
  390. if ($sheet->getPageSetup()->isRowsToRepeatAtTopSet()) {
  391. $rowsToRepeatAtTop = $sheet->getPageSetup()->getRowsToRepeatAtTop();
  392. // we can only support repeating rows that start at top row
  393. if ($rowsToRepeatAtTop[0] == 1) {
  394. $theadStart = $rowsToRepeatAtTop[0];
  395. $theadEnd = $rowsToRepeatAtTop[1];
  396. $tbodyStart = $rowsToRepeatAtTop[1] + 1;
  397. }
  398. }
  399. // Loop through cells
  400. $row = $rowMin-1;
  401. while ($row++ < $rowMax) {
  402. // <thead> ?
  403. if ($row == $theadStart) {
  404. $html .= ' <thead>' . PHP_EOL;
  405. $cellType = 'th';
  406. }
  407. // <tbody> ?
  408. if ($row == $tbodyStart) {
  409. $html .= ' <tbody>' . PHP_EOL;
  410. $cellType = 'td';
  411. }
  412. // Write row if there are HTML table cells in it
  413. if (!isset($this->isSpannedRow[$sheet->getParent()->getIndex($sheet)][$row])) {
  414. // Start a new rowData
  415. $rowData = array();
  416. // Loop through columns
  417. $column = $dimension[0][0] - 1;
  418. while ($column++ < $dimension[1][0]) {
  419. // Cell exists?
  420. if ($sheet->cellExistsByColumnAndRow($column, $row)) {
  421. $rowData[$column] = PHPExcel_Cell::stringFromColumnIndex($column) . $row;
  422. } else {
  423. $rowData[$column] = '';
  424. }
  425. }
  426. $html .= $this->generateRow($sheet, $rowData, $row - 1, $cellType);
  427. }
  428. // </thead> ?
  429. if ($row == $theadEnd) {
  430. $html .= ' </thead>' . PHP_EOL;
  431. }
  432. }
  433. $html .= $this->extendRowsForChartsAndImages($sheet, $row);
  434. // Close table body.
  435. $html .= ' </tbody>' . PHP_EOL;
  436. // Write table footer
  437. $html .= $this->generateTableFooter();
  438. // Writing PDF?
  439. if ($this->isPdf) {
  440. if (is_null($this->sheetIndex) && $sheetId + 1 < $this->phpExcel->getSheetCount()) {
  441. $html .= '<div style="page-break-before:always" />';
  442. }
  443. }
  444. // Next sheet
  445. ++$sheetId;
  446. }
  447. return $html;
  448. }
  449. /**
  450. * Generate sheet tabs
  451. *
  452. * @return string
  453. * @throws PHPExcel_Writer_Exception
  454. */
  455. public function generateNavigation()
  456. {
  457. // PHPExcel object known?
  458. if (is_null($this->phpExcel)) {
  459. throw new PHPExcel_Writer_Exception('Internal PHPExcel object not set to an instance of an object.');
  460. }
  461. // Fetch sheets
  462. $sheets = array();
  463. if (is_null($this->sheetIndex)) {
  464. $sheets = $this->phpExcel->getAllSheets();
  465. } else {
  466. $sheets[] = $this->phpExcel->getSheet($this->sheetIndex);
  467. }
  468. // Construct HTML
  469. $html = '';
  470. // Only if there are more than 1 sheets
  471. if (count($sheets) > 1) {
  472. // Loop all sheets
  473. $sheetId = 0;
  474. $html .= '<ul class="navigation">' . PHP_EOL;
  475. foreach ($sheets as $sheet) {
  476. $html .= ' <li class="sheet' . $sheetId . '"><a href="#sheet' . $sheetId . '">' . $sheet->getTitle() . '</a></li>' . PHP_EOL;
  477. ++$sheetId;
  478. }
  479. $html .= '</ul>' . PHP_EOL;
  480. }
  481. return $html;
  482. }
  483. private function extendRowsForChartsAndImages(PHPExcel_Worksheet $pSheet, $row)
  484. {
  485. $rowMax = $row;
  486. $colMax = 'A';
  487. if ($this->includeCharts) {
  488. foreach ($pSheet->getChartCollection() as $chart) {
  489. if ($chart instanceof PHPExcel_Chart) {
  490. $chartCoordinates = $chart->getTopLeftPosition();
  491. $chartTL = PHPExcel_Cell::coordinateFromString($chartCoordinates['cell']);
  492. $chartCol = PHPExcel_Cell::columnIndexFromString($chartTL[0]);
  493. if ($chartTL[1] > $rowMax) {
  494. $rowMax = $chartTL[1];
  495. if ($chartCol > PHPExcel_Cell::columnIndexFromString($colMax)) {
  496. $colMax = $chartTL[0];
  497. }
  498. }
  499. }
  500. }
  501. }
  502. foreach ($pSheet->getDrawingCollection() as $drawing) {
  503. if ($drawing instanceof PHPExcel_Worksheet_Drawing) {
  504. $imageTL = PHPExcel_Cell::coordinateFromString($drawing->getCoordinates());
  505. $imageCol = PHPExcel_Cell::columnIndexFromString($imageTL[0]);
  506. if ($imageTL[1] > $rowMax) {
  507. $rowMax = $imageTL[1];
  508. if ($imageCol > PHPExcel_Cell::columnIndexFromString($colMax)) {
  509. $colMax = $imageTL[0];
  510. }
  511. }
  512. }
  513. }
  514. $html = '';
  515. $colMax++;
  516. while ($row <= $rowMax) {
  517. $html .= '<tr>';
  518. for ($col = 'A'; $col != $colMax; ++$col) {
  519. $html .= '<td>';
  520. $html .= $this->writeImageInCell($pSheet, $col.$row);
  521. if ($this->includeCharts) {
  522. $html .= $this->writeChartInCell($pSheet, $col.$row);
  523. }
  524. $html .= '</td>';
  525. }
  526. ++$row;
  527. $html .= '</tr>';
  528. }
  529. return $html;
  530. }
  531. /**
  532. * Generate image tag in cell
  533. *
  534. * @param PHPExcel_Worksheet $pSheet PHPExcel_Worksheet
  535. * @param string $coordinates Cell coordinates
  536. * @return string
  537. * @throws PHPExcel_Writer_Exception
  538. */
  539. private function writeImageInCell(PHPExcel_Worksheet $pSheet, $coordinates)
  540. {
  541. // Construct HTML
  542. $html = '';
  543. // Write images
  544. foreach ($pSheet->getDrawingCollection() as $drawing) {
  545. if ($drawing instanceof PHPExcel_Worksheet_Drawing) {
  546. if ($drawing->getCoordinates() == $coordinates) {
  547. $filename = $drawing->getPath();
  548. // Strip off eventual '.'
  549. if (substr($filename, 0, 1) == '.') {
  550. $filename = substr($filename, 1);
  551. }
  552. // Prepend images root
  553. $filename = $this->getImagesRoot() . $filename;
  554. // Strip off eventual '.'
  555. if (substr($filename, 0, 1) == '.' && substr($filename, 0, 2) != './') {
  556. $filename = substr($filename, 1);
  557. }
  558. // Convert UTF8 data to PCDATA
  559. $filename = htmlspecialchars($filename);
  560. $html .= PHP_EOL;
  561. if ((!$this->embedImages) || ($this->isPdf)) {
  562. $imageData = $filename;
  563. } else {
  564. $imageDetails = getimagesize($filename);
  565. if ($fp = fopen($filename, "rb", 0)) {
  566. $picture = fread($fp, filesize($filename));
  567. fclose($fp);
  568. // base64 encode the binary data, then break it
  569. // into chunks according to RFC 2045 semantics
  570. $base64 = chunk_split(base64_encode($picture));
  571. $imageData = 'data:'.$imageDetails['mime'].';base64,' . $base64;
  572. } else {
  573. $imageData = $filename;
  574. }
  575. }
  576. $html .= '<div style="position: relative;">';
  577. $html .= '<img style="position: absolute; z-index: 1; left: ' .
  578. $drawing->getOffsetX() . 'px; top: ' . $drawing->getOffsetY() . 'px; width: ' .
  579. $drawing->getWidth() . 'px; height: ' . $drawing->getHeight() . 'px;" src="' .
  580. $imageData . '" border="0" />';
  581. $html .= '</div>';
  582. }
  583. }
  584. }
  585. return $html;
  586. }
  587. /**
  588. * Generate chart tag in cell
  589. *
  590. * @param PHPExcel_Worksheet $pSheet PHPExcel_Worksheet
  591. * @param string $coordinates Cell coordinates
  592. * @return string
  593. * @throws PHPExcel_Writer_Exception
  594. */
  595. private function writeChartInCell(PHPExcel_Worksheet $pSheet, $coordinates)
  596. {
  597. // Construct HTML
  598. $html = '';
  599. // Write charts
  600. foreach ($pSheet->getChartCollection() as $chart) {
  601. if ($chart instanceof PHPExcel_Chart) {
  602. $chartCoordinates = $chart->getTopLeftPosition();
  603. if ($chartCoordinates['cell'] == $coordinates) {
  604. $chartFileName = PHPExcel_Shared_File::sys_get_temp_dir().'/'.uniqid().'.png';
  605. if (!$chart->render($chartFileName)) {
  606. return;
  607. }
  608. $html .= PHP_EOL;
  609. $imageDetails = getimagesize($chartFileName);
  610. if ($fp = fopen($chartFileName, "rb", 0)) {
  611. $picture = fread($fp, filesize($chartFileName));
  612. fclose($fp);
  613. // base64 encode the binary data, then break it
  614. // into chunks according to RFC 2045 semantics
  615. $base64 = chunk_split(base64_encode($picture));
  616. $imageData = 'data:'.$imageDetails['mime'].';base64,' . $base64;
  617. $html .= '<div style="position: relative;">';
  618. $html .= '<img style="position: absolute; z-index: 1; left: ' . $chartCoordinates['xOffset'] . 'px; top: ' . $chartCoordinates['yOffset'] . 'px; width: ' . $imageDetails[0] . 'px; height: ' . $imageDetails[1] . 'px;" src="' . $imageData . '" border="0" />' . PHP_EOL;
  619. $html .= '</div>';
  620. unlink($chartFileName);
  621. }
  622. }
  623. }
  624. }
  625. // Return
  626. return $html;
  627. }
  628. /**
  629. * Generate CSS styles
  630. *
  631. * @param boolean $generateSurroundingHTML Generate surrounding HTML tags? (&lt;style&gt; and &lt;/style&gt;)
  632. * @return string
  633. * @throws PHPExcel_Writer_Exception
  634. */
  635. public function generateStyles($generateSurroundingHTML = true)
  636. {
  637. // PHPExcel object known?
  638. if (is_null($this->phpExcel)) {
  639. throw new PHPExcel_Writer_Exception('Internal PHPExcel object not set to an instance of an object.');
  640. }
  641. // Build CSS
  642. $css = $this->buildCSS($generateSurroundingHTML);
  643. // Construct HTML
  644. $html = '';
  645. // Start styles
  646. if ($generateSurroundingHTML) {
  647. $html .= ' <style type="text/css">' . PHP_EOL;
  648. $html .= ' html { ' . $this->assembleCSS($css['html']) . ' }' . PHP_EOL;
  649. }
  650. // Write all other styles
  651. foreach ($css as $styleName => $styleDefinition) {
  652. if ($styleName != 'html') {
  653. $html .= ' ' . $styleName . ' { ' . $this->assembleCSS($styleDefinition) . ' }' . PHP_EOL;
  654. }
  655. }
  656. // End styles
  657. if ($generateSurroundingHTML) {
  658. $html .= ' </style>' . PHP_EOL;
  659. }
  660. // Return
  661. return $html;
  662. }
  663. /**
  664. * Build CSS styles
  665. *
  666. * @param boolean $generateSurroundingHTML Generate surrounding HTML style? (html { })
  667. * @return array
  668. * @throws PHPExcel_Writer_Exception
  669. */
  670. public function buildCSS($generateSurroundingHTML = true)
  671. {
  672. // PHPExcel object known?
  673. if (is_null($this->phpExcel)) {
  674. throw new PHPExcel_Writer_Exception('Internal PHPExcel object not set to an instance of an object.');
  675. }
  676. // Cached?
  677. if (!is_null($this->cssStyles)) {
  678. return $this->cssStyles;
  679. }
  680. // Ensure that spans have been calculated
  681. if (!$this->spansAreCalculated) {
  682. $this->calculateSpans();
  683. }
  684. // Construct CSS
  685. $css = array();
  686. // Start styles
  687. if ($generateSurroundingHTML) {
  688. // html { }
  689. $css['html']['font-family'] = 'Calibri, Arial, Helvetica, sans-serif';
  690. $css['html']['font-size'] = '11pt';
  691. $css['html']['background-color'] = 'white';
  692. }
  693. // table { }
  694. $css['table']['border-collapse'] = 'collapse';
  695. if (!$this->isPdf) {
  696. $css['table']['page-break-after'] = 'always';
  697. }
  698. // .gridlines td { }
  699. $css['.gridlines td']['border'] = '1px dotted black';
  700. $css['.gridlines th']['border'] = '1px dotted black';
  701. // .b {}
  702. $css['.b']['text-align'] = 'center'; // BOOL
  703. // .e {}
  704. $css['.e']['text-align'] = 'center'; // ERROR
  705. // .f {}
  706. $css['.f']['text-align'] = 'right'; // FORMULA
  707. // .inlineStr {}
  708. $css['.inlineStr']['text-align'] = 'left'; // INLINE
  709. // .n {}
  710. $css['.n']['text-align'] = 'right'; // NUMERIC
  711. // .s {}
  712. $css['.s']['text-align'] = 'left'; // STRING
  713. // Calculate cell style hashes
  714. foreach ($this->phpExcel->getCellXfCollection() as $index => $style) {
  715. $css['td.style' . $index] = $this->createCSSStyle($style);
  716. $css['th.style' . $index] = $this->createCSSStyle($style);
  717. }
  718. // Fetch sheets
  719. $sheets = array();
  720. if (is_null($this->sheetIndex)) {
  721. $sheets = $this->phpExcel->getAllSheets();
  722. } else {
  723. $sheets[] = $this->phpExcel->getSheet($this->sheetIndex);
  724. }
  725. // Build styles per sheet
  726. foreach ($sheets as $sheet) {
  727. // Calculate hash code
  728. $sheetIndex = $sheet->getParent()->getIndex($sheet);
  729. // Build styles
  730. // Calculate column widths
  731. $sheet->calculateColumnWidths();
  732. // col elements, initialize
  733. $highestColumnIndex = PHPExcel_Cell::columnIndexFromString($sheet->getHighestColumn()) - 1;
  734. $column = -1;
  735. while ($column++ < $highestColumnIndex) {
  736. $this->columnWidths[$sheetIndex][$column] = 42; // approximation
  737. $css['table.sheet' . $sheetIndex . ' col.col' . $column]['width'] = '42pt';
  738. }
  739. // col elements, loop through columnDimensions and set width
  740. foreach ($sheet->getColumnDimensions() as $columnDimension) {
  741. if (($width = PHPExcel_Shared_Drawing::cellDimensionToPixels($columnDimension->getWidth(), $this->defaultFont)) >= 0) {
  742. $width = PHPExcel_Shared_Drawing::pixelsToPoints($width);
  743. $column = PHPExcel_Cell::columnIndexFromString($columnDimension->getColumnIndex()) - 1;
  744. $this->columnWidths[$sheetIndex][$column] = $width;
  745. $css['table.sheet' . $sheetIndex . ' col.col' . $column]['width'] = $width . 'pt';
  746. if ($columnDimension->getVisible() === false) {
  747. $css['table.sheet' . $sheetIndex . ' col.col' . $column]['visibility'] = 'collapse';
  748. $css['table.sheet' . $sheetIndex . ' col.col' . $column]['*display'] = 'none'; // target IE6+7
  749. }
  750. }
  751. }
  752. // Default row height
  753. $rowDimension = $sheet->getDefaultRowDimension();
  754. // table.sheetN tr { }
  755. $css['table.sheet' . $sheetIndex . ' tr'] = array();
  756. if ($rowDimension->getRowHeight() == -1) {
  757. $pt_height = PHPExcel_Shared_Font::getDefaultRowHeightByFont($this->phpExcel->getDefaultStyle()->getFont());
  758. } else {
  759. $pt_height = $rowDimension->getRowHeight();
  760. }
  761. $css['table.sheet' . $sheetIndex . ' tr']['height'] = $pt_height . 'pt';
  762. if ($rowDimension->getVisible() === false) {
  763. $css['table.sheet' . $sheetIndex . ' tr']['display'] = 'none';
  764. $css['table.sheet' . $sheetIndex . ' tr']['visibility'] = 'hidden';
  765. }
  766. // Calculate row heights
  767. foreach ($sheet->getRowDimensions() as $rowDimension) {
  768. $row = $rowDimension->getRowIndex() - 1;
  769. // table.sheetN tr.rowYYYYYY { }
  770. $css['table.sheet' . $sheetIndex . ' tr.row' . $row] = array();
  771. if ($rowDimension->getRowHeight() == -1) {
  772. $pt_height = PHPExcel_Shared_Font::getDefaultRowHeightByFont($this->phpExcel->getDefaultStyle()->getFont());
  773. } else {
  774. $pt_height = $rowDimension->getRowHeight();
  775. }
  776. $css['table.sheet' . $sheetIndex . ' tr.row' . $row]['height'] = $pt_height . 'pt';
  777. if ($rowDimension->getVisible() === false) {
  778. $css['table.sheet' . $sheetIndex . ' tr.row' . $row]['display'] = 'none';
  779. $css['table.sheet' . $sheetIndex . ' tr.row' . $row]['visibility'] = 'hidden';
  780. }
  781. }
  782. }
  783. // Cache
  784. if (is_null($this->cssStyles)) {
  785. $this->cssStyles = $css;
  786. }
  787. // Return
  788. return $css;
  789. }
  790. /**
  791. * Create CSS style
  792. *
  793. * @param PHPExcel_Style $pStyle PHPExcel_Style
  794. * @return array
  795. */
  796. private function createCSSStyle(PHPExcel_Style $pStyle)
  797. {
  798. // Construct CSS
  799. $css = '';
  800. // Create CSS
  801. $css = array_merge(
  802. $this->createCSSStyleAlignment($pStyle->getAlignment()),
  803. $this->createCSSStyleBorders($pStyle->getBorders()),
  804. $this->createCSSStyleFont($pStyle->getFont()),
  805. $this->createCSSStyleFill($pStyle->getFill())
  806. );
  807. // Return
  808. return $css;
  809. }
  810. /**
  811. * Create CSS style (PHPExcel_Style_Alignment)
  812. *
  813. * @param PHPExcel_Style_Alignment $pStyle PHPExcel_Style_Alignment
  814. * @return array
  815. */
  816. private function createCSSStyleAlignment(PHPExcel_Style_Alignment $pStyle)
  817. {
  818. // Construct CSS
  819. $css = array();
  820. // Create CSS
  821. $css['vertical-align'] = $this->mapVAlign($pStyle->getVertical());
  822. if ($textAlign = $this->mapHAlign($pStyle->getHorizontal())) {
  823. $css['text-align'] = $textAlign;
  824. if (in_array($textAlign, array('left', 'right'))) {
  825. $css['padding-'.$textAlign] = (string)((int)$pStyle->getIndent() * 9).'px';
  826. }
  827. }
  828. return $css;
  829. }
  830. /**
  831. * Create CSS style (PHPExcel_Style_Font)
  832. *
  833. * @param PHPExcel_Style_Font $pStyle PHPExcel_Style_Font
  834. * @return array
  835. */
  836. private function createCSSStyleFont(PHPExcel_Style_Font $pStyle)
  837. {
  838. // Construct CSS
  839. $css = array();
  840. // Create CSS
  841. if ($pStyle->getBold()) {
  842. $css['font-weight'] = 'bold';
  843. }
  844. if ($pStyle->getUnderline() != PHPExcel_Style_Font::UNDERLINE_NONE && $pStyle->getStrikethrough()) {
  845. $css['text-decoration'] = 'underline line-through';
  846. } elseif ($pStyle->getUnderline() != PHPExcel_Style_Font::UNDERLINE_NONE) {
  847. $css['text-decoration'] = 'underline';
  848. } elseif ($pStyle->getStrikethrough()) {
  849. $css['text-decoration'] = 'line-through';
  850. }
  851. if ($pStyle->getItalic()) {
  852. $css['font-style'] = 'italic';
  853. }
  854. $css['color'] = '#' . $pStyle->getColor()->getRGB();
  855. $css['font-family'] = '\'' . $pStyle->getName() . '\'';
  856. $css['font-size'] = $pStyle->getSize() . 'pt';
  857. return $css;
  858. }
  859. /**
  860. * Create CSS style (PHPExcel_Style_Borders)
  861. *
  862. * @param PHPExcel_Style_Borders $pStyle PHPExcel_Style_Borders
  863. * @return array
  864. */
  865. private function createCSSStyleBorders(PHPExcel_Style_Borders $pStyle)
  866. {
  867. // Construct CSS
  868. $css = array();
  869. // Create CSS
  870. $css['border-bottom'] = $this->createCSSStyleBorder($pStyle->getBottom());
  871. $css['border-top'] = $this->createCSSStyleBorder($pStyle->getTop());
  872. $css['border-left'] = $this->createCSSStyleBorder($pStyle->getLeft());
  873. $css['border-right'] = $this->createCSSStyleBorder($pStyle->getRight());
  874. return $css;
  875. }
  876. /**
  877. * Create CSS style (PHPExcel_Style_Border)
  878. *
  879. * @param PHPExcel_Style_Border $pStyle PHPExcel_Style_Border
  880. * @return string
  881. */
  882. private function createCSSStyleBorder(PHPExcel_Style_Border $pStyle)
  883. {
  884. // Create CSS
  885. // $css = $this->mapBorderStyle($pStyle->getBorderStyle()) . ' #' . $pStyle->getColor()->getRGB();
  886. // Create CSS - add !important to non-none border styles for merged cells
  887. $borderStyle = $this->mapBorderStyle($pStyle->getBorderStyle());
  888. $css = $borderStyle . ' #' . $pStyle->getColor()->getRGB() . (($borderStyle == 'none') ? '' : ' !important');
  889. return $css;
  890. }
  891. /**
  892. * Create CSS style (PHPExcel_Style_Fill)
  893. *
  894. * @param PHPExcel_Style_Fill $pStyle PHPExcel_Style_Fill
  895. * @return array
  896. */
  897. private function createCSSStyleFill(PHPExcel_Style_Fill $pStyle)
  898. {
  899. // Construct HTML
  900. $css = array();
  901. // Create CSS
  902. $value = $pStyle->getFillType() == PHPExcel_Style_Fill::FILL_NONE ?
  903. 'white' : '#' . $pStyle->getStartColor()->getRGB();
  904. $css['background-color'] = $value;
  905. return $css;
  906. }
  907. /**
  908. * Generate HTML footer
  909. */
  910. public function generateHTMLFooter()
  911. {
  912. // Construct HTML
  913. $html = '';
  914. $html .= ' </body>' . PHP_EOL;
  915. $html .= '</html>' . PHP_EOL;
  916. return $html;
  917. }
  918. /**
  919. * Generate table header
  920. *
  921. * @param PHPExcel_Worksheet $pSheet The worksheet for the table we are writing
  922. * @return string
  923. * @throws PHPExcel_Writer_Exception
  924. */
  925. private function generateTableHeader($pSheet)
  926. {
  927. $sheetIndex = $pSheet->getParent()->getIndex($pSheet);
  928. // Construct HTML
  929. $html = '';
  930. $html .= $this->setMargins($pSheet);
  931. if (!$this->useInlineCss) {
  932. $gridlines = $pSheet->getShowGridlines() ? ' gridlines' : '';
  933. $html .= ' <table border="0" cellpadding="0" cellspacing="0" id="sheet' . $sheetIndex . '" class="sheet' . $sheetIndex . $gridlines . '">' . PHP_EOL;
  934. } else {
  935. $style = isset($this->cssStyles['table']) ?
  936. $this->assembleCSS($this->cssStyles['table']) : '';
  937. if ($this->isPdf && $pSheet->getShowGridlines()) {
  938. $html .= ' <table border="1" cellpadding="1" id="sheet' . $sheetIndex . '" cellspacing="1" style="' . $style . '">' . PHP_EOL;
  939. } else {
  940. $html .= ' <table border="0" cellpadding="1" id="sheet' . $sheetIndex . '" cellspacing="0" style="' . $style . '">' . PHP_EOL;
  941. }
  942. }
  943. // Write <col> elements
  944. $highestColumnIndex = PHPExcel_Cell::columnIndexFromString($pSheet->getHighestColumn()) - 1;
  945. $i = -1;
  946. while ($i++ < $highestColumnIndex) {
  947. if (!$this->isPdf) {
  948. if (!$this->useInlineCss) {
  949. $html .= ' <col class="col' . $i . '">' . PHP_EOL;
  950. } else {
  951. $style = isset($this->cssStyles['table.sheet' . $sheetIndex . ' col.col' . $i]) ?
  952. $this->assembleCSS($this->cssStyles['table.sheet' . $sheetIndex . ' col.col' . $i]) : '';
  953. $html .= ' <col style="' . $style . '">' . PHP_EOL;
  954. }
  955. }
  956. }
  957. return $html;
  958. }
  959. /**
  960. * Generate table footer
  961. *
  962. * @throws PHPExcel_Writer_Exception
  963. */
  964. private function generateTableFooter()
  965. {
  966. $html = ' </table>' . PHP_EOL;
  967. return $html;
  968. }
  969. /**
  970. * Generate row
  971. *
  972. * @param PHPExcel_Worksheet $pSheet PHPExcel_Worksheet
  973. * @param array $pValues Array containing cells in a row
  974. * @param int $pRow Row number (0-based)
  975. * @return string
  976. * @throws PHPExcel_Writer_Exception
  977. */
  978. private function generateRow(PHPExcel_Worksheet $pSheet, $pValues = null, $pRow = 0, $cellType = 'td')
  979. {
  980. if (is_array($pValues)) {
  981. // Construct HTML
  982. $html = '';
  983. // Sheet index
  984. $sheetIndex = $pSheet->getParent()->getIndex($pSheet);
  985. // DomPDF and breaks
  986. if ($this->isPdf && count($pSheet->getBreaks()) > 0) {
  987. $breaks = $pSheet->getBreaks();
  988. // check if a break is needed before this row
  989. if (isset($breaks['A' . $pRow])) {
  990. // close table: </table>
  991. $html .= $this->generateTableFooter();
  992. // insert page break
  993. $html .= '<div style="page-break-before:always" />';
  994. // open table again: <table> + <col> etc.
  995. $html .= $this->generateTableHeader($pSheet);
  996. }
  997. }
  998. // Write row start
  999. if (!$this->useInlineCss) {
  1000. $html .= ' <tr class="row' . $pRow . '">' . PHP_EOL;
  1001. } else {
  1002. $style = isset($this->cssStyles['table.sheet' . $sheetIndex . ' tr.row' . $pRow])
  1003. ? $this->assembleCSS($this->cssStyles['table.sheet' . $sheetIndex . ' tr.row' . $pRow]) : '';
  1004. $html .= ' <tr style="' . $style . '">' . PHP_EOL;
  1005. }
  1006. // Write cells
  1007. $colNum = 0;
  1008. foreach ($pValues as $cellAddress) {
  1009. $cell = ($cellAddress > '') ? $pSheet->getCell($cellAddress) : '';
  1010. $coordinate = PHPExcel_Cell::stringFromColumnIndex($colNum) . ($pRow + 1);
  1011. if (!$this->useInlineCss) {
  1012. $cssClass = '';
  1013. $cssClass = 'column' . $colNum;
  1014. } else {
  1015. $cssClass = array();
  1016. if ($cellType == 'th') {
  1017. if (isset($this->cssStyles['table.sheet' . $sheetIndex . ' th.column' . $colNum])) {
  1018. $this->cssStyles['table.sheet' . $sheetIndex . ' th.column' . $colNum];
  1019. }
  1020. } else {
  1021. if (isset($this->cssStyles['table.sheet' . $sheetIndex . ' td.column' . $colNum])) {
  1022. $this->cssStyles['table.sheet' . $sheetIndex . ' td.column' . $colNum];
  1023. }
  1024. }
  1025. }
  1026. $colSpan = 1;
  1027. $rowSpan = 1;
  1028. // initialize
  1029. $cellData = '&nbsp;';
  1030. // PHPExcel_Cell
  1031. if ($cell instanceof PHPExcel_Cell) {
  1032. $cellData = '';
  1033. if (is_null($cell->getParent())) {
  1034. $cell->attach($pSheet);
  1035. }
  1036. // Value
  1037. if ($cell->getValue() instanceof PHPExcel_RichText) {
  1038. // Loop through rich text elements
  1039. $elements = $cell->getValue()->getRichTextElements();
  1040. foreach ($elements as $element) {
  1041. // Rich text start?
  1042. if ($element instanceof PHPExcel_RichText_Run) {
  1043. $cellData .= '<span style="' . $this->assembleCSS($this->createCSSStyleFont($element->getFont())) . '">';
  1044. if ($element->getFont()->getSuperScript()) {
  1045. $cellData .= '<sup>';
  1046. } elseif ($element->getFont()->getSubScript()) {
  1047. $cellData .= '<sub>';
  1048. }
  1049. }
  1050. // Convert UTF8 data to PCDATA
  1051. $cellText = $element->getText();
  1052. $cellData .= htmlspecialchars($cellText);
  1053. if ($element instanceof PHPExcel_RichText_Run) {
  1054. if ($element->getFont()->getSuperScript()) {
  1055. $cellData .= '</sup>';
  1056. } elseif ($element->getFont()->getSubScript()) {
  1057. $cellData .= '</sub>';
  1058. }
  1059. $cellData .= '</span>';
  1060. }
  1061. }
  1062. } else {
  1063. if ($this->preCalculateFormulas) {
  1064. $cellData = PHPExcel_Style_NumberFormat::toFormattedString(
  1065. $cell->getCalculatedValue(),
  1066. $pSheet->getParent()->getCellXfByIndex($cell->getXfIndex())->getNumberFormat()->getFormatCode(),
  1067. array($this, 'formatColor')
  1068. );
  1069. } else {
  1070. $cellData = PHPExcel_Style_NumberFormat::toFormattedString(
  1071. $cell->getValue(),
  1072. $pSheet->getParent()->getCellXfByIndex($cell->getXfIndex())->getNumberFormat()->getFormatCode(),
  1073. array($this, 'formatColor')
  1074. );
  1075. }
  1076. $cellData = htmlspecialchars($cellData);
  1077. if ($pSheet->getParent()->getCellXfByIndex($cell->getXfIndex())->getFont()->getSuperScript()) {
  1078. $cellData = '<sup>'.$cellData.'</sup>';
  1079. } elseif ($pSheet->getParent()->getCellXfByIndex($cell->getXfIndex())->getFont()->getSubScript()) {
  1080. $cellData = '<sub>'.$cellData.'</sub>';
  1081. }
  1082. }
  1083. // Converts the cell content so that spaces occuring at beginning of each new line are replaced by &nbsp;
  1084. // Example: " Hello\n to the world" is converted to "&nbsp;&nbsp;Hello\n&nbsp;to the world"
  1085. $cellData = preg_replace("/(?m)(?:^|\\G) /", '&nbsp;', $cellData);
  1086. // convert newline "\n" to '<br>'
  1087. $cellData = nl2br($cellData);
  1088. // Extend CSS class?
  1089. if (!$this->useInlineCss) {
  1090. $cssClass .= ' style' . $cell->getXfIndex();
  1091. $cssClass .= ' ' . $cell->getDataType();
  1092. } else {
  1093. if ($cellType == 'th') {
  1094. if (isset($this->cssStyles['th.style' . $cell->getXfIndex()])) {
  1095. $cssClass = array_merge($cssClass, $this->cssStyles['th.style' . $cell->getXfIndex()]);
  1096. }
  1097. } else {
  1098. if (isset($this->cssStyles['td.style' . $cell->getXfIndex()])) {
  1099. $cssClass = array_merge($cssClass, $this->cssStyles['td.style' . $cell->getXfIndex()]);
  1100. }
  1101. }
  1102. // General horizontal alignment: Actual horizontal alignment depends on dataType
  1103. $sharedStyle = $pSheet->getParent()->getCellXfByIndex($cell->getXfIndex());
  1104. if ($sharedStyle->getAlignment()->getHorizontal() == PHPExcel_Style_Alignment::HORIZONTAL_GENERAL
  1105. && isset($this->cssStyles['.' . $cell->getDataType()]['text-align'])) {
  1106. $cssClass['text-align'] = $this->cssStyles['.' . $cell->getDataType()]['text-align'];
  1107. }
  1108. }
  1109. }
  1110. // Hyperlink?
  1111. if ($pSheet->hyperlinkExists($coordinate) && !$pSheet->getHyperlink($coordinate)->isInternal()) {
  1112. $cellData = '<a href="' . htmlspecialchars($pSheet->getHyperlink($coordinate)->getUrl()) . '" title="' . htmlspecialchars($pSheet->getHyperlink($coordinate)->getTooltip()) . '">' . $cellData . '</a>';
  1113. }
  1114. // Should the cell be written or is it swallowed by a rowspan or colspan?
  1115. $writeCell = !(isset($this->isSpannedCell[$pSheet->getParent()->getIndex($pSheet)][$pRow + 1][$colNum])
  1116. && $this->isSpannedCell[$pSheet->getParent()->getIndex($pSheet)][$pRow + 1][$colNum]);
  1117. // Colspan and Rowspan
  1118. $colspan = 1;
  1119. $rowspan = 1;
  1120. if (isset($this->isBaseCell[$pSheet->getParent()->getIndex($pSheet)][$pRow + 1][$colNum])) {
  1121. $spans = $this->isBaseCell[$pSheet->getParent()->getIndex($pSheet)][$pRow + 1][$colNum];
  1122. $rowSpan = $spans['rowspan'];
  1123. $colSpan = $spans['colspan'];
  1124. // Also apply style from last cell in merge to fix borders -
  1125. // relies on !important for non-none border declarations in createCSSStyleBorder
  1126. $endCellCoord = PHPExcel_Cell::stringFromColumnIndex($colNum + $colSpan - 1) . ($pRow + $rowSpan);
  1127. if (!$this->useInlineCss) {
  1128. $cssClass .= ' style' . $pSheet->getCell($endCellCoord)->getXfIndex();
  1129. }
  1130. }
  1131. // Write
  1132. if ($writeCell) {
  1133. // Column start
  1134. $html .= ' <' . $cellType;
  1135. if (!$this->useInlineCss) {
  1136. $html .= ' class="' . $cssClass . '"';
  1137. } else {
  1138. //** Necessary redundant code for the sake of PHPExcel_Writer_PDF **
  1139. // We must explicitly write the width of the <td> element because TCPDF
  1140. // does not recognize e.g. <col style="width:42pt">
  1141. $width = 0;
  1142. $i = $colNum - 1;
  1143. $e = $colNum + $colSpan - 1;
  1144. while ($i++ < $e) {
  1145. if (isset($this->columnWidths[$sheetIndex][$i])) {
  1146. $width += $this->columnWidths[$sheetIndex][$i];
  1147. }
  1148. }
  1149. $cssClass['width'] = $width . 'pt';
  1150. // We must also explicitly write the height of the <td> element because TCPDF
  1151. // does not recognize e.g. <tr style="height:50pt">
  1152. if (isset($this->cssStyles['table.sheet' . $sheetIndex . ' tr.row' . $pRow]['height'])) {
  1153. $height = $this->cssStyles['table.sheet' . $sheetIndex . ' tr.row' . $pRow]['height'];
  1154. $cssClass['height'] = $height;
  1155. }
  1156. //** end of redundant code **
  1157. $html .= ' style="' . $this->assembleCSS($cssClass) . '"';
  1158. }
  1159. if ($colSpan > 1) {
  1160. $html .= ' colspan="' . $colSpan . '"';
  1161. }
  1162. if ($rowSpan > 1) {
  1163. $html .= ' rowspan="' . $rowSpan . '"';
  1164. }
  1165. $html .= '>';
  1166. // Image?
  1167. $html .= $this->writeImageInCell($pSheet, $coordinate);
  1168. // Chart?
  1169. if ($this->includeCharts) {
  1170. $html .= $this->writeChartInCell($pSheet, $coordinate);
  1171. }

Large files files are truncated, but you can click here to view the full file