Source for file HTML.php
Documentation is available at HTML.php
* Copyright (c) 2006 - 2011 PHPExcel
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
* @package PHPExcel_Writer
* @copyright Copyright (c) 2006 - 2011 PHPExcel (http://www.codeplex.com/PHPExcel)
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version 1.7.6, 2011-02-27
* @package PHPExcel_Writer
* @copyright Copyright (c) 2006 - 2011 PHPExcel (http://www.codeplex.com/PHPExcel)
private $_sheetIndex = 0;
private $_preCalculateFormulas = true;
private $_imagesRoot = '.';
private $_useInlineCss = false;
private $_cssStyles = null;
* Array of column widths in points
private $_columnWidths = null;
* @var PHPExcel_Style_Font
* Flag whether spans have been calculated
private $_spansAreCalculated = false;
* Excel cells that should not be written as HTML cells
private $_isSpannedCell = array();
* Excel cells that are upper-left corner in a cell merge
private $_isBaseCell = array();
* Excel rows that should not be written as HTML rows
private $_isSpannedRow = array();
* Is the current writer creating PDF?
* Generate the Navigation block
private $_generateSheetNavigationBlock = true;
* Create a new PHPExcel_Writer_HTML
* @param PHPExcel $phpExcel PHPExcel object
$this->_defaultFont = $this->_phpExcel->getDefaultStyle()->getFont();
* @param string $pFileName
public function save($pFilename = null) {
$fileHandle = fopen($pFilename, 'wb+');
if ($fileHandle === false) {
throw new Exception("Could not open file $pFilename for writing.");
// Write navigation (tabs)
if ((!$this->_isPdf) && ($this->_generateSheetNavigationBlock)) {
private function _mapVAlign($vAlign) {
default: return 'baseline';
private function _mapHAlign($hAlign) {
private function _mapBorderStyle($borderStyle) {
default: return '1px solid'; // map others to thin
return $this->_sheetIndex;
* @param int $pValue Sheet index
* @return PHPExcel_Writer_HTML
$this->_sheetIndex = $pValue;
return $this->_generateSheetNavigationBlock;
* @param boolean $pValue Flag indicating whether the sheet navigation block should be generated or not
* @return PHPExcel_Writer_HTML
$this->_generateSheetNavigationBlock = (bool) $pValue;
* Write all sheets (resets sheetIndex to NULL)
$this->_sheetIndex = null;
* @param boolean $pIncludeStyles Include styles?
// PHPExcel object known?
throw new Exception('Internal PHPExcel object not set to an instance of an object.');
$html = '<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">' . PHP_EOL;
$html .= '<!-- Generated by PHPExcel - http://www.phpexcel.net -->' . PHP_EOL;
$html .= '<html>' . PHP_EOL;
$html .= ' <head>' . PHP_EOL;
$html .= ' <meta http-equiv="Content-Type" content="text/html; charset=utf-8">' . PHP_EOL;
$html .= ' </head>' . PHP_EOL;
$html .= ' <body>' . PHP_EOL;
// PHPExcel object known?
throw new Exception('Internal PHPExcel object not set to an instance of an object.');
// Ensure that Spans have been calculated?
if (!$this->_spansAreCalculated) {
$this->_calculateSpans();
$sheets[] = $this->_phpExcel->getSheet($this->_sheetIndex);
foreach ($sheets as $sheet) {
$html .= $this->_generateTableHeader($sheet);
// Get worksheet dimension
$dimension = explode(':', $sheet->calculateWorksheetDimension());
$rowMin = $dimension[0][1];
$rowMax = $dimension[1][1];
// calculate start of <tbody>, <thead>
$theadStart = $theadEnd = 0; // default: no <thead> no </thead>
if ($sheet->getPageSetup()->isRowsToRepeatAtTopSet()) {
$rowsToRepeatAtTop = $sheet->getPageSetup()->getRowsToRepeatAtTop();
// we can only support repeating rows that start at top row
if ($rowsToRepeatAtTop[0] == 1) {
$theadStart = $rowsToRepeatAtTop[0];
$theadEnd = $rowsToRepeatAtTop[1];
$tbodyStart = $rowsToRepeatAtTop[1] + 1;
while($row++ < $rowMax) {
if ($row == $theadStart) {
$html .= ' <thead>' . PHP_EOL;
if ($row == $tbodyStart) {
$html .= ' <tbody>' . PHP_EOL;
// Write row if there are HTML table cells in it
if ( !isset ($this->_isSpannedRow[$sheet->getParent()->getIndex($sheet)][$row]) ) {
$column = $dimension[0][0] - 1;
while($column++ < $dimension[1][0]) {
if ($sheet->cellExistsByColumnAndRow($column, $row)) {
$rowData[$column] = $sheet->getCellByColumnAndRow($column, $row);
$html .= $this->_generateRow($sheet, $rowData, $row - 1);
$html .= ' </thead>' . PHP_EOL;
$html .= ' </tbody>' . PHP_EOL;
$html .= $this->_generateTableFooter();
if (is_null($this->_sheetIndex) && $sheetId + 1 < $this->_phpExcel->getSheetCount()) {
$html .= '<div style="page-break-before:always" />';
// PHPExcel object known?
throw new Exception('Internal PHPExcel object not set to an instance of an object.');
$sheets[] = $this->_phpExcel->getSheet($this->_sheetIndex);
// Only if there are more than 1 sheets
if (count($sheets) > 1) {
$html .= '<ul class="navigation">' . PHP_EOL;
foreach ($sheets as $sheet) {
$html .= ' <li class="sheet' . $sheetId . '"><a href="#sheet' . $sheetId . '">' . $sheet->getTitle() . '</a></li>' . PHP_EOL;
$html .= '</ul>' . PHP_EOL;
* Generate image tag in cell
* @param PHPExcel_Worksheet $pSheet PHPExcel_Worksheet
* @param string $coordinates Cell coordinates
private function _writeImageTagInCell(PHPExcel_Worksheet $pSheet, $coordinates) {
foreach ($pSheet->getDrawingCollection() as $drawing) {
if ($drawing->getCoordinates() == $coordinates) {
$filename = $drawing->getPath();
// Strip off eventual '.'
if (substr($filename, 0, 1) == '.') {
$filename = substr($filename, 1);
// Strip off eventual '.'
if (substr($filename, 0, 1) == '.' && substr($filename, 0, 2) != './') {
$filename = substr($filename, 1);
// Convert UTF8 data to PCDATA
$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" width="' . $drawing->getWidth() . '" height="' . $drawing->getHeight() . '" />' . PHP_EOL;
* @param boolean $generateSurroundingHTML Generate surrounding HTML tags? (<style> and </style>)
// PHPExcel object known?
throw new Exception('Internal PHPExcel object not set to an instance of an object.');
$css = $this->buildCSS($generateSurroundingHTML);
if ($generateSurroundingHTML) {
$html .= ' <style type="text/css">' . PHP_EOL;
$html .= ' html { ' . $this->_assembleCSS($css['html']) . ' }' . PHP_EOL;
// Write all other styles
foreach ($css as $styleName => $styleDefinition) {
if ($styleName != 'html') {
$html .= ' ' . $styleName . ' { ' . $this->_assembleCSS($styleDefinition) . ' }' . PHP_EOL;
if ($generateSurroundingHTML) {
$html .= ' </style>' . PHP_EOL;
* @param boolean $generateSurroundingHTML Generate surrounding HTML style? (html { })
public function buildCSS($generateSurroundingHTML = true) {
// PHPExcel object known?
throw new Exception('Internal PHPExcel object not set to an instance of an object.');
return $this->_cssStyles;
// Ensure that spans have been calculated
if (!$this->_spansAreCalculated) {
$this->_calculateSpans();
if ($generateSurroundingHTML) {
$css['html']['font-family'] = 'Calibri, Arial, Helvetica, sans-serif';
$css['html']['font-size'] = '11pt';
$css['html']['background-color'] = 'white';
$css['table']['border-collapse'] = 'collapse';
$css['table']['page-break-after'] = 'always';
$css['.gridlines td']['border'] = '1px dotted black';
$css['.b']['text-align'] = 'center'; // BOOL
$css['.e']['text-align'] = 'center'; // ERROR
$css['.f']['text-align'] = 'right'; // FORMULA
$css['.inlineStr']['text-align'] = 'left'; // INLINE
$css['.n']['text-align'] = 'right'; // NUMERIC
$css['.s']['text-align'] = 'left'; // STRING
// Calculate cell style hashes
foreach ($this->_phpExcel->getCellXfCollection() as $index => $style) {
$css['td.style' . $index] = $this->_createCSSStyle( $style );
$sheets[] = $this->_phpExcel->getSheet($this->_sheetIndex);
// Build styles per sheet
foreach ($sheets as $sheet) {
$sheetIndex = $sheet->getParent()->getIndex($sheet);
// Calculate column widths
$sheet->calculateColumnWidths();
// col elements, initialize
while($column++ < $highestColumnIndex) {
$this->_columnWidths[$sheetIndex][$column] = 42; // approximation
$css['table.sheet' . $sheetIndex . ' col.col' . $column]['width'] = '42pt';
// col elements, loop through columnDimensions and set width
foreach ($sheet->getColumnDimensions() as $columnDimension) {
$this->_columnWidths[$sheetIndex][$column] = $width;
$css['table.sheet' . $sheetIndex . ' col.col' . $column]['width'] = $width . 'pt';
if ($columnDimension->getVisible() === false) {
$css['table.sheet' . $sheetIndex . ' col.col' . $column]['visibility'] = 'collapse';
$css['table.sheet' . $sheetIndex . ' col.col' . $column]['*display'] = 'none'; // target IE6+7
$rowDimension = $sheet->getDefaultRowDimension();
$css['table.sheet' . $sheetIndex . ' tr'] = array();
if ($rowDimension->getRowHeight() == - 1) {
$pt_height = $rowDimension->getRowHeight();
$css['table.sheet' . $sheetIndex . ' tr']['height'] = $pt_height . 'pt';
if ($rowDimension->getVisible() === false) {
$css['table.sheet' . $sheetIndex . ' tr']['display'] = 'none';
$css['table.sheet' . $sheetIndex . ' tr']['visibility'] = 'hidden';
foreach ($sheet->getRowDimensions() as $rowDimension) {
$row = $rowDimension->getRowIndex() - 1;
// table.sheetN tr.rowYYYYYY { }
$css['table.sheet' . $sheetIndex . ' tr.row' . $row] = array();
if ($rowDimension->getRowHeight() == - 1) {
$pt_height = $rowDimension->getRowHeight();
$css['table.sheet' . $sheetIndex . ' tr.row' . $row]['height'] = $pt_height . 'pt';
if ($rowDimension->getVisible() === false) {
$css['table.sheet' . $sheetIndex . ' tr.row' . $row]['display'] = 'none';
$css['table.sheet' . $sheetIndex . ' tr.row' . $row]['visibility'] = 'hidden';
$this->_cssStyles = $css;
* @param PHPExcel_Style $pStyle PHPExcel_Style
private function _createCSSStyle(PHPExcel_Style $pStyle) {
$this->_createCSSStyleAlignment($pStyle->getAlignment())
, $this->_createCSSStyleBorders($pStyle->getBorders())
, $this->_createCSSStyleFont($pStyle->getFont())
, $this->_createCSSStyleFill($pStyle->getFill())
* Create CSS style (PHPExcel_Style_Alignment)
* @param PHPExcel_Style_Alignment $pStyle PHPExcel_Style_Alignment
private function _createCSSStyleAlignment(PHPExcel_Style_Alignment $pStyle) {
$css['vertical-align'] = $this->_mapVAlign($pStyle->getVertical());
if ($textAlign = $this->_mapHAlign($pStyle->getHorizontal())) {
$css['text-align'] = $textAlign;
* Create CSS style (PHPExcel_Style_Font)
* @param PHPExcel_Style_Font $pStyle PHPExcel_Style_Font
private function _createCSSStyleFont(PHPExcel_Style_Font $pStyle) {
if ($pStyle->getBold()) {
$css['font-weight'] = 'bold';
if ($pStyle->getUnderline() != PHPExcel_Style_Font::UNDERLINE_NONE && $pStyle->getStrikethrough()) {
$css['text-decoration'] = 'underline line-through';
$css['text-decoration'] = 'underline';
} else if ($pStyle->getStrikethrough()) {
$css['text-decoration'] = 'line-through';
if ($pStyle->getItalic()) {
$css['font-style'] = 'italic';
$css['color'] = '#' . $pStyle->getColor()->getRGB();
$css['font-family'] = '\'' . $pStyle->getName() . '\'';
$css['font-size'] = $pStyle->getSize() . 'pt';
* Create CSS style (PHPExcel_Style_Borders)
* @param PHPExcel_Style_Borders $pStyle PHPExcel_Style_Borders
private function _createCSSStyleBorders(PHPExcel_Style_Borders $pStyle) {
$css['border-bottom'] = $this->_createCSSStyleBorder($pStyle->getBottom());
$css['border-top'] = $this->_createCSSStyleBorder($pStyle->getTop());
$css['border-left'] = $this->_createCSSStyleBorder($pStyle->getLeft());
$css['border-right'] = $this->_createCSSStyleBorder($pStyle->getRight());
* Create CSS style (PHPExcel_Style_Border)
* @param PHPExcel_Style_Border $pStyle PHPExcel_Style_Border
private function _createCSSStyleBorder(PHPExcel_Style_Border $pStyle) {
$css .= $this->_mapBorderStyle($pStyle->getBorderStyle()) . ' #' . $pStyle->getColor()->getRGB();
* Create CSS style (PHPExcel_Style_Fill)
* @param PHPExcel_Style_Fill $pStyle PHPExcel_Style_Fill
private function _createCSSStyleFill(PHPExcel_Style_Fill $pStyle) {
'white' : '#' . $pStyle->getStartColor()->getRGB();
$css['background-color'] = $value;
$html .= ' </body>' . PHP_EOL;
$html .= '</html>' . PHP_EOL;
* @param PHPExcel_Worksheet $pSheet The worksheet for the table we are writing
private function _generateTableHeader($pSheet) {
$sheetIndex = $pSheet->getParent()->getIndex($pSheet);
if (!$this->_useInlineCss) {
$gridlines = $pSheet->getShowGridLines() ? ' gridlines' : '';
$html .= ' <table border="0" cellpadding="0" cellspacing="0" id="sheet' . $sheetIndex . '" class="sheet' . $sheetIndex . $gridlines . '">' . PHP_EOL;
$style = isset ($this->_cssStyles['table']) ?
$this->_assembleCSS($this->_cssStyles['table']) : '';
if ($this->_isPdf && $pSheet->getShowGridLines()) {
$html .= ' <table border="1" cellpadding="1" id="sheet' . $sheetIndex . '" cellspacing="4" style="' . $style . '">' . PHP_EOL;
$html .= ' <table border="0" cellpadding="1" id="sheet' . $sheetIndex . '" cellspacing="4" style="' . $style . '">' . PHP_EOL;
while($i++ < $highestColumnIndex) {
if (!$this->_useInlineCss) {
$html .= ' <col class="col' . $i . '">' . PHP_EOL;
$style = isset ($this->_cssStyles['table.sheet' . $sheetIndex . ' col.col' . $i]) ?
$this->_assembleCSS($this->_cssStyles['table.sheet' . $sheetIndex . ' col.col' . $i]) : '';
$html .= ' <col style="' . $style . '">' . PHP_EOL;
private function _generateTableFooter() {
$html .= ' </table>' . PHP_EOL;
* @param PHPExcel_Worksheet $pSheet PHPExcel_Worksheet
* @param array $pValues Array containing cells in a row
* @param int $pRow Row number (0-based)
private function _generateRow(PHPExcel_Worksheet $pSheet, $pValues = null, $pRow = 0) {
$sheetIndex = $pSheet->getParent()->getIndex($pSheet);
if ($this->_isPdf && count($pSheet->getBreaks()) > 0) {
$breaks = $pSheet->getBreaks();
// check if a break is needed before this row
if (isset ($breaks['A' . $pRow])) {
$html .= $this->_generateTableFooter();
$html .= '<div style="page-break-before:always" />';
// open table again: <table> + <col> etc.
$html .= $this->_generateTableHeader($pSheet);
if (!$this->_useInlineCss) {
$html .= ' <tr class="row' . $pRow . '">' . PHP_EOL;
$style = isset ($this->_cssStyles['table.sheet' . $sheetIndex . ' tr.row' . $pRow])
? $this->_assembleCSS($this->_cssStyles['table.sheet' . $sheetIndex . ' tr.row' . $pRow]) : '';
$html .= ' <tr style="' . $style . '">' . PHP_EOL;
foreach ($pValues as $cell) {
if (!$this->_useInlineCss) {
$cssClass = 'column' . $colNum;
if (isset ($this->_cssStyles['table.sheet' . $sheetIndex . ' td.column' . $colNum])) {
$this->_cssStyles['table.sheet' . $sheetIndex . ' td.column' . $colNum];
// Loop through rich text elements
$elements = $cell->getValue()->getRichTextElements();
foreach ($elements as $element) {
$cellData .= '<span style="' . $this->_assembleCSS($this->_createCSSStyleFont($element->getFont())) . '">';
if ($element->getFont()->getSuperScript()) {
} else if ($element->getFont()->getSubScript()) {
// Convert UTF8 data to PCDATA
$cellText = $element->getText();
if ($element->getFont()->getSuperScript()) {
} else if ($element->getFont()->getSubScript()) {
if ($this->_preCalculateFormulas) {
$cell->getCalculatedValue(),
$pSheet->getParent()->getCellXfByIndex( $cell->getXfIndex() )->getNumberFormat()->getFormatCode(),
array($this, 'formatColor')
$pSheet->getParent()->getCellXfByIndex( $cell->getXfIndex() )->getNumberFormat()->getFormatCode(),
array($this, 'formatColor')
if ($pSheet->getParent()->getCellXfByIndex( $cell->getXfIndex() )->getFont()->getSuperScript()) {
$cellData = '<sup>'. $cellData. '</sup>';
} elseif ($pSheet->getParent()->getCellXfByIndex( $cell->getXfIndex() )->getFont()->getSubScript()) {
$cellData = '<sub>'. $cellData. '</sub>';
// Converts the cell content so that spaces occuring at beginning of each new line are replaced by
// Example: " Hello\n to the world" is converted to " Hello\n to the world"
$cellData = preg_replace("/(?m)(?:^|\\G) /", ' ', $cellData);
// convert newline "\n" to '<br>'
$cellData = nl2br($cellData);
if (!$this->_useInlineCss) {
$cssClass .= ' style' . $cell->getXfIndex();
$cssClass .= ' ' . $cell->getDataType();
if (isset ($this->_cssStyles['td.style' . $cell->getXfIndex()])) {
$cssClass = array_merge($cssClass, $this->_cssStyles['td.style' . $cell->getXfIndex()]);
// General horizontal alignment: Actual horizontal alignment depends on dataType
$sharedStyle = $pSheet->getParent()->getCellXfByIndex( $cell->getXfIndex() );
&& isset ($this->_cssStyles['.' . $cell->getDataType()]['text-align']))
$cssClass['text-align'] = $this->_cssStyles['.' . $cell->getDataType()]['text-align'];
if ($pSheet->hyperlinkExists($coordinate) && !$pSheet->getHyperlink($coordinate)->isInternal()) {
$cellData = '<a href="' . htmlspecialchars($pSheet->getHyperlink($coordinate)->getUrl()) . '" title="' . htmlspecialchars($pSheet->getHyperlink($coordinate)->getTooltip()) . '">' . $cellData . '</a>';
// Should the cell be written or is it swallowed by a rowspan or colspan?
$writeCell = ! ( isset ($this->_isSpannedCell[$pSheet->getParent()->getIndex($pSheet)][$pRow + 1][$colNum])
&& $this->_isSpannedCell[$pSheet->getParent()->getIndex($pSheet)][$pRow + 1][$colNum] );
if (isset ($this->_isBaseCell[$pSheet->getParent()->getIndex($pSheet)][$pRow + 1][$colNum])) {
$spans = $this->_isBaseCell[$pSheet->getParent()->getIndex($pSheet)][$pRow + 1][$colNum];
$rowSpan = $spans['rowspan'];
$colSpan = $spans['colspan'];
if (!$this->_useInlineCss) {
$html .= ' class="' . $cssClass . '"';
//** Necessary redundant code for the sake of PHPExcel_Writer_PDF **
// We must explicitly write the width of the <td> element because TCPDF
// does not recognize e.g. <col style="width:42pt">
$e = $colNum + $colSpan - 1;
if (isset ($this->_columnWidths[$sheetIndex][$i])) {
$width += $this->_columnWidths[$sheetIndex][$i];
$cssClass['width'] = $width . 'pt';
// We must also explicitly write the height of the <td> element because TCPDF
// does not recognize e.g. <tr style="height:50pt">
if (isset ($this->_cssStyles['table.sheet' . $sheetIndex . ' tr.row' . $pRow]['height'])) {
$height = $this->_cssStyles['table.sheet' . $sheetIndex . ' tr.row' . $pRow]['height'];
$cssClass['height'] = $height;
//** end of redundant code **
$html .= ' style="' . $this->_assembleCSS($cssClass) . '"';
$html .= ' colspan="' . $colSpan . '"';
$html .= ' rowspan="' . $rowSpan . '"';
$html .= $this->_writeImageTagInCell($pSheet, $coordinate);
$html .= '</td>' . PHP_EOL;
$html .= ' </tr>' . PHP_EOL;
throw new Exception("Invalid parameters passed.");
* Takes array where of CSS properties / values and converts to CSS string
private function _assembleCSS($pValue = array())
foreach ($pValue as $property => $value) {
$pairs[] = $property . ':' . $value;
* Get Pre-Calculate Formulas
return $this->_preCalculateFormulas;
* Set Pre-Calculate Formulas
* @param boolean $pValue Pre-Calculate Formulas?
* @return PHPExcel_Writer_HTML
$this->_preCalculateFormulas = $pValue;
return $this->_imagesRoot;
* @return PHPExcel_Writer_HTML
$this->_imagesRoot = $pValue;
return $this->_useInlineCss;
* @return PHPExcel_Writer_HTML
$this->_useInlineCss = $pValue;
* Add color to formatted string as inline style
* @param string $pValue Plain formatted value without color
* @param string $pFormat Format code
// Color information, e.g. [Red] is always at the beginning
$color = null; // initialize
$color_regex = '/^\\[[a-zA-Z]+\\]/';
if (preg_match($color_regex, $pFormat, $matches)) {
$value = '<span style="color:' . $color . '">' . $value . '</span>';
* Calculate information about HTML colspan and rowspan which is not always the same as Excel's
private function _calculateSpans()
// Identify all cells that should be omitted in HTML due to cell merge.
// In HTML only the upper-left cell should be written and it should have
// appropriate rowspan / colspan attribute
$sheetIndexes = $this->_sheetIndex !== null ?
array($this->_sheetIndex) : range(0, $this->_phpExcel->getSheetCount() - 1);
foreach ($sheetIndexes as $sheetIndex) {
$sheet = $this->_phpExcel->getSheet($sheetIndex);
$candidateSpannedRow = array();
// loop through all Excel merged cells
foreach ($sheet->getMergeCells() as $cells) {
// loop through the individual cells in the individual merge
// also, flag this row as a HTML row that is candidate to be omitted
$candidateSpannedRow[$r] = $r;
if ( !($c == $fc && $r == $fr) ) {
// not the upper-left cell (should not be written in HTML)
$this->_isSpannedCell[$sheetIndex][$r][$c] = array(
'baseCell' => array($fr, $fc),
// upper-left is the base cell that should hold the colspan/rowspan attribute
$this->_isBaseCell[$sheetIndex][$r][$c] = array(
'xlrowspan' => $lr - $fr + 1, // Excel rowspan
'rowspan' => $lr - $fr + 1, // HTML rowspan, value may change
'xlcolspan' => $lc - $fc + 1, // Excel colspan
'colspan' => $lc - $fc + 1, // HTML colspan, value may change
// Identify which rows should be omitted in HTML. These are the rows where all the cells
// participate in a merge and the where base cells are somewhere above.
foreach ($candidateSpannedRow as $rowIndex) {
if (isset ($this->_isSpannedCell[$sheetIndex][$rowIndex])) {
if (count($this->_isSpannedCell[$sheetIndex][$rowIndex]) == $countColumns) {
$this->_isSpannedRow[$sheetIndex][$rowIndex] = $rowIndex;
// For each of the omitted rows we found above, the affected rowspans should be subtracted by 1
if ( isset ($this->_isSpannedRow[$sheetIndex]) ) {
foreach ($this->_isSpannedRow[$sheetIndex] as $rowIndex) {
$adjustedBaseCells = array();
$baseCell = $this->_isSpannedCell[$sheetIndex][$rowIndex][$c]['baseCell'];
if ( !in_array($baseCell, $adjustedBaseCells) ) {
-- $this->_isBaseCell[$sheetIndex][ $baseCell[0] ][ $baseCell[1] ]['rowspan'];
$adjustedBaseCells[] = $baseCell;
// TODO: Same for columns
// We have calculated the spans
$this->_spansAreCalculated = true;
|