PageRenderTime 51ms CodeModel.GetById 12ms RepoModel.GetById 1ms app.codeStats 0ms

/branches/v1.6.2/Classes/PHPExcel/Writer/HTML.php

#
PHP | 742 lines | 370 code | 99 blank | 273 comment | 68 complexity | dad51a8844e8c1bbd7ce91ab4c43b6b5 MD5 | raw file
Possible License(s): AGPL-1.0, LGPL-2.0, LGPL-2.1, GPL-3.0, LGPL-3.0
  1. <?php
  2. /**
  3. * PHPExcel
  4. *
  5. * Copyright (c) 2006 - 2008 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
  23. * @copyright Copyright (c) 2006 - 2008 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. /** PHPExcel_IWriter */
  28. require_once 'PHPExcel/Writer/IWriter.php';
  29. /** PHPExcel_Cell */
  30. require_once 'PHPExcel/Cell.php';
  31. /** PHPExcel_RichText */
  32. require_once 'PHPExcel/RichText.php';
  33. /** PHPExcel_Shared_Drawing */
  34. require_once 'PHPExcel/Shared/Drawing.php';
  35. /** PHPExcel_Shared_String */
  36. require_once 'PHPExcel/Shared/String.php';
  37. /** PHPExcel_HashTable */
  38. require_once 'PHPExcel/HashTable.php';
  39. /**
  40. * PHPExcel_Writer_HTML
  41. *
  42. * @category PHPExcel
  43. * @package PHPExcel_Writer
  44. * @copyright Copyright (c) 2006 - 2008 PHPExcel (http://www.codeplex.com/PHPExcel)
  45. */
  46. class PHPExcel_Writer_HTML implements PHPExcel_Writer_IWriter {
  47. /**
  48. * PHPExcel object
  49. *
  50. * @var PHPExcel
  51. */
  52. private $_phpExcel;
  53. /**
  54. * Sheet index to write
  55. *
  56. * @var int
  57. */
  58. private $_sheetIndex;
  59. /**
  60. * Pre-calculate formulas
  61. *
  62. * @var boolean
  63. */
  64. private $_preCalculateFormulas = true;
  65. /**
  66. * Images root
  67. *
  68. * @var string
  69. */
  70. private $_imagesRoot = '.';
  71. /**
  72. * Create a new PHPExcel_Writer_HTML
  73. *
  74. * @param PHPExcel $phpExcel PHPExcel object
  75. */
  76. public function __construct(PHPExcel $phpExcel) {
  77. $this->_phpExcel = $phpExcel;
  78. $this->_sheetIndex = 0;
  79. $this->_imagesRoot = '.';
  80. }
  81. /**
  82. * Save PHPExcel to file
  83. *
  84. * @param string $pFileName
  85. * @throws Exception
  86. */
  87. public function save($pFilename = null) {
  88. // Open file
  89. $fileHandle = fopen($pFilename, 'w');
  90. if ($fileHandle === false) {
  91. throw new Exception("Could not open file $pFilename for writing.");
  92. }
  93. // Fetch sheets
  94. $sheets = array();
  95. if (is_null($this->_sheetIndex)) {
  96. $sheets = $this->_phpExcel->getAllSheets();
  97. } else {
  98. $sheets[] = $this->_phpExcel->getSheet($this->_sheetIndex);
  99. }
  100. // Write headers
  101. $this->_writeHTMLHeader($fileHandle);
  102. $this->_writeStyles($fileHandle, $sheets);
  103. // Loop all sheets
  104. foreach ($sheets as $sheet) {
  105. // Calculate hash code
  106. $hashCode = $sheet->getHashCode();
  107. // Get cell collection
  108. $cellCollection = $sheet->getCellCollection();
  109. // Write header
  110. $this->_writeTableHeader($fileHandle, $hashCode);
  111. // Get worksheet dimension
  112. $dimension = explode(':', $sheet->calculateWorksheetDimension());
  113. $dimension[0] = PHPExcel_Cell::coordinateFromString($dimension[0]);
  114. $dimension[0][0] = PHPExcel_Cell::columnIndexFromString($dimension[0][0]) - 1;
  115. $dimension[1] = PHPExcel_Cell::coordinateFromString($dimension[1]);
  116. $dimension[1][0] = PHPExcel_Cell::columnIndexFromString($dimension[1][0]) - 1;
  117. // Loop trough cells
  118. $rowData = null;
  119. for ($row = $dimension[0][1]; $row <= $dimension[1][1]; $row++) {
  120. // Start a new row
  121. $rowData = array();
  122. // Loop trough columns
  123. for ($column = $dimension[0][0]; $column <= $dimension[1][0]; $column++) {
  124. // Cell exists?
  125. if ($sheet->cellExistsByColumnAndRow($column, $row)) {
  126. $rowData[$column] = $sheet->getCellByColumnAndRow($column, $row);
  127. } else {
  128. $rowData[$column] = '';
  129. }
  130. }
  131. // Write row
  132. $this->_writeRow($fileHandle, $sheet, $rowData, $row - 1);
  133. }
  134. // Write footer
  135. $this->_writeTableFooter($fileHandle);
  136. }
  137. // Write footer
  138. $this->_writeHTMLFooter($fileHandle);
  139. // Close file
  140. fclose($fileHandle);
  141. }
  142. /**
  143. * Map VAlign
  144. */
  145. private function _mapVAlign($vAlign) {
  146. switch ($vAlign) {
  147. case PHPExcel_Style_Alignment::VERTICAL_BOTTOM: return 'bottom';
  148. case PHPExcel_Style_Alignment::VERTICAL_TOP: return 'top';
  149. case PHPExcel_Style_Alignment::VERTICAL_CENTER:
  150. case PHPExcel_Style_Alignment::VERTICAL_JUSTIFY: return 'middle';
  151. default: return ' baseline';
  152. }
  153. }
  154. /**
  155. * Map HAlign
  156. */
  157. private function _mapHAlign($hAlign) {
  158. switch ($hAlign) {
  159. case PHPExcel_Style_Alignment::HORIZONTAL_GENERAL:
  160. case PHPExcel_Style_Alignment::HORIZONTAL_LEFT: return 'left';
  161. case PHPExcel_Style_Alignment::HORIZONTAL_RIGHT: return 'right';
  162. case PHPExcel_Style_Alignment::HORIZONTAL_CENTER: return 'center';
  163. case PHPExcel_Style_Alignment::HORIZONTAL_JUSTIFY: return 'justify';
  164. default: return ' baseline';
  165. }
  166. }
  167. /**
  168. * Map border style
  169. */
  170. private function _mapBorderStyle($borderStyle) {
  171. switch ($borderStyle) {
  172. case PHPExcel_Style_Border::BORDER_NONE: return '0px';
  173. case PHPExcel_Style_Border::BORDER_DASHED: return '1px dashed';
  174. case PHPExcel_Style_Border::BORDER_DOTTED: return '1px dotted';
  175. case PHPExcel_Style_Border::BORDER_THICK: return '2px solid';
  176. default: return '1px solid'; // map others to thin
  177. }
  178. }
  179. /**
  180. * Get sheet index
  181. *
  182. * @return int
  183. */
  184. public function getSheetIndex() {
  185. return $this->_sheetIndex;
  186. }
  187. /**
  188. * Set sheet index
  189. *
  190. * @param int $pValue Sheet index
  191. */
  192. public function setSheetIndex($pValue = 0) {
  193. $this->_sheetIndex = $pValue;
  194. }
  195. /**
  196. * Write all sheets (resets sheetIndex to NULL)
  197. */
  198. public function writeAllSheets() {
  199. $this->_sheetIndex = null;
  200. }
  201. /**
  202. * Write HTML header to file
  203. *
  204. * @param mixed $pFileHandle PHP filehandle
  205. * @throws Exception
  206. */
  207. private function _writeHTMLHeader($pFileHandle = null) {
  208. if (!is_null($pFileHandle)) {
  209. // Construct HTML
  210. $html = '';
  211. $html .= '<!-- Generated by PHPExcel - http://www.phpexcel.net -->' . "\r\n";
  212. $html .= '<html>' . "\r\n";
  213. $html .= ' <head>' . "\r\n";
  214. $html .= ' <title>' . $this->_phpExcel->getProperties()->getTitle() . '</title>' . "\r\n";
  215. $html .= ' </head>' . "\r\n";
  216. $html .= '' . "\r\n";
  217. $html .= ' <body>' . "\r\n";
  218. // Write to file
  219. fwrite($pFileHandle, $html);
  220. } else {
  221. throw new Exception("Invalid parameters passed.");
  222. }
  223. }
  224. /**
  225. * Write images to file
  226. *
  227. * @param mixed $pFileHandle PHP filehandle
  228. * @param PHPExcel_Worksheet $pSheet PHPExcel_Worksheet
  229. * @param string $coordinates Cell coordinates
  230. * @throws Exception
  231. */
  232. private function _writeImageInCell($pFileHandle = null, PHPExcel_Worksheet $pSheet, $coordinates) {
  233. if (!is_null($pFileHandle)) {
  234. // Construct HTML
  235. $html = '';
  236. // Write images
  237. foreach ($pSheet->getDrawingCollection() as $drawing) {
  238. if ($drawing instanceof PHPExcel_Worksheet_BaseDrawing) {
  239. if ($drawing->getCoordinates() == $coordinates) {
  240. $filename = $drawing->getPath();
  241. // Strip off eventual '.'
  242. if (substr($filename, 0, 1) == '.') {
  243. $filename = substr($filename, 1);
  244. }
  245. // Prepend images root
  246. $filename = $this->getImagesRoot() . $filename;
  247. $html .= "\r\n";
  248. $html .= ' <img style="position: relative; left: ' . $drawing->getOffsetX() . 'px; top: ' . $drawing->getOffsetY() . 'px; width: ' . $drawing->getWidth() . 'px; height: ' . $drawing->getHeight() . 'px;" src="' . $filename . '" border="0">' . "\r\n";
  249. }
  250. }
  251. }
  252. // Write to file
  253. fwrite($pFileHandle, $html);
  254. } else {
  255. throw new Exception("Invalid parameters passed.");
  256. }
  257. }
  258. /**
  259. * Write styles to file
  260. *
  261. * @param mixed $pFileHandle PHP filehandle
  262. * @param PHPExcel_Worksheet[] $pSheets Array of PHPExcel_Worksheet
  263. * @throws Exception
  264. */
  265. private function _writeStyles($pFileHandle = null, $pSheets) {
  266. if (!is_null($pFileHandle) && is_array($pSheets)) {
  267. // Construct HTML
  268. $html = '';
  269. // Start styles
  270. $html .= ' <style>' . "\r\n";
  271. $html .= ' <!--' . "\r\n";
  272. $html .= ' html {' . "\r\n";
  273. $html .= ' font-family: Calibri, Arial, Helvetica, Sans Serif;' . "\r\n";
  274. $html .= ' font-size: 10pt;' . "\r\n";
  275. $html .= ' background-color: white;' . "\r\n";
  276. $html .= ' }' . "\r\n";
  277. // Write styles per sheet
  278. foreach ($pSheets as $sheet) {
  279. // Calculate hash code
  280. $hashCode = $sheet->getHashCode();
  281. // Write styles
  282. $html .= ' table.sheet' . $hashCode . ', table.sheet' . $hashCode . ' td {' . "\r\n";
  283. if ($sheet->getShowGridlines()) {
  284. $html .= ' border: 1px dotted black;' . "\r\n";
  285. }
  286. $html .= ' page-break-after: always;' . "\r\n";
  287. $html .= ' }' . "\r\n";
  288. // Calculate column widths
  289. $sheet->calculateColumnWidths();
  290. foreach ($sheet->getColumnDimensions() as $columnDimension) {
  291. $column = PHPExcel_Cell::columnIndexFromString($columnDimension->getColumnIndex()) - 1;
  292. $html .= ' table.sheet' . $hashCode . ' td.column' . $column . ' {' . "\r\n";
  293. $html .= ' width: ' . PHPExcel_Shared_Drawing::cellDimensionToPixels($columnDimension->getWidth()) . 'px;' . "\r\n";
  294. if ($columnDimension->getVisible() === false) {
  295. $html .= ' display: none;' . "\r\n";
  296. $html .= ' visibility: hidden;' . "\r\n";
  297. }
  298. $html .= ' }' . "\r\n";
  299. }
  300. // Calculate row heights
  301. foreach ($sheet->getRowDimensions() as $rowDimension) {
  302. $html .= ' table.sheet' . $hashCode . ' tr.row' . ($rowDimension->getRowIndex() - 1) . ' {' . "\r\n";
  303. // height is disproportionately large
  304. $px_height = round( PHPExcel_Shared_Drawing::cellDimensionToPixels($rowDimension->getRowHeight()) /12 );
  305. $html .= ' height: ' . $px_height . 'px;' . "\r\n";
  306. if ($rowDimension->getVisible() === false) {
  307. $html .= ' display: none;' . "\r\n";
  308. $html .= ' visibility: hidden;' . "\r\n";
  309. }
  310. $html .= ' }' . "\r\n";
  311. }
  312. // Calculate cell style hashes
  313. $cellStyleHashes = new PHPExcel_HashTable();
  314. $cellStyleHashes->addFromSource( $sheet->getStyles() );
  315. for ($i = 0; $i < $cellStyleHashes->count(); $i++) {
  316. $html .= $this->_createCSSStyle( $cellStyleHashes->getByIndex($i) );
  317. }
  318. }
  319. // End styles
  320. $html .= ' -->' . "\r\n";
  321. $html .= ' </style>' . "\r\n";
  322. // Write to file
  323. fwrite($pFileHandle, $html);
  324. } else {
  325. throw new Exception("Invalid parameters passed.");
  326. }
  327. }
  328. /**
  329. * Create CSS style
  330. *
  331. * @param PHPExcel_Style $pStyle PHPExcel_Style
  332. * @return string
  333. */
  334. private function _createCSSStyle(PHPExcel_Style $pStyle) {
  335. // Construct HTML
  336. $html = '';
  337. // Create CSS
  338. $html .= ' .style' . $pStyle->getHashCode() . ' {' . "\r\n";
  339. $html .= $this->_createCSSStyleAlignment($pStyle->getAlignment());
  340. $html .= $this->_createCSSStyleFont($pStyle->getFont());
  341. $html .= $this->_createCSSStyleBorders($pStyle->getBorders());
  342. $html .= $this->_createCSSStyleFill($pStyle->getFill());
  343. $html .= ' }' . "\r\n";
  344. // Return
  345. return $html;
  346. }
  347. /**
  348. * Create CSS style (PHPExcel_Style_Alignment)
  349. *
  350. * @param PHPExcel_Style_Alignment $pStyle PHPExcel_Style_Alignment
  351. * @return string
  352. */
  353. private function _createCSSStyleAlignment(PHPExcel_Style_Alignment $pStyle) {
  354. // Construct HTML
  355. $html = '';
  356. // Create CSS
  357. $html .= ' vertical-align: ' . $this->_mapVAlign($pStyle->getVertical()) . ';' . "\r\n";
  358. $html .= ' text-align: ' . $this->_mapHAlign($pStyle->getHorizontal()) . ';' . "\r\n";
  359. // Return
  360. return $html;
  361. }
  362. /**
  363. * Create CSS style (PHPExcel_Style_Font)
  364. *
  365. * @param PHPExcel_Style_Font $pStyle PHPExcel_Style_Font
  366. * @return string
  367. */
  368. private function _createCSSStyleFont(PHPExcel_Style_Font $pStyle) {
  369. // Construct HTML
  370. $html = '';
  371. // Create CSS
  372. if ($pStyle->getBold()) {
  373. $html .= ' font-weight: bold;' . "\r\n";
  374. }
  375. if ($pStyle->getUnderline() != PHPExcel_Style_Font::UNDERLINE_NONE && $pStyle->getStriketrough()) {
  376. $html .= ' text-decoration: underline line-through;' . "\r\n";
  377. } else if ($pStyle->getUnderline() != PHPExcel_Style_Font::UNDERLINE_NONE) {
  378. $html .= ' text-decoration: underline;' . "\r\n";
  379. } else if ($pStyle->getStriketrough()) {
  380. $html .= ' text-decoration: line-through;' . "\r\n";
  381. }
  382. if ($pStyle->getItalic()) {
  383. $html .= ' font-style: italic;' . "\r\n";
  384. }
  385. $html .= ' color: ' . '#' . $pStyle->getColor()->getRGB() . ';' . "\r\n";
  386. $html .= ' font-family: ' . $pStyle->getName() . ';' . "\r\n";
  387. $html .= ' font-size: ' . $pStyle->getSize() . 'pt;' . "\r\n";
  388. // Return
  389. return $html;
  390. }
  391. /**
  392. * Create CSS style (PHPExcel_Style_Borders)
  393. *
  394. * @param PHPExcel_Style_Borders $pStyle PHPExcel_Style_Borders
  395. * @return string
  396. */
  397. private function _createCSSStyleBorders(PHPExcel_Style_Borders $pStyle) {
  398. // Construct HTML
  399. $html = '';
  400. // Create CSS
  401. $html .= ' border-bottom: ' . $this->_createCSSStyleBorder($pStyle->getBottom()) . ';' . "\r\n";
  402. $html .= ' border-top: ' . $this->_createCSSStyleBorder($pStyle->getTop()) . ';' . "\r\n";
  403. $html .= ' border-left: ' . $this->_createCSSStyleBorder($pStyle->getLeft()) . ';' . "\r\n";
  404. $html .= ' border-right: ' . $this->_createCSSStyleBorder($pStyle->getRight()) . ';' . "\r\n";
  405. // Return
  406. return $html;
  407. }
  408. /**
  409. * Create CSS style (PHPExcel_Style_Border)
  410. *
  411. * @param PHPExcel_Style_Border $pStyle PHPExcel_Style_Border
  412. * @return string
  413. */
  414. private function _createCSSStyleBorder(PHPExcel_Style_Border $pStyle) {
  415. // Construct HTML
  416. $html = '';
  417. // Create CSS
  418. $html .= $this->_mapBorderStyle($pStyle->getBorderStyle()) . ' #' . $pStyle->getColor()->getRGB();
  419. // Return
  420. return $html;
  421. }
  422. /**
  423. * Create CSS style (PHPExcel_Style_Fill)
  424. *
  425. * @param PHPExcel_Style_Fill $pStyle PHPExcel_Style_Fill
  426. * @return string
  427. */
  428. private function _createCSSStyleFill(PHPExcel_Style_Fill $pStyle) {
  429. // Construct HTML
  430. $html = '';
  431. // Create CSS
  432. $html .= ' background-color: ' . '#' . $pStyle->getStartColor()->getRGB() . ';' . "\r\n";
  433. // Return
  434. return $html;
  435. }
  436. /**
  437. * Write HTML footer to file
  438. *
  439. * @param mixed $pFileHandle PHP filehandle
  440. * @throws Exception
  441. */
  442. private function _writeHTMLFooter($pFileHandle = null) {
  443. if (!is_null($pFileHandle)) {
  444. // Construct HTML
  445. $html = '';
  446. $html .= ' </body>' . "\r\n";
  447. $html .= '</html>' . "\r\n";
  448. // Write to file
  449. fwrite($pFileHandle, $html);
  450. } else {
  451. throw new Exception("Invalid parameters passed.");
  452. }
  453. }
  454. /**
  455. * Write table header to file
  456. *
  457. * @param mixed $pFileHandle PHP filehandle
  458. * @param string $pIdentifier Identifier for the table
  459. * @throws Exception
  460. */
  461. private function _writeTableHeader($pFileHandle = null, $pIdentifier = '') {
  462. if (!is_null($pFileHandle)) {
  463. // Construct HTML
  464. $html = '';
  465. $html .= ' <table border="0" cellpadding="0" cellspacing="0" class="sheet' . $pIdentifier . '">' . "\r\n";
  466. // Write to file
  467. fwrite($pFileHandle, $html);
  468. } else {
  469. throw new Exception("Invalid parameters passed.");
  470. }
  471. }
  472. /**
  473. * Write table footer to file
  474. *
  475. * @param mixed $pFileHandle PHP filehandle
  476. * @throws Exception
  477. */
  478. private function _writeTableFooter($pFileHandle = null) {
  479. if (!is_null($pFileHandle)) {
  480. // Construct HTML
  481. $html = '';
  482. $html .= ' </table>' . "\r\n";
  483. // Write to file
  484. fwrite($pFileHandle, $html);
  485. } else {
  486. throw new Exception("Invalid parameters passed.");
  487. }
  488. }
  489. /**
  490. * Write row to HTML file
  491. *
  492. * @param mixed $pFileHandle PHP filehandle
  493. * @param PHPExcel_Worksheet $pSheet PHPExcel_Worksheet
  494. * @param array $pValues Array containing cells in a row
  495. * @param int $pRow Row number
  496. * @throws Exception
  497. */
  498. private function _writeRow($pFileHandle = null, PHPExcel_Worksheet $pSheet, $pValues = null, $pRow = 0) {
  499. if (!is_null($pFileHandle) && is_array($pValues)) {
  500. // Write row start
  501. fwrite($pFileHandle, ' <tr class="row' . $pRow . '">' . "\r\n");
  502. // Write cells
  503. $colNum = 0;
  504. foreach ($pValues as $cell) {
  505. $cellData = '&nbsp;';
  506. $cssClass = 'column' . $colNum;
  507. $colSpan = 1;
  508. $rowSpan = 1;
  509. $writeCell = true; // Write cell
  510. // PHPExcel_Cell
  511. if ($cell instanceof PHPExcel_Cell) {
  512. // Value
  513. if ($cell->getValue() instanceof PHPExcel_RichText) {
  514. // Loop trough rich text elements
  515. $elements = $cell->getValue()->getRichTextElements();
  516. foreach ($elements as $element) {
  517. // Rich text start?
  518. if ($element instanceof PHPExcel_RichText_Run) {
  519. $cellData .= '<span style="' .
  520. str_replace("\r\n", '',
  521. $this->_createCSSStyleFont($element->getFont())
  522. ) . '">';
  523. }
  524. // Decode UTF8 data
  525. $cellText = $element->getText();
  526. if (PHPExcel_Shared_String::IsUTF8($cellText)) {
  527. $cellData .= utf8_decode($cellText);
  528. }
  529. if ($element instanceof PHPExcel_RichText_Run) {
  530. $cellData .= '</span>';
  531. }
  532. }
  533. } else {
  534. if ($this->_preCalculateFormulas) {
  535. $cellData = PHPExcel_Style_NumberFormat::toFormattedString(
  536. $cell->getCalculatedValue(),
  537. $pSheet->getstyle( $cell->getCoordinate() )->getNumberFormat()->getFormatCode()
  538. );
  539. } else {
  540. $cellData = PHPExcel_Style_NumberFormat::ToFormattedString(
  541. $cell->getValue(),
  542. $pSheet->getstyle( $cell->getCoordinate() )->getNumberFormat()->getFormatCode()
  543. );
  544. }
  545. // Decode UTF8 data
  546. if (PHPExcel_Shared_String::IsUTF8($cellData)) {
  547. $cellData = utf8_decode($cellData);
  548. }
  549. }
  550. // Check value
  551. if ($cellData == '') {
  552. $cellData = '&nbsp;';
  553. }
  554. // Extend CSS class?
  555. if (array_key_exists($cell->getCoordinate(), $pSheet->getStyles())) {
  556. $cssClass .= ' style' . $pSheet->getStyle($cell->getCoordinate())->getHashCode();
  557. }
  558. } else {
  559. $cell = new PHPExcel_Cell(
  560. PHPExcel_Cell::stringFromColumnIndex($colNum),
  561. ($pRow + 1),
  562. '',
  563. null,
  564. null
  565. );
  566. }
  567. // Hyperlink?
  568. if ($cell->hasHyperlink() && !$cell->getHyperlink()->isInternal()) {
  569. $cellData = '<a href="' . $cell->getHyperlink()->getUrl() . '" title="' . $cell->getHyperlink()->getTooltip() . '">' . $cellData . '</a>';
  570. }
  571. // Column/rowspan
  572. foreach ($pSheet->getMergeCells() as $cells) {
  573. if ($cell->isInRange($cells)) {
  574. list($first, ) = PHPExcel_Cell::splitRange($cells);
  575. if ($first == $cell->getCoordinate()) {
  576. list($colSpan, $rowSpan) = PHPExcel_Cell::rangeDimension($cells);
  577. } else {
  578. $writeCell = false;
  579. }
  580. break;
  581. }
  582. }
  583. // Write
  584. if ($writeCell) {
  585. // Column start
  586. fwrite($pFileHandle, ' <td');
  587. fwrite($pFileHandle, ' class="' . $cssClass . '"');
  588. if ($colSpan > 1) {
  589. fwrite($pFileHandle, ' colspan="' . $colSpan . '"');
  590. }
  591. if ($rowSpan > 1) {
  592. fwrite($pFileHandle, ' rowspan="' . $rowSpan . '"');
  593. }
  594. fwrite($pFileHandle, '>');
  595. // Image?
  596. $this->_writeImageInCell($pFileHandle, $pSheet, $cell->getCoordinate());
  597. // Cell data
  598. fwrite($pFileHandle, $cellData);
  599. // Column end
  600. fwrite($pFileHandle, '</td>' . "\r\n");
  601. }
  602. // Next column
  603. $colNum++;
  604. }
  605. // Write row end
  606. fwrite($pFileHandle, ' </tr>' . "\r\n");
  607. } else {
  608. throw new Exception("Invalid parameters passed.");
  609. }
  610. }
  611. /**
  612. * Get Pre-Calculate Formulas
  613. *
  614. * @return boolean
  615. */
  616. public function getPreCalculateFormulas() {
  617. return $this->_preCalculateFormulas;
  618. }
  619. /**
  620. * Set Pre-Calculate Formulas
  621. *
  622. * @param boolean $pValue Pre-Calculate Formulas?
  623. */
  624. public function setPreCalculateFormulas($pValue = true) {
  625. $this->_preCalculateFormulas = $pValue;
  626. }
  627. /**
  628. * Get images root
  629. *
  630. * @return string
  631. */
  632. public function getImagesRoot() {
  633. return $this->_imagesRoot;
  634. }
  635. /**
  636. * Set images root
  637. *
  638. * @param string $pValue
  639. */
  640. public function setImagesRoot($pValue = '.') {
  641. $this->_imagesRoot = $pValue;
  642. }
  643. }