Use th rather than td for cells when in thead

This commit is contained in:
MarkBaker 2014-08-06 00:09:44 +01:00
parent 14e5e806a7
commit bdb8b50156

View File

@ -412,11 +412,13 @@ class PHPExcel_Writer_HTML extends PHPExcel_Writer_Abstract implements PHPExcel_
// <thead> ? // <thead> ?
if ($row == $theadStart) { if ($row == $theadStart) {
$html .= ' <thead>' . PHP_EOL; $html .= ' <thead>' . PHP_EOL;
$cellType = 'th';
} }
// <tbody> ? // <tbody> ?
if ($row == $tbodyStart) { if ($row == $tbodyStart) {
$html .= ' <tbody>' . PHP_EOL; $html .= ' <tbody>' . PHP_EOL;
$cellType = 'td';
} }
// Write row if there are HTML table cells in it // Write row if there are HTML table cells in it
@ -433,7 +435,7 @@ class PHPExcel_Writer_HTML extends PHPExcel_Writer_Abstract implements PHPExcel_
$rowData[$column] = ''; $rowData[$column] = '';
} }
} }
$html .= $this->_generateRow($sheet, $rowData, $row - 1); $html .= $this->_generateRow($sheet, $rowData, $row - 1, $cellType);
} }
// </thead> ? // </thead> ?
@ -751,6 +753,7 @@ class PHPExcel_Writer_HTML extends PHPExcel_Writer_Abstract implements PHPExcel_
// .gridlines td { } // .gridlines td { }
$css['.gridlines td']['border'] = '1px dotted black'; $css['.gridlines td']['border'] = '1px dotted black';
$css['.gridlines th']['border'] = '1px dotted black';
// .b {} // .b {}
$css['.b']['text-align'] = 'center'; // BOOL $css['.b']['text-align'] = 'center'; // BOOL
@ -773,6 +776,7 @@ class PHPExcel_Writer_HTML extends PHPExcel_Writer_Abstract implements PHPExcel_
// Calculate cell style hashes // Calculate cell style hashes
foreach ($this->_phpExcel->getCellXfCollection() as $index => $style) { foreach ($this->_phpExcel->getCellXfCollection() as $index => $style) {
$css['td.style' . $index] = $this->_createCSSStyle( $style ); $css['td.style' . $index] = $this->_createCSSStyle( $style );
$css['th.style' . $index] = $this->_createCSSStyle( $style );
} }
// Fetch sheets // Fetch sheets
@ -1077,7 +1081,7 @@ class PHPExcel_Writer_HTML extends PHPExcel_Writer_Abstract implements PHPExcel_
* @return string * @return string
* @throws PHPExcel_Writer_Exception * @throws PHPExcel_Writer_Exception
*/ */
private function _generateRow(PHPExcel_Worksheet $pSheet, $pValues = null, $pRow = 0) { private function _generateRow(PHPExcel_Worksheet $pSheet, $pValues = null, $pRow = 0, $cellType = 'td') {
if (is_array($pValues)) { if (is_array($pValues)) {
// Construct HTML // Construct HTML
$html = ''; $html = '';
@ -1122,8 +1126,14 @@ class PHPExcel_Writer_HTML extends PHPExcel_Writer_Abstract implements PHPExcel_
$cssClass = 'column' . $colNum; $cssClass = 'column' . $colNum;
} else { } else {
$cssClass = array(); $cssClass = array();
if ($cellType == 'th') {
if (isset($this->_cssStyles['table.sheet' . $sheetIndex . ' th.column' . $colNum])) {
$this->_cssStyles['table.sheet' . $sheetIndex . ' th.column' . $colNum];
}
} else {
if (isset($this->_cssStyles['table.sheet' . $sheetIndex . ' td.column' . $colNum])) { if (isset($this->_cssStyles['table.sheet' . $sheetIndex . ' td.column' . $colNum])) {
$this->_cssStyles['table.sheet' . $sheetIndex . ' td.column' . $colNum]; $this->_cssStyles['table.sheet' . $sheetIndex . ' td.column' . $colNum];
}
} }
} }
$colSpan = 1; $colSpan = 1;
@ -1202,8 +1212,14 @@ class PHPExcel_Writer_HTML extends PHPExcel_Writer_Abstract implements PHPExcel_
$cssClass .= ' style' . $cell->getXfIndex(); $cssClass .= ' style' . $cell->getXfIndex();
$cssClass .= ' ' . $cell->getDataType(); $cssClass .= ' ' . $cell->getDataType();
} else { } else {
if ($cellType == 'th') {
if (isset($this->_cssStyles['th.style' . $cell->getXfIndex()])) {
$cssClass = array_merge($cssClass, $this->_cssStyles['th.style' . $cell->getXfIndex()]);
}
} else {
if (isset($this->_cssStyles['td.style' . $cell->getXfIndex()])) { if (isset($this->_cssStyles['td.style' . $cell->getXfIndex()])) {
$cssClass = array_merge($cssClass, $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 // General horizontal alignment: Actual horizontal alignment depends on dataType
@ -1244,7 +1260,7 @@ class PHPExcel_Writer_HTML extends PHPExcel_Writer_Abstract implements PHPExcel_
// Write // Write
if ($writeCell) { if ($writeCell) {
// Column start // Column start
$html .= ' <td'; $html .= ' <' . $cellType;
if (!$this->_useInlineCss) { if (!$this->_useInlineCss) {
$html .= ' class="' . $cssClass . '"'; $html .= ' class="' . $cssClass . '"';
} else { } else {
@ -1291,7 +1307,7 @@ class PHPExcel_Writer_HTML extends PHPExcel_Writer_Abstract implements PHPExcel_
$html .= $cellData; $html .= $cellData;
// Column end // Column end
$html .= '</td>' . PHP_EOL; $html .= '</'.$cellType.'>' . PHP_EOL;
} }
// Next column // Next column