From c1fe7016ab80cb78ed0c6ddb27ca554927481333 Mon Sep 17 00:00:00 2001 From: Mark Baker Date: Fri, 28 Jan 2011 16:02:33 +0000 Subject: [PATCH] Feature: Added support for superscript/subscript in HTML/PDF Writers git-svn-id: https://phpexcel.svn.codeplex.com/svn/trunk@67512 2327b42d-5241-43d6-9e2a-de5ac946f064 --- Classes/PHPExcel/Writer/HTML.php | 35 +++++++++++++++----------------- 1 file changed, 16 insertions(+), 19 deletions(-) diff --git a/Classes/PHPExcel/Writer/HTML.php b/Classes/PHPExcel/Writer/HTML.php index 4be99c2..9337c1f 100644 --- a/Classes/PHPExcel/Writer/HTML.php +++ b/Classes/PHPExcel/Writer/HTML.php @@ -426,7 +426,7 @@ class PHPExcel_Writer_HTML implements PHPExcel_Writer_IWriter { // Writing PDF? if ($this->_isPdf) { if (is_null($this->_sheetIndex) && $sheetId + 1 < $this->_phpExcel->getSheetCount()) { - $html .= ''; + $html .= '
'; } } @@ -729,7 +729,7 @@ class PHPExcel_Writer_HTML implements PHPExcel_Writer_IWriter { // Create CSS $css = array_merge( $this->_createCSSStyleAlignment($pStyle->getAlignment()) - , $this->_createCSSStyleBorders($pStyle->getBorders(),$pStyle->getFill()) + , $this->_createCSSStyleBorders($pStyle->getBorders()) , $this->_createCSSStyleFont($pStyle->getFont()) , $this->_createCSSStyleFill($pStyle->getFill()) ); @@ -797,15 +797,15 @@ class PHPExcel_Writer_HTML implements PHPExcel_Writer_IWriter { * @param PHPExcel_Style_Borders $pStyle PHPExcel_Style_Borders * @return array */ - private function _createCSSStyleBorders(PHPExcel_Style_Borders $pStyle, PHPExcel_Style_Fill $fill) { + private function _createCSSStyleBorders(PHPExcel_Style_Borders $pStyle) { // Construct CSS $css = array(); // Create CSS - $css['border-bottom'] = $this->_createCSSStyleBorder($pStyle->getBottom(),$fill); - $css['border-top'] = $this->_createCSSStyleBorder($pStyle->getTop(),$fill); - $css['border-left'] = $this->_createCSSStyleBorder($pStyle->getLeft(),$fill); - $css['border-right'] = $this->_createCSSStyleBorder($pStyle->getRight(),$fill); + $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()); // Return return $css; @@ -817,20 +817,12 @@ class PHPExcel_Writer_HTML implements PHPExcel_Writer_IWriter { * @param PHPExcel_Style_Border $pStyle PHPExcel_Style_Border * @return string */ - private function _createCSSStyleBorder(PHPExcel_Style_Border $pStyle, PHPExcel_Style_Fill $fill) { + private function _createCSSStyleBorder(PHPExcel_Style_Border $pStyle) { // Construct HTML $css = ''; // Create CSS - $borderWidth = $this->_mapBorderStyle($pStyle->getBorderStyle()); - if (($borderWidth == '0px') && ($this->_isPdf)) { - // tcPDF treats a 0px border with a colour of black as a thick black border, so we set the colour to the - // background colour for the cell if we're generating PDF output - $bValue = $fill->getFillType() == PHPExcel_Style_Fill::FILL_NONE ? 'FFFFFF' : $fill->getStartColor()->getRGB(); - $css .= $borderWidth . ' #' . $bValue; - } else { - $css .= $borderWidth . ' #' . $pStyle->getColor()->getRGB(); - } + $css .= $this->_mapBorderStyle($pStyle->getBorderStyle()) . ' #' . $pStyle->getColor()->getRGB(); // Return return $css; @@ -943,7 +935,7 @@ class PHPExcel_Writer_HTML implements PHPExcel_Writer_IWriter { // Sheet index $sheetIndex = $pSheet->getParent()->getIndex($pSheet); - // TCPDF and breaks + // DomPDF and breaks if ($this->_isPdf && count($pSheet->getBreaks()) > 0) { $breaks = $pSheet->getBreaks(); @@ -953,7 +945,7 @@ class PHPExcel_Writer_HTML implements PHPExcel_Writer_IWriter { $html .= $this->_generateTableFooter(); // insert page break - $html .= ''; + $html .= '
'; // open table again: + etc. $html .= $this->_generateTableHeader($pSheet); @@ -1039,6 +1031,11 @@ class PHPExcel_Writer_HTML implements PHPExcel_Writer_IWriter { array($this, 'formatColor') ); } + if ($pSheet->getParent()->getCellXfByIndex( $cell->getXfIndex() )->getFont()->getSuperScript()) { + $cellData = ''.$cellData.''; + } elseif ($pSheet->getParent()->getCellXfByIndex( $cell->getXfIndex() )->getFont()->getSubScript()) { + $cellData = ''.$cellData.''; + } } // Converts the cell content so that spaces occuring at beginning of each new line are replaced by