← All changes
|
vendor/phpoffice/phpexcel/Classes/PHPExcel/Writer/HTML.php
+1306
-1370
3.1.2
→
3.0.3
View file →
| @@ -1,10 +1,9 @@ | ||
| 1 | 1 | <?php |
| 2 | - | |
| 3 | 2 | /** |
| 4 | - * PHPExcel_Writer_HTML | |
| 3 | + * PHPExcel | |
| 5 | 4 | * |
| 6 | - * Copyright (c) 2006 - 2015 PHPExcel | |
| 5 | + * Copyright (c) 2006 - 2014 PHPExcel | |
| 7 | 6 | * |
| 8 | 7 | * This library is free software; you can redistribute it and/or |
| 9 | 8 | * modify it under the terms of the GNU Lesser General Public |
| 10 | 9 | * License as published by the Free Software Foundation; either |
| @@ -19,1594 +18,1531 @@ | ||
| 19 | 18 | * License along with this library; if not, write to the Free Software |
| 20 | 19 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
| 21 | 20 | * |
| 22 | 21 | * @category PHPExcel |
| 23 | - * @package PHPExcel_Writer_HTML | |
| 24 | - * @copyright Copyright (c) 2006 - 2015 PHPExcel (http://www.codeplex.com/PHPExcel) | |
| 25 | - * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL | |
| 26 | - * @version ##VERSION##, ##DATE## | |
| 22 | + * @package PHPExcel_Writer_HTML | |
| 23 | + * @copyright Copyright (c) 2006 - 2014 PHPExcel (http://www.codeplex.com/PHPExcel) | |
| 24 | + * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL | |
| 25 | + * @version ##VERSION##, ##DATE## | |
| 27 | 26 | */ |
| 28 | -class PHPExcel_Writer_HTML extends PHPExcel_Writer_Abstract implements PHPExcel_Writer_IWriter | |
| 29 | -{ | |
| 30 | - /** | |
| 31 | - * PHPExcel object | |
| 32 | - * | |
| 33 | - * @var PHPExcel | |
| 34 | - */ | |
| 35 | - protected $phpExcel; | |
| 36 | 27 | |
| 37 | - /** | |
| 38 | - * Sheet index to write | |
| 39 | - * | |
| 40 | - * @var int | |
| 41 | - */ | |
| 42 | - private $sheetIndex = 0; | |
| 43 | 28 | |
| 44 | - /** | |
| 45 | - * Images root | |
| 46 | - * | |
| 47 | - * @var string | |
| 48 | - */ | |
| 49 | - private $imagesRoot = '.'; | |
| 29 | +/** | |
| 30 | + * PHPExcel_Writer_HTML | |
| 31 | + * | |
| 32 | + * @category PHPExcel | |
| 33 | + * @package PHPExcel_Writer_HTML | |
| 34 | + * @copyright Copyright (c) 2006 - 2014 PHPExcel (http://www.codeplex.com/PHPExcel) | |
| 35 | + */ | |
| 36 | +class PHPExcel_Writer_HTML extends PHPExcel_Writer_Abstract implements PHPExcel_Writer_IWriter { | |
| 37 | + /** | |
| 38 | + * PHPExcel object | |
| 39 | + * | |
| 40 | + * @var PHPExcel | |
| 41 | + */ | |
| 42 | + protected $_phpExcel; | |
| 50 | 43 | |
| 51 | - /** | |
| 52 | - * embed images, or link to images | |
| 53 | - * | |
| 54 | - * @var boolean | |
| 55 | - */ | |
| 56 | - private $embedImages = false; | |
| 44 | + /** | |
| 45 | + * Sheet index to write | |
| 46 | + * | |
| 47 | + * @var int | |
| 48 | + */ | |
| 49 | + private $_sheetIndex = 0; | |
| 57 | 50 | |
| 58 | - /** | |
| 59 | - * Use inline CSS? | |
| 60 | - * | |
| 61 | - * @var boolean | |
| 62 | - */ | |
| 63 | - private $useInlineCss = false; | |
| 51 | + /** | |
| 52 | + * Images root | |
| 53 | + * | |
| 54 | + * @var string | |
| 55 | + */ | |
| 56 | + private $_imagesRoot = '.'; | |
| 64 | 57 | |
| 65 | - /** | |
| 66 | - * Array of CSS styles | |
| 67 | - * | |
| 68 | - * @var array | |
| 69 | - */ | |
| 70 | - private $cssStyles; | |
| 58 | + /** | |
| 59 | + * embed images, or link to images | |
| 60 | + * | |
| 61 | + * @var boolean | |
| 62 | + */ | |
| 63 | + private $_embedImages = FALSE; | |
| 71 | 64 | |
| 72 | - /** | |
| 73 | - * Array of column widths in points | |
| 74 | - * | |
| 75 | - * @var array | |
| 76 | - */ | |
| 77 | - private $columnWidths; | |
| 65 | + /** | |
| 66 | + * Use inline CSS? | |
| 67 | + * | |
| 68 | + * @var boolean | |
| 69 | + */ | |
| 70 | + private $_useInlineCss = false; | |
| 78 | 71 | |
| 79 | - /** | |
| 80 | - * Default font | |
| 81 | - * | |
| 82 | - * @var PHPExcel_Style_Font | |
| 83 | - */ | |
| 84 | - private $defaultFont; | |
| 72 | + /** | |
| 73 | + * Array of CSS styles | |
| 74 | + * | |
| 75 | + * @var array | |
| 76 | + */ | |
| 77 | + private $_cssStyles = null; | |
| 85 | 78 | |
| 86 | - /** | |
| 87 | - * Flag whether spans have been calculated | |
| 88 | - * | |
| 89 | - * @var boolean | |
| 90 | - */ | |
| 91 | - private $spansAreCalculated = false; | |
| 79 | + /** | |
| 80 | + * Array of column widths in points | |
| 81 | + * | |
| 82 | + * @var array | |
| 83 | + */ | |
| 84 | + private $_columnWidths = null; | |
| 92 | 85 | |
| 93 | - /** | |
| 94 | - * Excel cells that should not be written as HTML cells | |
| 95 | - * | |
| 96 | - * @var array | |
| 97 | - */ | |
| 98 | - private $isSpannedCell = array(); | |
| 86 | + /** | |
| 87 | + * Default font | |
| 88 | + * | |
| 89 | + * @var PHPExcel_Style_Font | |
| 90 | + */ | |
| 91 | + private $_defaultFont; | |
| 99 | 92 | |
| 100 | - /** | |
| 101 | - * Excel cells that are upper-left corner in a cell merge | |
| 102 | - * | |
| 103 | - * @var array | |
| 104 | - */ | |
| 105 | - private $isBaseCell = array(); | |
| 93 | + /** | |
| 94 | + * Flag whether spans have been calculated | |
| 95 | + * | |
| 96 | + * @var boolean | |
| 97 | + */ | |
| 98 | + private $_spansAreCalculated = false; | |
| 106 | 99 | |
| 107 | - /** | |
| 108 | - * Excel rows that should not be written as HTML rows | |
| 109 | - * | |
| 110 | - * @var array | |
| 111 | - */ | |
| 112 | - private $isSpannedRow = array(); | |
| 100 | + /** | |
| 101 | + * Excel cells that should not be written as HTML cells | |
| 102 | + * | |
| 103 | + * @var array | |
| 104 | + */ | |
| 105 | + private $_isSpannedCell = array(); | |
| 113 | 106 | |
| 114 | - /** | |
| 115 | - * Is the current writer creating PDF? | |
| 116 | - * | |
| 117 | - * @var boolean | |
| 118 | - */ | |
| 119 | - protected $isPdf = false; | |
| 107 | + /** | |
| 108 | + * Excel cells that are upper-left corner in a cell merge | |
| 109 | + * | |
| 110 | + * @var array | |
| 111 | + */ | |
| 112 | + private $_isBaseCell = array(); | |
| 120 | 113 | |
| 121 | - /** | |
| 122 | - * Generate the Navigation block | |
| 123 | - * | |
| 124 | - * @var boolean | |
| 125 | - */ | |
| 126 | - private $generateSheetNavigationBlock = true; | |
| 114 | + /** | |
| 115 | + * Excel rows that should not be written as HTML rows | |
| 116 | + * | |
| 117 | + * @var array | |
| 118 | + */ | |
| 119 | + private $_isSpannedRow = array(); | |
| 127 | 120 | |
| 128 | - /** | |
| 129 | - * Create a new PHPExcel_Writer_HTML | |
| 130 | - * | |
| 131 | - * @param PHPExcel $phpExcel PHPExcel object | |
| 132 | - */ | |
| 133 | - public function __construct(PHPExcel $phpExcel) | |
| 134 | - { | |
| 135 | - $this->phpExcel = $phpExcel; | |
| 136 | - $this->defaultFont = $this->phpExcel->getDefaultStyle()->getFont(); | |
| 137 | - } | |
| 121 | + /** | |
| 122 | + * Is the current writer creating PDF? | |
| 123 | + * | |
| 124 | + * @var boolean | |
| 125 | + */ | |
| 126 | + protected $_isPdf = false; | |
| 138 | 127 | |
| 139 | - /** | |
| 140 | - * Save PHPExcel to file | |
| 141 | - * | |
| 142 | - * @param string $pFilename | |
| 143 | - * @throws PHPExcel_Writer_Exception | |
| 144 | - */ | |
| 145 | - public function save($pFilename = null) | |
| 146 | - { | |
| 147 | - // garbage collect | |
| 148 | - $this->phpExcel->garbageCollect(); | |
| 128 | + /** | |
| 129 | + * Generate the Navigation block | |
| 130 | + * | |
| 131 | + * @var boolean | |
| 132 | + */ | |
| 133 | + private $_generateSheetNavigationBlock = true; | |
| 149 | 134 | |
| 150 | - $saveDebugLog = PHPExcel_Calculation::getInstance($this->phpExcel)->getDebugLog()->getWriteDebugLog(); | |
| 151 | - PHPExcel_Calculation::getInstance($this->phpExcel)->getDebugLog()->setWriteDebugLog(false); | |
| 152 | - $saveArrayReturnType = PHPExcel_Calculation::getArrayReturnType(); | |
| 153 | - PHPExcel_Calculation::setArrayReturnType(PHPExcel_Calculation::RETURN_ARRAY_AS_VALUE); | |
| 135 | + /** | |
| 136 | + * Create a new PHPExcel_Writer_HTML | |
| 137 | + * | |
| 138 | + * @param PHPExcel $phpExcel PHPExcel object | |
| 139 | + */ | |
| 140 | + public function __construct(PHPExcel $phpExcel) { | |
| 141 | + $this->_phpExcel = $phpExcel; | |
| 142 | + $this->_defaultFont = $this->_phpExcel->getDefaultStyle()->getFont(); | |
| 143 | + } | |
| 154 | 144 | |
| 155 | - // Build CSS | |
| 156 | - $this->buildCSS(!$this->useInlineCss); | |
| 145 | + /** | |
| 146 | + * Save PHPExcel to file | |
| 147 | + * | |
| 148 | + * @param string $pFilename | |
| 149 | + * @throws PHPExcel_Writer_Exception | |
| 150 | + */ | |
| 151 | + public function save($pFilename = null) { | |
| 152 | + // garbage collect | |
| 153 | + $this->_phpExcel->garbageCollect(); | |
| 157 | 154 | |
| 158 | - // Open file | |
| 159 | - $fileHandle = fopen($pFilename, 'wb+'); | |
| 160 | - if ($fileHandle === false) { | |
| 161 | - throw new PHPExcel_Writer_Exception("Could not open file $pFilename for writing."); | |
| 162 | - } | |
| 155 | + $saveDebugLog = PHPExcel_Calculation::getInstance($this->_phpExcel)->getDebugLog()->getWriteDebugLog(); | |
| 156 | + PHPExcel_Calculation::getInstance($this->_phpExcel)->getDebugLog()->setWriteDebugLog(FALSE); | |
| 157 | + $saveArrayReturnType = PHPExcel_Calculation::getArrayReturnType(); | |
| 158 | + PHPExcel_Calculation::setArrayReturnType(PHPExcel_Calculation::RETURN_ARRAY_AS_VALUE); | |
| 163 | 159 | |
| 164 | - // Write headers | |
| 165 | - fwrite($fileHandle, $this->generateHTMLHeader(!$this->useInlineCss)); | |
| 160 | + // Build CSS | |
| 161 | + $this->buildCSS(!$this->_useInlineCss); | |
| 166 | 162 | |
| 167 | - // Write navigation (tabs) | |
| 168 | - if ((!$this->isPdf) && ($this->generateSheetNavigationBlock)) { | |
| 169 | - fwrite($fileHandle, $this->generateNavigation()); | |
| 170 | - } | |
| 163 | + // Open file | |
| 164 | + $fileHandle = fopen($pFilename, 'wb+'); | |
| 165 | + if ($fileHandle === false) { | |
| 166 | + throw new PHPExcel_Writer_Exception("Could not open file $pFilename for writing."); | |
| 167 | + } | |
| 171 | 168 | |
| 172 | - // Write data | |
| 173 | - fwrite($fileHandle, $this->generateSheetData()); | |
| 169 | + // Write headers | |
| 170 | + fwrite($fileHandle, $this->generateHTMLHeader(!$this->_useInlineCss)); | |
| 174 | 171 | |
| 175 | - // Write footer | |
| 176 | - fwrite($fileHandle, $this->generateHTMLFooter()); | |
| 172 | + // Write navigation (tabs) | |
| 173 | + if ((!$this->_isPdf) && ($this->_generateSheetNavigationBlock)) { | |
| 174 | + fwrite($fileHandle, $this->generateNavigation()); | |
| 175 | + } | |
| 177 | 176 | |
| 178 | - // Close file | |
| 179 | - fclose($fileHandle); | |
| 177 | + // Write data | |
| 178 | + fwrite($fileHandle, $this->generateSheetData()); | |
| 180 | 179 | |
| 181 | - PHPExcel_Calculation::setArrayReturnType($saveArrayReturnType); | |
| 182 | - PHPExcel_Calculation::getInstance($this->phpExcel)->getDebugLog()->setWriteDebugLog($saveDebugLog); | |
| 183 | - } | |
| 180 | + // Write footer | |
| 181 | + fwrite($fileHandle, $this->generateHTMLFooter()); | |
| 184 | 182 | |
| 185 | - /** | |
| 186 | - * Map VAlign | |
| 187 | - * | |
| 188 | - * @param string $vAlign Vertical alignment | |
| 189 | - * @return string | |
| 190 | - */ | |
| 191 | - private function mapVAlign($vAlign) | |
| 192 | - { | |
| 193 | - switch ($vAlign) { | |
| 194 | - case PHPExcel_Style_Alignment::VERTICAL_BOTTOM: | |
| 195 | - return 'bottom'; | |
| 196 | - case PHPExcel_Style_Alignment::VERTICAL_TOP: | |
| 197 | - return 'top'; | |
| 198 | - case PHPExcel_Style_Alignment::VERTICAL_CENTER: | |
| 199 | - case PHPExcel_Style_Alignment::VERTICAL_JUSTIFY: | |
| 200 | - return 'middle'; | |
| 201 | - default: | |
| 202 | - return 'baseline'; | |
| 203 | - } | |
| 204 | - } | |
| 183 | + // Close file | |
| 184 | + fclose($fileHandle); | |
| 205 | 185 | |
| 206 | - /** | |
| 207 | - * Map HAlign | |
| 208 | - * | |
| 209 | - * @param string $hAlign Horizontal alignment | |
| 210 | - * @return string|false | |
| 211 | - */ | |
| 212 | - private function mapHAlign($hAlign) | |
| 213 | - { | |
| 214 | - switch ($hAlign) { | |
| 215 | - case PHPExcel_Style_Alignment::HORIZONTAL_GENERAL: | |
| 216 | - return false; | |
| 217 | - case PHPExcel_Style_Alignment::HORIZONTAL_LEFT: | |
| 218 | - return 'left'; | |
| 219 | - case PHPExcel_Style_Alignment::HORIZONTAL_RIGHT: | |
| 220 | - return 'right'; | |
| 221 | - case PHPExcel_Style_Alignment::HORIZONTAL_CENTER: | |
| 222 | - case PHPExcel_Style_Alignment::HORIZONTAL_CENTER_CONTINUOUS: | |
| 223 | - return 'center'; | |
| 224 | - case PHPExcel_Style_Alignment::HORIZONTAL_JUSTIFY: | |
| 225 | - return 'justify'; | |
| 226 | - default: | |
| 227 | - return false; | |
| 228 | - } | |
| 229 | - } | |
| 186 | + PHPExcel_Calculation::setArrayReturnType($saveArrayReturnType); | |
| 187 | + PHPExcel_Calculation::getInstance($this->_phpExcel)->getDebugLog()->setWriteDebugLog($saveDebugLog); | |
| 188 | + } | |
| 230 | 189 | |
| 231 | - /** | |
| 232 | - * Map border style | |
| 233 | - * | |
| 234 | - * @param int $borderStyle Sheet index | |
| 235 | - * @return string | |
| 236 | - */ | |
| 237 | - private function mapBorderStyle($borderStyle) | |
| 238 | - { | |
| 239 | - switch ($borderStyle) { | |
| 240 | - case PHPExcel_Style_Border::BORDER_NONE: | |
| 241 | - return 'none'; | |
| 242 | - case PHPExcel_Style_Border::BORDER_DASHDOT: | |
| 243 | - return '1px dashed'; | |
| 244 | - case PHPExcel_Style_Border::BORDER_DASHDOTDOT: | |
| 245 | - return '1px dotted'; | |
| 246 | - case PHPExcel_Style_Border::BORDER_DASHED: | |
| 247 | - return '1px dashed'; | |
| 248 | - case PHPExcel_Style_Border::BORDER_DOTTED: | |
| 249 | - return '1px dotted'; | |
| 250 | - case PHPExcel_Style_Border::BORDER_DOUBLE: | |
| 251 | - return '3px double'; | |
| 252 | - case PHPExcel_Style_Border::BORDER_HAIR: | |
| 253 | - return '1px solid'; | |
| 254 | - case PHPExcel_Style_Border::BORDER_MEDIUM: | |
| 255 | - return '2px solid'; | |
| 256 | - case PHPExcel_Style_Border::BORDER_MEDIUMDASHDOT: | |
| 257 | - return '2px dashed'; | |
| 258 | - case PHPExcel_Style_Border::BORDER_MEDIUMDASHDOTDOT: | |
| 259 | - return '2px dotted'; | |
| 260 | - case PHPExcel_Style_Border::BORDER_MEDIUMDASHED: | |
| 261 | - return '2px dashed'; | |
| 262 | - case PHPExcel_Style_Border::BORDER_SLANTDASHDOT: | |
| 263 | - return '2px dashed'; | |
| 264 | - case PHPExcel_Style_Border::BORDER_THICK: | |
| 265 | - return '3px solid'; | |
| 266 | - case PHPExcel_Style_Border::BORDER_THIN: | |
| 267 | - return '1px solid'; | |
| 268 | - default: | |
| 269 | - // map others to thin | |
| 270 | - return '1px solid'; | |
| 271 | - } | |
| 272 | - } | |
| 190 | + /** | |
| 191 | + * Map VAlign | |
| 192 | + * | |
| 193 | + * @param string $vAlign Vertical alignment | |
| 194 | + * @return string | |
| 195 | + */ | |
| 196 | + private function _mapVAlign($vAlign) { | |
| 197 | + switch ($vAlign) { | |
| 198 | + case PHPExcel_Style_Alignment::VERTICAL_BOTTOM: return 'bottom'; | |
| 199 | + case PHPExcel_Style_Alignment::VERTICAL_TOP: return 'top'; | |
| 200 | + case PHPExcel_Style_Alignment::VERTICAL_CENTER: | |
| 201 | + case PHPExcel_Style_Alignment::VERTICAL_JUSTIFY: return 'middle'; | |
| 202 | + default: return 'baseline'; | |
| 203 | + } | |
| 204 | + } | |
| 273 | 205 | |
| 274 | - /** | |
| 275 | - * Get sheet index | |
| 276 | - * | |
| 277 | - * @return int | |
| 278 | - */ | |
| 279 | - public function getSheetIndex() | |
| 280 | - { | |
| 281 | - return $this->sheetIndex; | |
| 282 | - } | |
| 206 | + /** | |
| 207 | + * Map HAlign | |
| 208 | + * | |
| 209 | + * @param string $hAlign Horizontal alignment | |
| 210 | + * @return string|false | |
| 211 | + */ | |
| 212 | + private function _mapHAlign($hAlign) { | |
| 213 | + switch ($hAlign) { | |
| 214 | + case PHPExcel_Style_Alignment::HORIZONTAL_GENERAL: return false; | |
| 215 | + case PHPExcel_Style_Alignment::HORIZONTAL_LEFT: return 'left'; | |
| 216 | + case PHPExcel_Style_Alignment::HORIZONTAL_RIGHT: return 'right'; | |
| 217 | + case PHPExcel_Style_Alignment::HORIZONTAL_CENTER: | |
| 218 | + case PHPExcel_Style_Alignment::HORIZONTAL_CENTER_CONTINUOUS: return 'center'; | |
| 219 | + case PHPExcel_Style_Alignment::HORIZONTAL_JUSTIFY: return 'justify'; | |
| 220 | + default: return false; | |
| 221 | + } | |
| 222 | + } | |
| 283 | 223 | |
| 284 | - /** | |
| 285 | - * Set sheet index | |
| 286 | - * | |
| 287 | - * @param int $pValue Sheet index | |
| 288 | - * @return PHPExcel_Writer_HTML | |
| 289 | - */ | |
| 290 | - public function setSheetIndex($pValue = 0) | |
| 291 | - { | |
| 292 | - $this->sheetIndex = $pValue; | |
| 293 | - return $this; | |
| 294 | - } | |
| 224 | + /** | |
| 225 | + * Map border style | |
| 226 | + * | |
| 227 | + * @param int $borderStyle Sheet index | |
| 228 | + * @return string | |
| 229 | + */ | |
| 230 | + private function _mapBorderStyle($borderStyle) { | |
| 231 | + switch ($borderStyle) { | |
| 232 | + case PHPExcel_Style_Border::BORDER_NONE: return 'none'; | |
| 233 | + case PHPExcel_Style_Border::BORDER_DASHDOT: return '1px dashed'; | |
| 234 | + case PHPExcel_Style_Border::BORDER_DASHDOTDOT: return '1px dotted'; | |
| 235 | + case PHPExcel_Style_Border::BORDER_DASHED: return '1px dashed'; | |
| 236 | + case PHPExcel_Style_Border::BORDER_DOTTED: return '1px dotted'; | |
| 237 | + case PHPExcel_Style_Border::BORDER_DOUBLE: return '3px double'; | |
| 238 | + case PHPExcel_Style_Border::BORDER_HAIR: return '1px solid'; | |
| 239 | + case PHPExcel_Style_Border::BORDER_MEDIUM: return '2px solid'; | |
| 240 | + case PHPExcel_Style_Border::BORDER_MEDIUMDASHDOT: return '2px dashed'; | |
| 241 | + case PHPExcel_Style_Border::BORDER_MEDIUMDASHDOTDOT: return '2px dotted'; | |
| 242 | + case PHPExcel_Style_Border::BORDER_MEDIUMDASHED: return '2px dashed'; | |
| 243 | + case PHPExcel_Style_Border::BORDER_SLANTDASHDOT: return '2px dashed'; | |
| 244 | + case PHPExcel_Style_Border::BORDER_THICK: return '3px solid'; | |
| 245 | + case PHPExcel_Style_Border::BORDER_THIN: return '1px solid'; | |
| 246 | + default: return '1px solid'; // map others to thin | |
| 247 | + } | |
| 248 | + } | |
| 295 | 249 | |
| 296 | - /** | |
| 297 | - * Get sheet index | |
| 298 | - * | |
| 299 | - * @return boolean | |
| 300 | - */ | |
| 301 | - public function getGenerateSheetNavigationBlock() | |
| 302 | - { | |
| 303 | - return $this->generateSheetNavigationBlock; | |
| 304 | - } | |
| 250 | + /** | |
| 251 | + * Get sheet index | |
| 252 | + * | |
| 253 | + * @return int | |
| 254 | + */ | |
| 255 | + public function getSheetIndex() { | |
| 256 | + return $this->_sheetIndex; | |
| 257 | + } | |
| 305 | 258 | |
| 306 | - /** | |
| 307 | - * Set sheet index | |
| 308 | - * | |
| 309 | - * @param boolean $pValue Flag indicating whether the sheet navigation block should be generated or not | |
| 310 | - * @return PHPExcel_Writer_HTML | |
| 311 | - */ | |
| 312 | - public function setGenerateSheetNavigationBlock($pValue = true) | |
| 313 | - { | |
| 314 | - $this->generateSheetNavigationBlock = (bool) $pValue; | |
| 315 | - return $this; | |
| 316 | - } | |
| 259 | + /** | |
| 260 | + * Set sheet index | |
| 261 | + * | |
| 262 | + * @param int $pValue Sheet index | |
| 263 | + * @return PHPExcel_Writer_HTML | |
| 264 | + */ | |
| 265 | + public function setSheetIndex($pValue = 0) { | |
| 266 | + $this->_sheetIndex = $pValue; | |
| 267 | + return $this; | |
| 268 | + } | |
| 317 | 269 | |
| 318 | - /** | |
| 319 | - * Write all sheets (resets sheetIndex to NULL) | |
| 320 | - */ | |
| 321 | - public function writeAllSheets() | |
| 322 | - { | |
| 323 | - $this->sheetIndex = null; | |
| 324 | - return $this; | |
| 325 | - } | |
| 270 | + /** | |
| 271 | + * Get sheet index | |
| 272 | + * | |
| 273 | + * @return boolean | |
| 274 | + */ | |
| 275 | + public function getGenerateSheetNavigationBlock() { | |
| 276 | + return $this->_generateSheetNavigationBlock; | |
| 277 | + } | |
| 326 | 278 | |
| 327 | - /** | |
| 328 | - * Generate HTML header | |
| 329 | - * | |
| 330 | - * @param boolean $pIncludeStyles Include styles? | |
| 331 | - * @return string | |
| 332 | - * @throws PHPExcel_Writer_Exception | |
| 333 | - */ | |
| 334 | - public function generateHTMLHeader($pIncludeStyles = false) | |
| 335 | - { | |
| 336 | - // PHPExcel object known? | |
| 337 | - if (is_null($this->phpExcel)) { | |
| 338 | - throw new PHPExcel_Writer_Exception('Internal PHPExcel object not set to an instance of an object.'); | |
| 339 | - } | |
| 279 | + /** | |
| 280 | + * Set sheet index | |
| 281 | + * | |
| 282 | + * @param boolean $pValue Flag indicating whether the sheet navigation block should be generated or not | |
| 283 | + * @return PHPExcel_Writer_HTML | |
| 284 | + */ | |
| 285 | + public function setGenerateSheetNavigationBlock($pValue = true) { | |
| 286 | + $this->_generateSheetNavigationBlock = (bool) $pValue; | |
| 287 | + return $this; | |
| 288 | + } | |
| 340 | 289 | |
| 341 | - // Construct HTML | |
| 342 | - $properties = $this->phpExcel->getProperties(); | |
| 343 | - $html = '<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">' . PHP_EOL; | |
| 344 | - $html .= '<!-- Generated by PHPExcel - http://www.phpexcel.net -->' . PHP_EOL; | |
| 345 | - $html .= '<html>' . PHP_EOL; | |
| 346 | - $html .= ' <head>' . PHP_EOL; | |
| 347 | - $html .= ' <meta http-equiv="Content-Type" content="text/html; charset=utf-8">' . PHP_EOL; | |
| 348 | - if ($properties->getTitle() > '') { | |
| 349 | - $html .= ' <title>' . htmlspecialchars($properties->getTitle()) . '</title>' . PHP_EOL; | |
| 350 | - } | |
| 351 | - if ($properties->getCreator() > '') { | |
| 352 | - $html .= ' <meta name="author" content="' . htmlspecialchars($properties->getCreator()) . '" />' . PHP_EOL; | |
| 353 | - } | |
| 354 | - if ($properties->getTitle() > '') { | |
| 355 | - $html .= ' <meta name="title" content="' . htmlspecialchars($properties->getTitle()) . '" />' . PHP_EOL; | |
| 356 | - } | |
| 357 | - if ($properties->getDescription() > '') { | |
| 358 | - $html .= ' <meta name="description" content="' . htmlspecialchars($properties->getDescription()) . '" />' . PHP_EOL; | |
| 359 | - } | |
| 360 | - if ($properties->getSubject() > '') { | |
| 361 | - $html .= ' <meta name="subject" content="' . htmlspecialchars($properties->getSubject()) . '" />' . PHP_EOL; | |
| 362 | - } | |
| 363 | - if ($properties->getKeywords() > '') { | |
| 364 | - $html .= ' <meta name="keywords" content="' . htmlspecialchars($properties->getKeywords()) . '" />' . PHP_EOL; | |
| 365 | - } | |
| 366 | - if ($properties->getCategory() > '') { | |
| 367 | - $html .= ' <meta name="category" content="' . htmlspecialchars($properties->getCategory()) . '" />' . PHP_EOL; | |
| 368 | - } | |
| 369 | - if ($properties->getCompany() > '') { | |
| 370 | - $html .= ' <meta name="company" content="' . htmlspecialchars($properties->getCompany()) . '" />' . PHP_EOL; | |
| 371 | - } | |
| 372 | - if ($properties->getManager() > '') { | |
| 373 | - $html .= ' <meta name="manager" content="' . htmlspecialchars($properties->getManager()) . '" />' . PHP_EOL; | |
| 374 | - } | |
| 290 | + /** | |
| 291 | + * Write all sheets (resets sheetIndex to NULL) | |
| 292 | + */ | |
| 293 | + public function writeAllSheets() { | |
| 294 | + $this->_sheetIndex = null; | |
| 295 | + return $this; | |
| 296 | + } | |
| 375 | 297 | |
| 376 | - if ($pIncludeStyles) { | |
| 377 | - $html .= $this->generateStyles(true); | |
| 378 | - } | |
| 298 | + /** | |
| 299 | + * Generate HTML header | |
| 300 | + * | |
| 301 | + * @param boolean $pIncludeStyles Include styles? | |
| 302 | + * @return string | |
| 303 | + * @throws PHPExcel_Writer_Exception | |
| 304 | + */ | |
| 305 | + public function generateHTMLHeader($pIncludeStyles = false) { | |
| 306 | + // PHPExcel object known? | |
| 307 | + if (is_null($this->_phpExcel)) { | |
| 308 | + throw new PHPExcel_Writer_Exception('Internal PHPExcel object not set to an instance of an object.'); | |
| 309 | + } | |
| 379 | 310 | |
| 380 | - $html .= ' </head>' . PHP_EOL; | |
| 381 | - $html .= '' . PHP_EOL; | |
| 382 | - $html .= ' <body>' . PHP_EOL; | |
| 311 | + // Construct HTML | |
| 312 | + $properties = $this->_phpExcel->getProperties(); | |
| 313 | + $html = '<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">' . PHP_EOL; | |
| 314 | + $html .= '<!-- Generated by PHPExcel - http://www.phpexcel.net -->' . PHP_EOL; | |
| 315 | + $html .= '<html>' . PHP_EOL; | |
| 316 | + $html .= ' <head>' . PHP_EOL; | |
| 317 | + $html .= ' <meta http-equiv="Content-Type" content="text/html; charset=utf-8">' . PHP_EOL; | |
| 318 | + if ($properties->getTitle() > '') | |
| 319 | + $html .= ' <title>' . htmlspecialchars($properties->getTitle()) . '</title>' . PHP_EOL; | |
| 383 | 320 | |
| 384 | - return $html; | |
| 385 | - } | |
| 321 | + if ($properties->getCreator() > '') | |
| 322 | + $html .= ' <meta name="author" content="' . htmlspecialchars($properties->getCreator()) . '" />' . PHP_EOL; | |
| 323 | + if ($properties->getTitle() > '') | |
| 324 | + $html .= ' <meta name="title" content="' . htmlspecialchars($properties->getTitle()) . '" />' . PHP_EOL; | |
| 325 | + if ($properties->getDescription() > '') | |
| 326 | + $html .= ' <meta name="description" content="' . htmlspecialchars($properties->getDescription()) . '" />' . PHP_EOL; | |
| 327 | + if ($properties->getSubject() > '') | |
| 328 | + $html .= ' <meta name="subject" content="' . htmlspecialchars($properties->getSubject()) . '" />' . PHP_EOL; | |
| 329 | + if ($properties->getKeywords() > '') | |
| 330 | + $html .= ' <meta name="keywords" content="' . htmlspecialchars($properties->getKeywords()) . '" />' . PHP_EOL; | |
| 331 | + if ($properties->getCategory() > '') | |
| 332 | + $html .= ' <meta name="category" content="' . htmlspecialchars($properties->getCategory()) . '" />' . PHP_EOL; | |
| 333 | + if ($properties->getCompany() > '') | |
| 334 | + $html .= ' <meta name="company" content="' . htmlspecialchars($properties->getCompany()) . '" />' . PHP_EOL; | |
| 335 | + if ($properties->getManager() > '') | |
| 336 | + $html .= ' <meta name="manager" content="' . htmlspecialchars($properties->getManager()) . '" />' . PHP_EOL; | |
| 386 | 337 | |
| 387 | - /** | |
| 388 | - * Generate sheet data | |
| 389 | - * | |
| 390 | - * @return string | |
| 391 | - * @throws PHPExcel_Writer_Exception | |
| 392 | - */ | |
| 393 | - public function generateSheetData() | |
| 394 | - { | |
| 395 | - // PHPExcel object known? | |
| 396 | - if (is_null($this->phpExcel)) { | |
| 397 | - throw new PHPExcel_Writer_Exception('Internal PHPExcel object not set to an instance of an object.'); | |
| 398 | - } | |
| 338 | + if ($pIncludeStyles) { | |
| 339 | + $html .= $this->generateStyles(true); | |
| 340 | + } | |
| 399 | 341 | |
| 400 | - // Ensure that Spans have been calculated? | |
| 401 | - if ($this->sheetIndex !== null || !$this->spansAreCalculated) { | |
| 402 | - $this->calculateSpans(); | |
| 403 | - } | |
| 342 | + $html .= ' </head>' . PHP_EOL; | |
| 343 | + $html .= '' . PHP_EOL; | |
| 344 | + $html .= ' <body>' . PHP_EOL; | |
| 404 | 345 | |
| 405 | - // Fetch sheets | |
| 406 | - $sheets = array(); | |
| 407 | - if (is_null($this->sheetIndex)) { | |
| 408 | - $sheets = $this->phpExcel->getAllSheets(); | |
| 409 | - } else { | |
| 410 | - $sheets[] = $this->phpExcel->getSheet($this->sheetIndex); | |
| 411 | - } | |
| 346 | + // Return | |
| 347 | + return $html; | |
| 348 | + } | |
| 412 | 349 | |
| 413 | - // Construct HTML | |
| 414 | - $html = ''; | |
| 350 | + /** | |
| 351 | + * Generate sheet data | |
| 352 | + * | |
| 353 | + * @return string | |
| 354 | + * @throws PHPExcel_Writer_Exception | |
| 355 | + */ | |
| 356 | + public function generateSheetData() { | |
| 357 | + // PHPExcel object known? | |
| 358 | + if (is_null($this->_phpExcel)) { | |
| 359 | + throw new PHPExcel_Writer_Exception('Internal PHPExcel object not set to an instance of an object.'); | |
| 360 | + } | |
| 415 | 361 | |
| 416 | - // Loop all sheets | |
| 417 | - $sheetId = 0; | |
| 418 | - foreach ($sheets as $sheet) { | |
| 419 | - // Write table header | |
| 420 | - $html .= $this->generateTableHeader($sheet); | |
| 362 | + // Ensure that Spans have been calculated? | |
| 363 | + if (!$this->_spansAreCalculated) { | |
| 364 | + $this->_calculateSpans(); | |
| 365 | + } | |
| 421 | 366 | |
| 422 | - // Get worksheet dimension | |
| 423 | - $dimension = explode(':', $sheet->calculateWorksheetDimension()); | |
| 424 | - $dimension[0] = PHPExcel_Cell::coordinateFromString($dimension[0]); | |
| 425 | - $dimension[0][0] = PHPExcel_Cell::columnIndexFromString($dimension[0][0]) - 1; | |
| 426 | - $dimension[1] = PHPExcel_Cell::coordinateFromString($dimension[1]); | |
| 427 | - $dimension[1][0] = PHPExcel_Cell::columnIndexFromString($dimension[1][0]) - 1; | |
| 367 | + // Fetch sheets | |
| 368 | + $sheets = array(); | |
| 369 | + if (is_null($this->_sheetIndex)) { | |
| 370 | + $sheets = $this->_phpExcel->getAllSheets(); | |
| 371 | + } else { | |
| 372 | + $sheets[] = $this->_phpExcel->getSheet($this->_sheetIndex); | |
| 373 | + } | |
| 428 | 374 | |
| 429 | - // row min,max | |
| 430 | - $rowMin = $dimension[0][1]; | |
| 431 | - $rowMax = $dimension[1][1]; | |
| 375 | + // Construct HTML | |
| 376 | + $html = ''; | |
| 432 | 377 | |
| 433 | - // calculate start of <tbody>, <thead> | |
| 434 | - $tbodyStart = $rowMin; | |
| 435 | - $theadStart = $theadEnd = 0; // default: no <thead> no </thead> | |
| 436 | - if ($sheet->getPageSetup()->isRowsToRepeatAtTopSet()) { | |
| 437 | - $rowsToRepeatAtTop = $sheet->getPageSetup()->getRowsToRepeatAtTop(); | |
| 378 | + // Loop all sheets | |
| 379 | + $sheetId = 0; | |
| 380 | + foreach ($sheets as $sheet) { | |
| 381 | + // Write table header | |
| 382 | + $html .= $this->_generateTableHeader($sheet); | |
| 438 | 383 | |
| 439 | - // we can only support repeating rows that start at top row | |
| 440 | - if ($rowsToRepeatAtTop[0] == 1) { | |
| 441 | - $theadStart = $rowsToRepeatAtTop[0]; | |
| 442 | - $theadEnd = $rowsToRepeatAtTop[1]; | |
| 443 | - $tbodyStart = $rowsToRepeatAtTop[1] + 1; | |
| 444 | - } | |
| 445 | - } | |
| 384 | + // Get worksheet dimension | |
| 385 | + $dimension = explode(':', $sheet->calculateWorksheetDimension()); | |
| 386 | + $dimension[0] = PHPExcel_Cell::coordinateFromString($dimension[0]); | |
| 387 | + $dimension[0][0] = PHPExcel_Cell::columnIndexFromString($dimension[0][0]) - 1; | |
| 388 | + $dimension[1] = PHPExcel_Cell::coordinateFromString($dimension[1]); | |
| 389 | + $dimension[1][0] = PHPExcel_Cell::columnIndexFromString($dimension[1][0]) - 1; | |
| 446 | 390 | |
| 447 | - // Loop through cells | |
| 448 | - $row = $rowMin-1; | |
| 449 | - while ($row++ < $rowMax) { | |
| 450 | - // <thead> ? | |
| 451 | - if ($row == $theadStart) { | |
| 452 | - $html .= ' <thead>' . PHP_EOL; | |
| 391 | + // row min,max | |
| 392 | + $rowMin = $dimension[0][1]; | |
| 393 | + $rowMax = $dimension[1][1]; | |
| 394 | + | |
| 395 | + // calculate start of <tbody>, <thead> | |
| 396 | + $tbodyStart = $rowMin; | |
| 397 | + $theadStart = $theadEnd = 0; // default: no <thead> no </thead> | |
| 398 | + if ($sheet->getPageSetup()->isRowsToRepeatAtTopSet()) { | |
| 399 | + $rowsToRepeatAtTop = $sheet->getPageSetup()->getRowsToRepeatAtTop(); | |
| 400 | + | |
| 401 | + // we can only support repeating rows that start at top row | |
| 402 | + if ($rowsToRepeatAtTop[0] == 1) { | |
| 403 | + $theadStart = $rowsToRepeatAtTop[0]; | |
| 404 | + $theadEnd = $rowsToRepeatAtTop[1]; | |
| 405 | + $tbodyStart = $rowsToRepeatAtTop[1] + 1; | |
| 406 | + } | |
| 407 | + } | |
| 408 | + | |
| 409 | + // Loop through cells | |
| 410 | + $row = $rowMin-1; | |
| 411 | + while($row++ < $rowMax) { | |
| 412 | + // <thead> ? | |
| 413 | + if ($row == $theadStart) { | |
| 414 | + $html .= ' <thead>' . PHP_EOL; | |
| 453 | 415 | $cellType = 'th'; |
| 454 | - } | |
| 416 | + } | |
| 455 | 417 | |
| 456 | - // <tbody> ? | |
| 457 | - if ($row == $tbodyStart) { | |
| 458 | - $html .= ' <tbody>' . PHP_EOL; | |
| 418 | + // <tbody> ? | |
| 419 | + if ($row == $tbodyStart) { | |
| 420 | + $html .= ' <tbody>' . PHP_EOL; | |
| 459 | 421 | $cellType = 'td'; |
| 460 | - } | |
| 422 | + } | |
| 461 | 423 | |
| 462 | - // Write row if there are HTML table cells in it | |
| 463 | - if (!isset($this->isSpannedRow[$sheet->getParent()->getIndex($sheet)][$row])) { | |
| 464 | - // Start a new rowData | |
| 465 | - $rowData = array(); | |
| 466 | - // Loop through columns | |
| 467 | - $column = $dimension[0][0] - 1; | |
| 468 | - while ($column++ < $dimension[1][0]) { | |
| 469 | - // Cell exists? | |
| 470 | - if ($sheet->cellExistsByColumnAndRow($column, $row)) { | |
| 471 | - $rowData[$column] = PHPExcel_Cell::stringFromColumnIndex($column) . $row; | |
| 472 | - } else { | |
| 473 | - $rowData[$column] = ''; | |
| 474 | - } | |
| 475 | - } | |
| 476 | - $html .= $this->generateRow($sheet, $rowData, $row - 1, $cellType); | |
| 477 | - } | |
| 424 | + // Write row if there are HTML table cells in it | |
| 425 | + if ( !isset($this->_isSpannedRow[$sheet->getParent()->getIndex($sheet)][$row]) ) { | |
| 426 | + // Start a new rowData | |
| 427 | + $rowData = array(); | |
| 428 | + // Loop through columns | |
| 429 | + $column = $dimension[0][0] - 1; | |
| 430 | + while($column++ < $dimension[1][0]) { | |
| 431 | + // Cell exists? | |
| 432 | + if ($sheet->cellExistsByColumnAndRow($column, $row)) { | |
| 433 | + $rowData[$column] = PHPExcel_Cell::stringFromColumnIndex($column) . $row; | |
| 434 | + } else { | |
| 435 | + $rowData[$column] = ''; | |
| 436 | + } | |
| 437 | + } | |
| 438 | + $html .= $this->_generateRow($sheet, $rowData, $row - 1, $cellType); | |
| 439 | + } | |
| 478 | 440 | |
| 479 | - // </thead> ? | |
| 480 | - if ($row == $theadEnd) { | |
| 481 | - $html .= ' </thead>' . PHP_EOL; | |
| 482 | - } | |
| 483 | - } | |
| 484 | - $html .= $this->extendRowsForChartsAndImages($sheet, $row); | |
| 441 | + // </thead> ? | |
| 442 | + if ($row == $theadEnd) { | |
| 443 | + $html .= ' </thead>' . PHP_EOL; | |
| 444 | + } | |
| 445 | + } | |
| 446 | + $html .= $this->_extendRowsForChartsAndImages($sheet, $row); | |
| 485 | 447 | |
| 486 | - // Close table body. | |
| 487 | - $html .= ' </tbody>' . PHP_EOL; | |
| 448 | + // Close table body. | |
| 449 | + $html .= ' </tbody>' . PHP_EOL; | |
| 488 | 450 | |
| 489 | - // Write table footer | |
| 490 | - $html .= $this->generateTableFooter(); | |
| 451 | + // Write table footer | |
| 452 | + $html .= $this->_generateTableFooter(); | |
| 491 | 453 | |
| 492 | - // Writing PDF? | |
| 493 | - if ($this->isPdf) { | |
| 494 | - if (is_null($this->sheetIndex) && $sheetId + 1 < $this->phpExcel->getSheetCount()) { | |
| 495 | - $html .= '<div style="page-break-before:always" />'; | |
| 496 | - } | |
| 497 | - } | |
| 454 | + // Writing PDF? | |
| 455 | + if ($this->_isPdf) { | |
| 456 | + if (is_null($this->_sheetIndex) && $sheetId + 1 < $this->_phpExcel->getSheetCount()) { | |
| 457 | + $html .= '<div style="page-break-before:always" />'; | |
| 458 | + } | |
| 459 | + } | |
| 498 | 460 | |
| 499 | - // Next sheet | |
| 500 | - ++$sheetId; | |
| 501 | - } | |
| 461 | + // Next sheet | |
| 462 | + ++$sheetId; | |
| 463 | + } | |
| 502 | 464 | |
| 503 | - return $html; | |
| 504 | - } | |
| 465 | + // Return | |
| 466 | + return $html; | |
| 467 | + } | |
| 505 | 468 | |
| 506 | - /** | |
| 507 | - * Generate sheet tabs | |
| 508 | - * | |
| 509 | - * @return string | |
| 510 | - * @throws PHPExcel_Writer_Exception | |
| 511 | - */ | |
| 512 | - public function generateNavigation() | |
| 513 | - { | |
| 514 | - // PHPExcel object known? | |
| 515 | - if (is_null($this->phpExcel)) { | |
| 516 | - throw new PHPExcel_Writer_Exception('Internal PHPExcel object not set to an instance of an object.'); | |
| 517 | - } | |
| 469 | + /** | |
| 470 | + * Generate sheet tabs | |
| 471 | + * | |
| 472 | + * @return string | |
| 473 | + * @throws PHPExcel_Writer_Exception | |
| 474 | + */ | |
| 475 | + public function generateNavigation() | |
| 476 | + { | |
| 477 | + // PHPExcel object known? | |
| 478 | + if (is_null($this->_phpExcel)) { | |
| 479 | + throw new PHPExcel_Writer_Exception('Internal PHPExcel object not set to an instance of an object.'); | |
| 480 | + } | |
| 518 | 481 | |
| 519 | - // Fetch sheets | |
| 520 | - $sheets = array(); | |
| 521 | - if (is_null($this->sheetIndex)) { | |
| 522 | - $sheets = $this->phpExcel->getAllSheets(); | |
| 523 | - } else { | |
| 524 | - $sheets[] = $this->phpExcel->getSheet($this->sheetIndex); | |
| 525 | - } | |
| 482 | + // Fetch sheets | |
| 483 | + $sheets = array(); | |
| 484 | + if (is_null($this->_sheetIndex)) { | |
| 485 | + $sheets = $this->_phpExcel->getAllSheets(); | |
| 486 | + } else { | |
| 487 | + $sheets[] = $this->_phpExcel->getSheet($this->_sheetIndex); | |
| 488 | + } | |
| 526 | 489 | |
| 527 | - // Construct HTML | |
| 528 | - $html = ''; | |
| 490 | + // Construct HTML | |
| 491 | + $html = ''; | |
| 529 | 492 | |
| 530 | - // Only if there are more than 1 sheets | |
| 531 | - if (count($sheets) > 1) { | |
| 532 | - // Loop all sheets | |
| 533 | - $sheetId = 0; | |
| 493 | + // Only if there are more than 1 sheets | |
| 494 | + if (count($sheets) > 1) { | |
| 495 | + // Loop all sheets | |
| 496 | + $sheetId = 0; | |
| 534 | 497 | |
| 535 | - $html .= '<ul class="navigation">' . PHP_EOL; | |
| 498 | + $html .= '<ul class="navigation">' . PHP_EOL; | |
| 536 | 499 | |
| 537 | - foreach ($sheets as $sheet) { | |
| 538 | - $html .= ' <li class="sheet' . $sheetId . '"><a href="#sheet' . $sheetId . '">' . $sheet->getTitle() . '</a></li>' . PHP_EOL; | |
| 539 | - ++$sheetId; | |
| 540 | - } | |
| 500 | + foreach ($sheets as $sheet) { | |
| 501 | + $html .= ' <li class="sheet' . $sheetId . '"><a href="#sheet' . $sheetId . '">' . $sheet->getTitle() . '</a></li>' . PHP_EOL; | |
| 502 | + ++$sheetId; | |
| 503 | + } | |
| 541 | 504 | |
| 542 | - $html .= '</ul>' . PHP_EOL; | |
| 543 | - } | |
| 505 | + $html .= '</ul>' . PHP_EOL; | |
| 506 | + } | |
| 544 | 507 | |
| 545 | - return $html; | |
| 546 | - } | |
| 508 | + return $html; | |
| 509 | + } | |
| 547 | 510 | |
| 548 | - private function extendRowsForChartsAndImages(PHPExcel_Worksheet $pSheet, $row) | |
| 549 | - { | |
| 550 | - $rowMax = $row; | |
| 551 | - $colMax = 'A'; | |
| 552 | - if ($this->includeCharts) { | |
| 553 | - foreach ($pSheet->getChartCollection() as $chart) { | |
| 554 | - if ($chart instanceof PHPExcel_Chart) { | |
| 555 | - $chartCoordinates = $chart->getTopLeftPosition(); | |
| 556 | - $chartTL = PHPExcel_Cell::coordinateFromString($chartCoordinates['cell']); | |
| 557 | - $chartCol = PHPExcel_Cell::columnIndexFromString($chartTL[0]); | |
| 558 | - if ($chartTL[1] > $rowMax) { | |
| 559 | - $rowMax = $chartTL[1]; | |
| 560 | - if ($chartCol > PHPExcel_Cell::columnIndexFromString($colMax)) { | |
| 561 | - $colMax = $chartTL[0]; | |
| 562 | - } | |
| 563 | - } | |
| 564 | - } | |
| 565 | - } | |
| 566 | - } | |
| 511 | + private function _extendRowsForChartsAndImages(PHPExcel_Worksheet $pSheet, $row) { | |
| 512 | + $rowMax = $row; | |
| 513 | + $colMax = 'A'; | |
| 514 | + if ($this->_includeCharts) { | |
| 515 | + foreach ($pSheet->getChartCollection() as $chart) { | |
| 516 | + if ($chart instanceof PHPExcel_Chart) { | |
| 517 | + $chartCoordinates = $chart->getTopLeftPosition(); | |
| 518 | + $chartTL = PHPExcel_Cell::coordinateFromString($chartCoordinates['cell']); | |
| 519 | + $chartCol = PHPExcel_Cell::columnIndexFromString($chartTL[0]); | |
| 520 | + if ($chartTL[1] > $rowMax) { | |
| 521 | + $rowMax = $chartTL[1]; | |
| 522 | + if ($chartCol > PHPExcel_Cell::columnIndexFromString($colMax)) { | |
| 523 | + $colMax = $chartTL[0]; | |
| 524 | + } | |
| 525 | + } | |
| 526 | + } | |
| 527 | + } | |
| 528 | + } | |
| 567 | 529 | |
| 568 | - foreach ($pSheet->getDrawingCollection() as $drawing) { | |
| 569 | - if ($drawing instanceof PHPExcel_Worksheet_Drawing) { | |
| 570 | - $imageTL = PHPExcel_Cell::coordinateFromString($drawing->getCoordinates()); | |
| 571 | - $imageCol = PHPExcel_Cell::columnIndexFromString($imageTL[0]); | |
| 572 | - if ($imageTL[1] > $rowMax) { | |
| 573 | - $rowMax = $imageTL[1]; | |
| 574 | - if ($imageCol > PHPExcel_Cell::columnIndexFromString($colMax)) { | |
| 575 | - $colMax = $imageTL[0]; | |
| 576 | - } | |
| 577 | - } | |
| 578 | - } | |
| 579 | - } | |
| 530 | + foreach ($pSheet->getDrawingCollection() as $drawing) { | |
| 531 | + if ($drawing instanceof PHPExcel_Worksheet_Drawing) { | |
| 532 | + $imageTL = PHPExcel_Cell::coordinateFromString($drawing->getCoordinates()); | |
| 533 | + $imageCol = PHPExcel_Cell::columnIndexFromString($imageTL[0]); | |
| 534 | + if ($imageTL[1] > $rowMax) { | |
| 535 | + $rowMax = $imageTL[1]; | |
| 536 | + if ($imageCol > PHPExcel_Cell::columnIndexFromString($colMax)) { | |
| 537 | + $colMax = $imageTL[0]; | |
| 538 | + } | |
| 539 | + } | |
| 540 | + } | |
| 541 | + } | |
| 542 | + $html = ''; | |
| 543 | + $colMax++; | |
| 544 | + while ($row < $rowMax) { | |
| 545 | + $html .= '<tr>'; | |
| 546 | + for ($col = 'A'; $col != $colMax; ++$col) { | |
| 547 | + $html .= '<td>'; | |
| 548 | + $html .= $this->_writeImageInCell($pSheet, $col.$row); | |
| 549 | + if ($this->_includeCharts) { | |
| 550 | + $html .= $this->_writeChartInCell($pSheet, $col.$row); | |
| 551 | + } | |
| 552 | + $html .= '</td>'; | |
| 553 | + } | |
| 554 | + ++$row; | |
| 555 | + $html .= '</tr>'; | |
| 556 | + } | |
| 557 | + return $html; | |
| 558 | + } | |
| 580 | 559 | |
| 581 | - $html = ''; | |
| 582 | - $colMax++; | |
| 583 | - while ($row <= $rowMax) { | |
| 584 | - $html .= '<tr>'; | |
| 585 | - for ($col = 'A'; $col != $colMax; ++$col) { | |
| 586 | - $html .= '<td>'; | |
| 587 | - $html .= $this->writeImageInCell($pSheet, $col.$row); | |
| 588 | - if ($this->includeCharts) { | |
| 589 | - $html .= $this->writeChartInCell($pSheet, $col.$row); | |
| 590 | - } | |
| 591 | - $html .= '</td>'; | |
| 592 | - } | |
| 593 | - ++$row; | |
| 594 | - $html .= '</tr>'; | |
| 595 | - } | |
| 596 | - return $html; | |
| 597 | - } | |
| 598 | 560 | |
| 561 | + /** | |
| 562 | + * Generate image tag in cell | |
| 563 | + * | |
| 564 | + * @param PHPExcel_Worksheet $pSheet PHPExcel_Worksheet | |
| 565 | + * @param string $coordinates Cell coordinates | |
| 566 | + * @return string | |
| 567 | + * @throws PHPExcel_Writer_Exception | |
| 568 | + */ | |
| 569 | + private function _writeImageInCell(PHPExcel_Worksheet $pSheet, $coordinates) { | |
| 570 | + // Construct HTML | |
| 571 | + $html = ''; | |
| 599 | 572 | |
| 600 | - /** | |
| 601 | - * Generate image tag in cell | |
| 602 | - * | |
| 603 | - * @param PHPExcel_Worksheet $pSheet PHPExcel_Worksheet | |
| 604 | - * @param string $coordinates Cell coordinates | |
| 605 | - * @return string | |
| 606 | - * @throws PHPExcel_Writer_Exception | |
| 607 | - */ | |
| 608 | - private function writeImageInCell(PHPExcel_Worksheet $pSheet, $coordinates) | |
| 609 | - { | |
| 610 | - // Construct HTML | |
| 611 | - $html = ''; | |
| 573 | + // Write images | |
| 574 | + foreach ($pSheet->getDrawingCollection() as $drawing) { | |
| 575 | + if ($drawing instanceof PHPExcel_Worksheet_Drawing) { | |
| 576 | + if ($drawing->getCoordinates() == $coordinates) { | |
| 577 | + $filename = $drawing->getPath(); | |
| 612 | 578 | |
| 613 | - // Write images | |
| 614 | - foreach ($pSheet->getDrawingCollection() as $drawing) { | |
| 615 | - if ($drawing instanceof PHPExcel_Worksheet_Drawing) { | |
| 616 | - if ($drawing->getCoordinates() == $coordinates) { | |
| 617 | - $filename = $drawing->getPath(); | |
| 579 | + // Strip off eventual '.' | |
| 580 | + if (substr($filename, 0, 1) == '.') { | |
| 581 | + $filename = substr($filename, 1); | |
| 582 | + } | |
| 618 | 583 | |
| 619 | - // Strip off eventual '.' | |
| 620 | - if (substr($filename, 0, 1) == '.') { | |
| 621 | - $filename = substr($filename, 1); | |
| 622 | - } | |
| 584 | + // Prepend images root | |
| 585 | + $filename = $this->getImagesRoot() . $filename; | |
| 623 | 586 | |
| 624 | - // Prepend images root | |
| 625 | - $filename = $this->getImagesRoot() . $filename; | |
| 587 | + // Strip off eventual '.' | |
| 588 | + if (substr($filename, 0, 1) == '.' && substr($filename, 0, 2) != './') { | |
| 589 | + $filename = substr($filename, 1); | |
| 590 | + } | |
| 626 | 591 | |
| 627 | - // Strip off eventual '.' | |
| 628 | - if (substr($filename, 0, 1) == '.' && substr($filename, 0, 2) != './') { | |
| 629 | - $filename = substr($filename, 1); | |
| 630 | - } | |
| 592 | + // Convert UTF8 data to PCDATA | |
| 593 | + $filename = htmlspecialchars($filename); | |
| 631 | 594 | |
| 632 | - // Convert UTF8 data to PCDATA | |
| 633 | - $filename = htmlspecialchars($filename); | |
| 595 | + $html .= PHP_EOL; | |
| 596 | + if ((!$this->_embedImages) || ($this->_isPdf)) { | |
| 597 | + $imageData = $filename; | |
| 598 | + } else { | |
| 599 | + $imageDetails = getimagesize($filename); | |
| 600 | + if ($fp = fopen($filename,"rb", 0)) { | |
| 601 | + $picture = fread($fp,filesize($filename)); | |
| 602 | + fclose($fp); | |
| 603 | + // base64 encode the binary data, then break it | |
| 604 | + // into chunks according to RFC 2045 semantics | |
| 605 | + $base64 = chunk_split(base64_encode($picture)); | |
| 606 | + $imageData = 'data:'.$imageDetails['mime'].';base64,' . $base64; | |
| 607 | + } else { | |
| 608 | + $imageData = $filename; | |
| 609 | + } | |
| 610 | + } | |
| 634 | 611 | |
| 635 | - $html .= PHP_EOL; | |
| 636 | - if ((!$this->embedImages) || ($this->isPdf)) { | |
| 637 | - $imageData = $filename; | |
| 638 | - } else { | |
| 639 | - $imageDetails = getimagesize($filename); | |
| 640 | - if ($fp = fopen($filename, "rb", 0)) { | |
| 641 | - $picture = fread($fp, filesize($filename)); | |
| 642 | - fclose($fp); | |
| 643 | - // base64 encode the binary data, then break it | |
| 644 | - // into chunks according to RFC 2045 semantics | |
| 645 | - $base64 = chunk_split(base64_encode($picture)); | |
| 646 | - $imageData = 'data:'.$imageDetails['mime'].';base64,' . $base64; | |
| 647 | - } else { | |
| 648 | - $imageData = $filename; | |
| 649 | - } | |
| 650 | - } | |
| 651 | - | |
| 652 | - $html .= '<div style="position: relative;">'; | |
| 653 | - $html .= '<img style="position: absolute; z-index: 1; left: ' . | |
| 654 | - $drawing->getOffsetX() . 'px; top: ' . $drawing->getOffsetY() . 'px; width: ' . | |
| 655 | - $drawing->getWidth() . 'px; height: ' . $drawing->getHeight() . 'px;" src="' . | |
| 612 | + $html .= '<div style="position: relative;">'; | |
| 613 | + $html .= '<img style="position: absolute; z-index: 1; left: ' . | |
| 614 | + $drawing->getOffsetX() . 'px; top: ' . $drawing->getOffsetY() . 'px; width: ' . | |
| 615 | + $drawing->getWidth() . 'px; height: ' . $drawing->getHeight() . 'px;" src="' . | |
| 656 | 616 | $imageData . '" border="0" />'; |
| 657 | - $html .= '</div>'; | |
| 658 | - } | |
| 659 | - } elseif ($drawing instanceof PHPExcel_Worksheet_MemoryDrawing) { | |
| 660 | - if ($drawing->getCoordinates() != $coordinates) { | |
| 661 | - continue; | |
| 662 | - } | |
| 663 | - ob_start(); // Let's start output buffering. | |
| 664 | - imagepng($drawing->getImageResource()); // This will normally output the image, but because of ob_start(), it won't. | |
| 665 | - $contents = ob_get_contents(); // Instead, output above is saved to $contents | |
| 666 | - ob_end_clean(); // End the output buffer. | |
| 617 | + $html .= '</div>'; | |
| 618 | + } | |
| 619 | + } | |
| 620 | + } | |
| 667 | 621 | |
| 668 | - $dataUri = "data:image/jpeg;base64," . base64_encode($contents); | |
| 622 | + // Return | |
| 623 | + return $html; | |
| 624 | + } | |
| 669 | 625 | |
| 670 | - // Because of the nature of tables, width is more important than height. | |
| 671 | - // max-width: 100% ensures that image doesnt overflow containing cell | |
| 672 | - // width: X sets width of supplied image. | |
| 673 | - // As a result, images bigger than cell will be contained and images smaller will not get stretched | |
| 674 | - $html .= '<img src="'.$dataUri.'" style="max-width:100%;width:'.$drawing->getWidth().'px;" />'; | |
| 675 | - } | |
| 676 | - } | |
| 626 | + /** | |
| 627 | + * Generate chart tag in cell | |
| 628 | + * | |
| 629 | + * @param PHPExcel_Worksheet $pSheet PHPExcel_Worksheet | |
| 630 | + * @param string $coordinates Cell coordinates | |
| 631 | + * @return string | |
| 632 | + * @throws PHPExcel_Writer_Exception | |
| 633 | + */ | |
| 634 | + private function _writeChartInCell(PHPExcel_Worksheet $pSheet, $coordinates) { | |
| 635 | + // Construct HTML | |
| 636 | + $html = ''; | |
| 677 | 637 | |
| 678 | - return $html; | |
| 679 | - } | |
| 638 | + // Write charts | |
| 639 | + foreach ($pSheet->getChartCollection() as $chart) { | |
| 640 | + if ($chart instanceof PHPExcel_Chart) { | |
| 641 | + $chartCoordinates = $chart->getTopLeftPosition(); | |
| 642 | + if ($chartCoordinates['cell'] == $coordinates) { | |
| 643 | + $chartFileName = PHPExcel_Shared_File::sys_get_temp_dir().'/'.uniqid().'.png'; | |
| 644 | + if (!$chart->render($chartFileName)) { | |
| 645 | + return; | |
| 646 | + } | |
| 680 | 647 | |
| 681 | - /** | |
| 682 | - * Generate chart tag in cell | |
| 683 | - * | |
| 684 | - * @param PHPExcel_Worksheet $pSheet PHPExcel_Worksheet | |
| 685 | - * @param string $coordinates Cell coordinates | |
| 686 | - * @return string | |
| 687 | - * @throws PHPExcel_Writer_Exception | |
| 688 | - */ | |
| 689 | - private function writeChartInCell(PHPExcel_Worksheet $pSheet, $coordinates) | |
| 690 | - { | |
| 691 | - // Construct HTML | |
| 692 | - $html = ''; | |
| 648 | + $html .= PHP_EOL; | |
| 649 | + $imageDetails = getimagesize($chartFileName); | |
| 650 | + if ($fp = fopen($chartFileName,"rb", 0)) { | |
| 651 | + $picture = fread($fp,filesize($chartFileName)); | |
| 652 | + fclose($fp); | |
| 653 | + // base64 encode the binary data, then break it | |
| 654 | + // into chunks according to RFC 2045 semantics | |
| 655 | + $base64 = chunk_split(base64_encode($picture)); | |
| 656 | + $imageData = 'data:'.$imageDetails['mime'].';base64,' . $base64; | |
| 693 | 657 | |
| 694 | - // Write charts | |
| 695 | - foreach ($pSheet->getChartCollection() as $chart) { | |
| 696 | - if ($chart instanceof PHPExcel_Chart) { | |
| 697 | - $chartCoordinates = $chart->getTopLeftPosition(); | |
| 698 | - if ($chartCoordinates['cell'] == $coordinates) { | |
| 699 | - $chartFileName = PHPExcel_Shared_File::sys_get_temp_dir().'/'.uniqid().'.png'; | |
| 700 | - if (!$chart->render($chartFileName)) { | |
| 701 | - return; | |
| 702 | - } | |
| 658 | + $html .= '<div style="position: relative;">'; | |
| 659 | + $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; | |
| 660 | + $html .= '</div>'; | |
| 703 | 661 | |
| 704 | - $html .= PHP_EOL; | |
| 705 | - $imageDetails = getimagesize($chartFileName); | |
| 706 | - if ($fp = fopen($chartFileName, "rb", 0)) { | |
| 707 | - $picture = fread($fp, filesize($chartFileName)); | |
| 708 | - fclose($fp); | |
| 709 | - // base64 encode the binary data, then break it | |
| 710 | - // into chunks according to RFC 2045 semantics | |
| 711 | - $base64 = chunk_split(base64_encode($picture)); | |
| 712 | - $imageData = 'data:'.$imageDetails['mime'].';base64,' . $base64; | |
| 662 | + unlink($chartFileName); | |
| 663 | + } | |
| 664 | + } | |
| 665 | + } | |
| 666 | + } | |
| 713 | 667 | |
| 714 | - $html .= '<div style="position: relative;">'; | |
| 715 | - $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; | |
| 716 | - $html .= '</div>'; | |
| 668 | + // Return | |
| 669 | + return $html; | |
| 670 | + } | |
| 717 | 671 | |
| 718 | - unlink($chartFileName); | |
| 719 | - } | |
| 720 | - } | |
| 721 | - } | |
| 722 | - } | |
| 672 | + /** | |
| 673 | + * Generate CSS styles | |
| 674 | + * | |
| 675 | + * @param boolean $generateSurroundingHTML Generate surrounding HTML tags? (<style> and </style>) | |
| 676 | + * @return string | |
| 677 | + * @throws PHPExcel_Writer_Exception | |
| 678 | + */ | |
| 679 | + public function generateStyles($generateSurroundingHTML = true) { | |
| 680 | + // PHPExcel object known? | |
| 681 | + if (is_null($this->_phpExcel)) { | |
| 682 | + throw new PHPExcel_Writer_Exception('Internal PHPExcel object not set to an instance of an object.'); | |
| 683 | + } | |
| 723 | 684 | |
| 724 | - // Return | |
| 725 | - return $html; | |
| 726 | - } | |
| 685 | + // Build CSS | |
| 686 | + $css = $this->buildCSS($generateSurroundingHTML); | |
| 727 | 687 | |
| 728 | - /** | |
| 729 | - * Generate CSS styles | |
| 730 | - * | |
| 731 | - * @param boolean $generateSurroundingHTML Generate surrounding HTML tags? (<style> and </style>) | |
| 732 | - * @return string | |
| 733 | - * @throws PHPExcel_Writer_Exception | |
| 734 | - */ | |
| 735 | - public function generateStyles($generateSurroundingHTML = true) | |
| 736 | - { | |
| 737 | - // PHPExcel object known? | |
| 738 | - if (is_null($this->phpExcel)) { | |
| 739 | - throw new PHPExcel_Writer_Exception('Internal PHPExcel object not set to an instance of an object.'); | |
| 740 | - } | |
| 688 | + // Construct HTML | |
| 689 | + $html = ''; | |
| 741 | 690 | |
| 742 | - // Build CSS | |
| 743 | - $css = $this->buildCSS($generateSurroundingHTML); | |
| 691 | + // Start styles | |
| 692 | + if ($generateSurroundingHTML) { | |
| 693 | + $html .= ' <style type="text/css">' . PHP_EOL; | |
| 694 | + $html .= ' html { ' . $this->_assembleCSS($css['html']) . ' }' . PHP_EOL; | |
| 695 | + } | |
| 744 | 696 | |
| 745 | - // Construct HTML | |
| 746 | - $html = ''; | |
| 697 | + // Write all other styles | |
| 698 | + foreach ($css as $styleName => $styleDefinition) { | |
| 699 | + if ($styleName != 'html') { | |
| 700 | + $html .= ' ' . $styleName . ' { ' . $this->_assembleCSS($styleDefinition) . ' }' . PHP_EOL; | |
| 701 | + } | |
| 702 | + } | |
| 747 | 703 | |
| 748 | - // Start styles | |
| 749 | - if ($generateSurroundingHTML) { | |
| 750 | - $html .= ' <style type="text/css">' . PHP_EOL; | |
| 751 | - $html .= ' html { ' . $this->assembleCSS($css['html']) . ' }' . PHP_EOL; | |
| 752 | - } | |
| 704 | + // End styles | |
| 705 | + if ($generateSurroundingHTML) { | |
| 706 | + $html .= ' </style>' . PHP_EOL; | |
| 707 | + } | |
| 753 | 708 | |
| 754 | - // Write all other styles | |
| 755 | - foreach ($css as $styleName => $styleDefinition) { | |
| 756 | - if ($styleName != 'html') { | |
| 757 | - $html .= ' ' . $styleName . ' { ' . $this->assembleCSS($styleDefinition) . ' }' . PHP_EOL; | |
| 758 | - } | |
| 759 | - } | |
| 709 | + // Return | |
| 710 | + return $html; | |
| 711 | + } | |
| 760 | 712 | |
| 761 | - // End styles | |
| 762 | - if ($generateSurroundingHTML) { | |
| 763 | - $html .= ' </style>' . PHP_EOL; | |
| 764 | - } | |
| 713 | + /** | |
| 714 | + * Build CSS styles | |
| 715 | + * | |
| 716 | + * @param boolean $generateSurroundingHTML Generate surrounding HTML style? (html { }) | |
| 717 | + * @return array | |
| 718 | + * @throws PHPExcel_Writer_Exception | |
| 719 | + */ | |
| 720 | + public function buildCSS($generateSurroundingHTML = true) { | |
| 721 | + // PHPExcel object known? | |
| 722 | + if (is_null($this->_phpExcel)) { | |
| 723 | + throw new PHPExcel_Writer_Exception('Internal PHPExcel object not set to an instance of an object.'); | |
| 724 | + } | |
| 765 | 725 | |
| 766 | - // Return | |
| 767 | - return $html; | |
| 768 | - } | |
| 726 | + // Cached? | |
| 727 | + if (!is_null($this->_cssStyles)) { | |
| 728 | + return $this->_cssStyles; | |
| 729 | + } | |
| 769 | 730 | |
| 770 | - /** | |
| 771 | - * Build CSS styles | |
| 772 | - * | |
| 773 | - * @param boolean $generateSurroundingHTML Generate surrounding HTML style? (html { }) | |
| 774 | - * @return array | |
| 775 | - * @throws PHPExcel_Writer_Exception | |
| 776 | - */ | |
| 777 | - public function buildCSS($generateSurroundingHTML = true) | |
| 778 | - { | |
| 779 | - // PHPExcel object known? | |
| 780 | - if (is_null($this->phpExcel)) { | |
| 781 | - throw new PHPExcel_Writer_Exception('Internal PHPExcel object not set to an instance of an object.'); | |
| 782 | - } | |
| 731 | + // Ensure that spans have been calculated | |
| 732 | + if (!$this->_spansAreCalculated) { | |
| 733 | + $this->_calculateSpans(); | |
| 734 | + } | |
| 783 | 735 | |
| 784 | - // Cached? | |
| 785 | - if (!is_null($this->cssStyles)) { | |
| 786 | - return $this->cssStyles; | |
| 787 | - } | |
| 736 | + // Construct CSS | |
| 737 | + $css = array(); | |
| 788 | 738 | |
| 789 | - // Ensure that spans have been calculated | |
| 790 | - if (!$this->spansAreCalculated) { | |
| 791 | - $this->calculateSpans(); | |
| 792 | - } | |
| 739 | + // Start styles | |
| 740 | + if ($generateSurroundingHTML) { | |
| 741 | + // html { } | |
| 742 | + $css['html']['font-family'] = 'Calibri, Arial, Helvetica, sans-serif'; | |
| 743 | + $css['html']['font-size'] = '11pt'; | |
| 744 | + $css['html']['background-color'] = 'white'; | |
| 745 | + } | |
| 793 | 746 | |
| 794 | - // Construct CSS | |
| 795 | - $css = array(); | |
| 796 | 747 | |
| 797 | - // Start styles | |
| 798 | - if ($generateSurroundingHTML) { | |
| 799 | - // html { } | |
| 800 | - $css['html']['font-family'] = 'Calibri, Arial, Helvetica, sans-serif'; | |
| 801 | - $css['html']['font-size'] = '11pt'; | |
| 802 | - $css['html']['background-color'] = 'white'; | |
| 803 | - } | |
| 748 | + // table { } | |
| 749 | + $css['table']['border-collapse'] = 'collapse'; | |
| 750 | + if (!$this->_isPdf) { | |
| 751 | + $css['table']['page-break-after'] = 'always'; | |
| 752 | + } | |
| 804 | 753 | |
| 754 | + // .gridlines td { } | |
| 755 | + $css['.gridlines td']['border'] = '1px dotted black'; | |
| 756 | + $css['.gridlines th']['border'] = '1px dotted black'; | |
| 805 | 757 | |
| 806 | - // table { } | |
| 807 | - $css['table']['border-collapse'] = 'collapse'; | |
| 808 | - if (!$this->isPdf) { | |
| 809 | - $css['table']['page-break-after'] = 'always'; | |
| 810 | - } | |
| 758 | + // .b {} | |
| 759 | + $css['.b']['text-align'] = 'center'; // BOOL | |
| 811 | 760 | |
| 812 | - // .gridlines td { } | |
| 813 | - $css['.gridlines td']['border'] = '1px dotted black'; | |
| 814 | - $css['.gridlines th']['border'] = '1px dotted black'; | |
| 761 | + // .e {} | |
| 762 | + $css['.e']['text-align'] = 'center'; // ERROR | |
| 815 | 763 | |
| 816 | - // .b {} | |
| 817 | - $css['.b']['text-align'] = 'center'; // BOOL | |
| 764 | + // .f {} | |
| 765 | + $css['.f']['text-align'] = 'right'; // FORMULA | |
| 818 | 766 | |
| 819 | - // .e {} | |
| 820 | - $css['.e']['text-align'] = 'center'; // ERROR | |
| 767 | + // .inlineStr {} | |
| 768 | + $css['.inlineStr']['text-align'] = 'left'; // INLINE | |
| 821 | 769 | |
| 822 | - // .f {} | |
| 823 | - $css['.f']['text-align'] = 'right'; // FORMULA | |
| 770 | + // .n {} | |
| 771 | + $css['.n']['text-align'] = 'right'; // NUMERIC | |
| 824 | 772 | |
| 825 | - // .inlineStr {} | |
| 826 | - $css['.inlineStr']['text-align'] = 'left'; // INLINE | |
| 773 | + // .s {} | |
| 774 | + $css['.s']['text-align'] = 'left'; // STRING | |
| 827 | 775 | |
| 828 | - // .n {} | |
| 829 | - $css['.n']['text-align'] = 'right'; // NUMERIC | |
| 776 | + // Calculate cell style hashes | |
| 777 | + foreach ($this->_phpExcel->getCellXfCollection() as $index => $style) { | |
| 778 | + $css['td.style' . $index] = $this->_createCSSStyle( $style ); | |
| 779 | + $css['th.style' . $index] = $this->_createCSSStyle( $style ); | |
| 780 | + } | |
| 830 | 781 | |
| 831 | - // .s {} | |
| 832 | - $css['.s']['text-align'] = 'left'; // STRING | |
| 782 | + // Fetch sheets | |
| 783 | + $sheets = array(); | |
| 784 | + if (is_null($this->_sheetIndex)) { | |
| 785 | + $sheets = $this->_phpExcel->getAllSheets(); | |
| 786 | + } else { | |
| 787 | + $sheets[] = $this->_phpExcel->getSheet($this->_sheetIndex); | |
| 788 | + } | |
| 833 | 789 | |
| 834 | - // Calculate cell style hashes | |
| 835 | - foreach ($this->phpExcel->getCellXfCollection() as $index => $style) { | |
| 836 | - $css['td.style' . $index] = $this->createCSSStyle($style); | |
| 837 | - $css['th.style' . $index] = $this->createCSSStyle($style); | |
| 838 | - } | |
| 790 | + // Build styles per sheet | |
| 791 | + foreach ($sheets as $sheet) { | |
| 792 | + // Calculate hash code | |
| 793 | + $sheetIndex = $sheet->getParent()->getIndex($sheet); | |
| 839 | 794 | |
| 840 | - // Fetch sheets | |
| 841 | - $sheets = array(); | |
| 842 | - if (is_null($this->sheetIndex)) { | |
| 843 | - $sheets = $this->phpExcel->getAllSheets(); | |
| 844 | - } else { | |
| 845 | - $sheets[] = $this->phpExcel->getSheet($this->sheetIndex); | |
| 846 | - } | |
| 795 | + // Build styles | |
| 796 | + // Calculate column widths | |
| 797 | + $sheet->calculateColumnWidths(); | |
| 847 | 798 | |
| 848 | - // Build styles per sheet | |
| 849 | - foreach ($sheets as $sheet) { | |
| 850 | - // Calculate hash code | |
| 851 | - $sheetIndex = $sheet->getParent()->getIndex($sheet); | |
| 799 | + // col elements, initialize | |
| 800 | + $highestColumnIndex = PHPExcel_Cell::columnIndexFromString($sheet->getHighestColumn()) - 1; | |
| 801 | + $column = -1; | |
| 802 | + while($column++ < $highestColumnIndex) { | |
| 803 | + $this->_columnWidths[$sheetIndex][$column] = 42; // approximation | |
| 804 | + $css['table.sheet' . $sheetIndex . ' col.col' . $column]['width'] = '42pt'; | |
| 805 | + } | |
| 852 | 806 | |
| 853 | - // Build styles | |
| 854 | - // Calculate column widths | |
| 855 | - $sheet->calculateColumnWidths(); | |
| 807 | + // col elements, loop through columnDimensions and set width | |
| 808 | + foreach ($sheet->getColumnDimensions() as $columnDimension) { | |
| 809 | + if (($width = PHPExcel_Shared_Drawing::cellDimensionToPixels($columnDimension->getWidth(), $this->_defaultFont)) >= 0) { | |
| 810 | + $width = PHPExcel_Shared_Drawing::pixelsToPoints($width); | |
| 811 | + $column = PHPExcel_Cell::columnIndexFromString($columnDimension->getColumnIndex()) - 1; | |
| 812 | + $this->_columnWidths[$sheetIndex][$column] = $width; | |
| 813 | + $css['table.sheet' . $sheetIndex . ' col.col' . $column]['width'] = $width . 'pt'; | |
| 856 | 814 | |
| 857 | - // col elements, initialize | |
| 858 | - $highestColumnIndex = PHPExcel_Cell::columnIndexFromString($sheet->getHighestColumn()) - 1; | |
| 859 | - $column = -1; | |
| 860 | - while ($column++ < $highestColumnIndex) { | |
| 861 | - $this->columnWidths[$sheetIndex][$column] = 42; // approximation | |
| 862 | - $css['table.sheet' . $sheetIndex . ' col.col' . $column]['width'] = '42pt'; | |
| 863 | - } | |
| 815 | + if ($columnDimension->getVisible() === false) { | |
| 816 | + $css['table.sheet' . $sheetIndex . ' col.col' . $column]['visibility'] = 'collapse'; | |
| 817 | + $css['table.sheet' . $sheetIndex . ' col.col' . $column]['*display'] = 'none'; // target IE6+7 | |
| 818 | + } | |
| 819 | + } | |
| 820 | + } | |
| 864 | 821 | |
| 865 | - // col elements, loop through columnDimensions and set width | |
| 866 | - foreach ($sheet->getColumnDimensions() as $columnDimension) { | |
| 867 | - if (($width = PHPExcel_Shared_Drawing::cellDimensionToPixels($columnDimension->getWidth(), $this->defaultFont)) >= 0) { | |
| 868 | - $width = PHPExcel_Shared_Drawing::pixelsToPoints($width); | |
| 869 | - $column = PHPExcel_Cell::columnIndexFromString($columnDimension->getColumnIndex()) - 1; | |
| 870 | - $this->columnWidths[$sheetIndex][$column] = $width; | |
| 871 | - $css['table.sheet' . $sheetIndex . ' col.col' . $column]['width'] = $width . 'pt'; | |
| 822 | + // Default row height | |
| 823 | + $rowDimension = $sheet->getDefaultRowDimension(); | |
| 872 | 824 | |
| 873 | - if ($columnDimension->getVisible() === false) { | |
| 874 | - $css['table.sheet' . $sheetIndex . ' col.col' . $column]['visibility'] = 'collapse'; | |
| 875 | - $css['table.sheet' . $sheetIndex . ' col.col' . $column]['*display'] = 'none'; // target IE6+7 | |
| 876 | - } | |
| 877 | - } | |
| 878 | - } | |
| 825 | + // table.sheetN tr { } | |
| 826 | + $css['table.sheet' . $sheetIndex . ' tr'] = array(); | |
| 879 | 827 | |
| 880 | - // Default row height | |
| 881 | - $rowDimension = $sheet->getDefaultRowDimension(); | |
| 828 | + if ($rowDimension->getRowHeight() == -1) { | |
| 829 | + $pt_height = PHPExcel_Shared_Font::getDefaultRowHeightByFont($this->_phpExcel->getDefaultStyle()->getFont()); | |
| 830 | + } else { | |
| 831 | + $pt_height = $rowDimension->getRowHeight(); | |
| 832 | + } | |
| 833 | + $css['table.sheet' . $sheetIndex . ' tr']['height'] = $pt_height . 'pt'; | |
| 834 | + if ($rowDimension->getVisible() === false) { | |
| 835 | + $css['table.sheet' . $sheetIndex . ' tr']['display'] = 'none'; | |
| 836 | + $css['table.sheet' . $sheetIndex . ' tr']['visibility'] = 'hidden'; | |
| 837 | + } | |
| 882 | 838 | |
| 883 | - // table.sheetN tr { } | |
| 884 | - $css['table.sheet' . $sheetIndex . ' tr'] = array(); | |
| 839 | + // Calculate row heights | |
| 840 | + foreach ($sheet->getRowDimensions() as $rowDimension) { | |
| 841 | + $row = $rowDimension->getRowIndex() - 1; | |
| 885 | 842 | |
| 886 | - if ($rowDimension->getRowHeight() == -1) { | |
| 887 | - $pt_height = PHPExcel_Shared_Font::getDefaultRowHeightByFont($this->phpExcel->getDefaultStyle()->getFont()); | |
| 888 | - } else { | |
| 889 | - $pt_height = $rowDimension->getRowHeight(); | |
| 890 | - } | |
| 891 | - $css['table.sheet' . $sheetIndex . ' tr']['height'] = $pt_height . 'pt'; | |
| 892 | - if ($rowDimension->getVisible() === false) { | |
| 893 | - $css['table.sheet' . $sheetIndex . ' tr']['display'] = 'none'; | |
| 894 | - $css['table.sheet' . $sheetIndex . ' tr']['visibility'] = 'hidden'; | |
| 895 | - } | |
| 843 | + // table.sheetN tr.rowYYYYYY { } | |
| 844 | + $css['table.sheet' . $sheetIndex . ' tr.row' . $row] = array(); | |
| 896 | 845 | |
| 897 | - // Calculate row heights | |
| 898 | - foreach ($sheet->getRowDimensions() as $rowDimension) { | |
| 899 | - $row = $rowDimension->getRowIndex() - 1; | |
| 846 | + if ($rowDimension->getRowHeight() == -1) { | |
| 847 | + $pt_height = PHPExcel_Shared_Font::getDefaultRowHeightByFont($this->_phpExcel->getDefaultStyle()->getFont()); | |
| 848 | + } else { | |
| 849 | + $pt_height = $rowDimension->getRowHeight(); | |
| 850 | + } | |
| 851 | + $css['table.sheet' . $sheetIndex . ' tr.row' . $row]['height'] = $pt_height . 'pt'; | |
| 852 | + if ($rowDimension->getVisible() === false) { | |
| 853 | + $css['table.sheet' . $sheetIndex . ' tr.row' . $row]['display'] = 'none'; | |
| 854 | + $css['table.sheet' . $sheetIndex . ' tr.row' . $row]['visibility'] = 'hidden'; | |
| 855 | + } | |
| 856 | + } | |
| 857 | + } | |
| 900 | 858 | |
| 901 | - // table.sheetN tr.rowYYYYYY { } | |
| 902 | - $css['table.sheet' . $sheetIndex . ' tr.row' . $row] = array(); | |
| 859 | + // Cache | |
| 860 | + if (is_null($this->_cssStyles)) { | |
| 861 | + $this->_cssStyles = $css; | |
| 862 | + } | |
| 903 | 863 | |
| 904 | - if ($rowDimension->getRowHeight() == -1) { | |
| 905 | - $pt_height = PHPExcel_Shared_Font::getDefaultRowHeightByFont($this->phpExcel->getDefaultStyle()->getFont()); | |
| 906 | - } else { | |
| 907 | - $pt_height = $rowDimension->getRowHeight(); | |
| 908 | - } | |
| 909 | - $css['table.sheet' . $sheetIndex . ' tr.row' . $row]['height'] = $pt_height . 'pt'; | |
| 910 | - if ($rowDimension->getVisible() === false) { | |
| 911 | - $css['table.sheet' . $sheetIndex . ' tr.row' . $row]['display'] = 'none'; | |
| 912 | - $css['table.sheet' . $sheetIndex . ' tr.row' . $row]['visibility'] = 'hidden'; | |
| 913 | - } | |
| 914 | - } | |
| 915 | - } | |
| 864 | + // Return | |
| 865 | + return $css; | |
| 866 | + } | |
| 916 | 867 | |
| 917 | - // Cache | |
| 918 | - if (is_null($this->cssStyles)) { | |
| 919 | - $this->cssStyles = $css; | |
| 920 | - } | |
| 868 | + /** | |
| 869 | + * Create CSS style | |
| 870 | + * | |
| 871 | + * @param PHPExcel_Style $pStyle PHPExcel_Style | |
| 872 | + * @return array | |
| 873 | + */ | |
| 874 | + private function _createCSSStyle(PHPExcel_Style $pStyle) { | |
| 875 | + // Construct CSS | |
| 876 | + $css = ''; | |
| 921 | 877 | |
| 922 | - // Return | |
| 923 | - return $css; | |
| 924 | - } | |
| 878 | + // Create CSS | |
| 879 | + $css = array_merge( | |
| 880 | + $this->_createCSSStyleAlignment($pStyle->getAlignment()) | |
| 881 | + , $this->_createCSSStyleBorders($pStyle->getBorders()) | |
| 882 | + , $this->_createCSSStyleFont($pStyle->getFont()) | |
| 883 | + , $this->_createCSSStyleFill($pStyle->getFill()) | |
| 884 | + ); | |
| 925 | 885 | |
| 926 | - /** | |
| 927 | - * Create CSS style | |
| 928 | - * | |
| 929 | - * @param PHPExcel_Style $pStyle PHPExcel_Style | |
| 930 | - * @return array | |
| 931 | - */ | |
| 932 | - private function createCSSStyle(PHPExcel_Style $pStyle) | |
| 933 | - { | |
| 934 | - // Construct CSS | |
| 935 | - $css = ''; | |
| 886 | + // Return | |
| 887 | + return $css; | |
| 888 | + } | |
| 936 | 889 | |
| 937 | - // Create CSS | |
| 938 | - $css = array_merge( | |
| 939 | - $this->createCSSStyleAlignment($pStyle->getAlignment()), | |
| 940 | - $this->createCSSStyleBorders($pStyle->getBorders()), | |
| 941 | - $this->createCSSStyleFont($pStyle->getFont()), | |
| 942 | - $this->createCSSStyleFill($pStyle->getFill()) | |
| 943 | - ); | |
| 890 | + /** | |
| 891 | + * Create CSS style (PHPExcel_Style_Alignment) | |
| 892 | + * | |
| 893 | + * @param PHPExcel_Style_Alignment $pStyle PHPExcel_Style_Alignment | |
| 894 | + * @return array | |
| 895 | + */ | |
| 896 | + private function _createCSSStyleAlignment(PHPExcel_Style_Alignment $pStyle) { | |
| 897 | + // Construct CSS | |
| 898 | + $css = array(); | |
| 944 | 899 | |
| 945 | - // Return | |
| 946 | - return $css; | |
| 947 | - } | |
| 900 | + // Create CSS | |
| 901 | + $css['vertical-align'] = $this->_mapVAlign($pStyle->getVertical()); | |
| 902 | + if ($textAlign = $this->_mapHAlign($pStyle->getHorizontal())) { | |
| 903 | + $css['text-align'] = $textAlign; | |
| 904 | + if(in_array($textAlign,array('left','right'))) | |
| 905 | + $css['padding-'.$textAlign] = (string)((int)$pStyle->getIndent() * 9).'px'; | |
| 906 | + } | |
| 948 | 907 | |
| 949 | - /** | |
| 950 | - * Create CSS style (PHPExcel_Style_Alignment) | |
| 951 | - * | |
| 952 | - * @param PHPExcel_Style_Alignment $pStyle PHPExcel_Style_Alignment | |
| 953 | - * @return array | |
| 954 | - */ | |
| 955 | - private function createCSSStyleAlignment(PHPExcel_Style_Alignment $pStyle) | |
| 956 | - { | |
| 957 | - // Construct CSS | |
| 958 | - $css = array(); | |
| 908 | + // Return | |
| 909 | + return $css; | |
| 910 | + } | |
| 959 | 911 | |
| 960 | - // Create CSS | |
| 961 | - $css['vertical-align'] = $this->mapVAlign($pStyle->getVertical()); | |
| 962 | - if ($textAlign = $this->mapHAlign($pStyle->getHorizontal())) { | |
| 963 | - $css['text-align'] = $textAlign; | |
| 964 | - if (in_array($textAlign, array('left', 'right'))) { | |
| 965 | - $css['padding-'.$textAlign] = (string)((int)$pStyle->getIndent() * 9).'px'; | |
| 966 | - } | |
| 967 | - } | |
| 912 | + /** | |
| 913 | + * Create CSS style (PHPExcel_Style_Font) | |
| 914 | + * | |
| 915 | + * @param PHPExcel_Style_Font $pStyle PHPExcel_Style_Font | |
| 916 | + * @return array | |
| 917 | + */ | |
| 918 | + private function _createCSSStyleFont(PHPExcel_Style_Font $pStyle) { | |
| 919 | + // Construct CSS | |
| 920 | + $css = array(); | |
| 968 | 921 | |
| 969 | - return $css; | |
| 970 | - } | |
| 922 | + // Create CSS | |
| 923 | + if ($pStyle->getBold()) { | |
| 924 | + $css['font-weight'] = 'bold'; | |
| 925 | + } | |
| 926 | + if ($pStyle->getUnderline() != PHPExcel_Style_Font::UNDERLINE_NONE && $pStyle->getStrikethrough()) { | |
| 927 | + $css['text-decoration'] = 'underline line-through'; | |
| 928 | + } else if ($pStyle->getUnderline() != PHPExcel_Style_Font::UNDERLINE_NONE) { | |
| 929 | + $css['text-decoration'] = 'underline'; | |
| 930 | + } else if ($pStyle->getStrikethrough()) { | |
| 931 | + $css['text-decoration'] = 'line-through'; | |
| 932 | + } | |
| 933 | + if ($pStyle->getItalic()) { | |
| 934 | + $css['font-style'] = 'italic'; | |
| 935 | + } | |
| 971 | 936 | |
| 972 | - /** | |
| 973 | - * Create CSS style (PHPExcel_Style_Font) | |
| 974 | - * | |
| 975 | - * @param PHPExcel_Style_Font $pStyle PHPExcel_Style_Font | |
| 976 | - * @return array | |
| 977 | - */ | |
| 978 | - private function createCSSStyleFont(PHPExcel_Style_Font $pStyle) | |
| 979 | - { | |
| 980 | - // Construct CSS | |
| 981 | - $css = array(); | |
| 937 | + $css['color'] = '#' . $pStyle->getColor()->getRGB(); | |
| 938 | + $css['font-family'] = '\'' . $pStyle->getName() . '\''; | |
| 939 | + $css['font-size'] = $pStyle->getSize() . 'pt'; | |
| 982 | 940 | |
| 983 | - // Create CSS | |
| 984 | - if ($pStyle->getBold()) { | |
| 985 | - $css['font-weight'] = 'bold'; | |
| 986 | - } | |
| 987 | - if ($pStyle->getUnderline() != PHPExcel_Style_Font::UNDERLINE_NONE && $pStyle->getStrikethrough()) { | |
| 988 | - $css['text-decoration'] = 'underline line-through'; | |
| 989 | - } elseif ($pStyle->getUnderline() != PHPExcel_Style_Font::UNDERLINE_NONE) { | |
| 990 | - $css['text-decoration'] = 'underline'; | |
| 991 | - } elseif ($pStyle->getStrikethrough()) { | |
| 992 | - $css['text-decoration'] = 'line-through'; | |
| 993 | - } | |
| 994 | - if ($pStyle->getItalic()) { | |
| 995 | - $css['font-style'] = 'italic'; | |
| 996 | - } | |
| 941 | + // Return | |
| 942 | + return $css; | |
| 943 | + } | |
| 997 | 944 | |
| 998 | - $css['color'] = '#' . $pStyle->getColor()->getRGB(); | |
| 999 | - $css['font-family'] = '\'' . $pStyle->getName() . '\''; | |
| 1000 | - $css['font-size'] = $pStyle->getSize() . 'pt'; | |
| 945 | + /** | |
| 946 | + * Create CSS style (PHPExcel_Style_Borders) | |
| 947 | + * | |
| 948 | + * @param PHPExcel_Style_Borders $pStyle PHPExcel_Style_Borders | |
| 949 | + * @return array | |
| 950 | + */ | |
| 951 | + private function _createCSSStyleBorders(PHPExcel_Style_Borders $pStyle) { | |
| 952 | + // Construct CSS | |
| 953 | + $css = array(); | |
| 1001 | 954 | |
| 1002 | - return $css; | |
| 1003 | - } | |
| 955 | + // Create CSS | |
| 956 | + $css['border-bottom'] = $this->_createCSSStyleBorder($pStyle->getBottom()); | |
| 957 | + $css['border-top'] = $this->_createCSSStyleBorder($pStyle->getTop()); | |
| 958 | + $css['border-left'] = $this->_createCSSStyleBorder($pStyle->getLeft()); | |
| 959 | + $css['border-right'] = $this->_createCSSStyleBorder($pStyle->getRight()); | |
| 1004 | 960 | |
| 1005 | - /** | |
| 1006 | - * Create CSS style (PHPExcel_Style_Borders) | |
| 1007 | - * | |
| 1008 | - * @param PHPExcel_Style_Borders $pStyle PHPExcel_Style_Borders | |
| 1009 | - * @return array | |
| 1010 | - */ | |
| 1011 | - private function createCSSStyleBorders(PHPExcel_Style_Borders $pStyle) | |
| 1012 | - { | |
| 1013 | - // Construct CSS | |
| 1014 | - $css = array(); | |
| 961 | + // Return | |
| 962 | + return $css; | |
| 963 | + } | |
| 1015 | 964 | |
| 1016 | - // Create CSS | |
| 1017 | - $css['border-bottom'] = $this->createCSSStyleBorder($pStyle->getBottom()); | |
| 1018 | - $css['border-top'] = $this->createCSSStyleBorder($pStyle->getTop()); | |
| 1019 | - $css['border-left'] = $this->createCSSStyleBorder($pStyle->getLeft()); | |
| 1020 | - $css['border-right'] = $this->createCSSStyleBorder($pStyle->getRight()); | |
| 965 | + /** | |
| 966 | + * Create CSS style (PHPExcel_Style_Border) | |
| 967 | + * | |
| 968 | + * @param PHPExcel_Style_Border $pStyle PHPExcel_Style_Border | |
| 969 | + * @return string | |
| 970 | + */ | |
| 971 | + private function _createCSSStyleBorder(PHPExcel_Style_Border $pStyle) { | |
| 972 | + // Create CSS | |
| 973 | +// $css = $this->_mapBorderStyle($pStyle->getBorderStyle()) . ' #' . $pStyle->getColor()->getRGB(); | |
| 974 | + // Create CSS - add !important to non-none border styles for merged cells | |
| 975 | + $borderStyle = $this->_mapBorderStyle($pStyle->getBorderStyle()); | |
| 976 | + $css = $borderStyle . ' #' . $pStyle->getColor()->getRGB() . (($borderStyle == 'none') ? '' : ' !important'); | |
| 1021 | 977 | |
| 1022 | - return $css; | |
| 1023 | - } | |
| 978 | + // Return | |
| 979 | + return $css; | |
| 980 | + } | |
| 1024 | 981 | |
| 1025 | - /** | |
| 1026 | - * Create CSS style (PHPExcel_Style_Border) | |
| 1027 | - * | |
| 1028 | - * @param PHPExcel_Style_Border $pStyle PHPExcel_Style_Border | |
| 1029 | - * @return string | |
| 1030 | - */ | |
| 1031 | - private function createCSSStyleBorder(PHPExcel_Style_Border $pStyle) | |
| 1032 | - { | |
| 1033 | - // Create CSS | |
| 1034 | -// $css = $this->mapBorderStyle($pStyle->getBorderStyle()) . ' #' . $pStyle->getColor()->getRGB(); | |
| 1035 | - // Create CSS - add !important to non-none border styles for merged cells | |
| 1036 | - $borderStyle = $this->mapBorderStyle($pStyle->getBorderStyle()); | |
| 1037 | - $css = $borderStyle . ' #' . $pStyle->getColor()->getRGB() . (($borderStyle == 'none') ? '' : ' !important'); | |
| 982 | + /** | |
| 983 | + * Create CSS style (PHPExcel_Style_Fill) | |
| 984 | + * | |
| 985 | + * @param PHPExcel_Style_Fill $pStyle PHPExcel_Style_Fill | |
| 986 | + * @return array | |
| 987 | + */ | |
| 988 | + private function _createCSSStyleFill(PHPExcel_Style_Fill $pStyle) { | |
| 989 | + // Construct HTML | |
| 990 | + $css = array(); | |
| 1038 | 991 | |
| 1039 | - return $css; | |
| 1040 | - } | |
| 992 | + // Create CSS | |
| 993 | + $value = $pStyle->getFillType() == PHPExcel_Style_Fill::FILL_NONE ? | |
| 994 | + 'white' : '#' . $pStyle->getStartColor()->getRGB(); | |
| 995 | + $css['background-color'] = $value; | |
| 1041 | 996 | |
| 1042 | - /** | |
| 1043 | - * Create CSS style (PHPExcel_Style_Fill) | |
| 1044 | - * | |
| 1045 | - * @param PHPExcel_Style_Fill $pStyle PHPExcel_Style_Fill | |
| 1046 | - * @return array | |
| 1047 | - */ | |
| 1048 | - private function createCSSStyleFill(PHPExcel_Style_Fill $pStyle) | |
| 1049 | - { | |
| 1050 | - // Construct HTML | |
| 1051 | - $css = array(); | |
| 997 | + // Return | |
| 998 | + return $css; | |
| 999 | + } | |
| 1052 | 1000 | |
| 1053 | - // Create CSS | |
| 1054 | - $value = $pStyle->getFillType() == PHPExcel_Style_Fill::FILL_NONE ? | |
| 1055 | - 'white' : '#' . $pStyle->getStartColor()->getRGB(); | |
| 1056 | - $css['background-color'] = $value; | |
| 1001 | + /** | |
| 1002 | + * Generate HTML footer | |
| 1003 | + */ | |
| 1004 | + public function generateHTMLFooter() { | |
| 1005 | + // Construct HTML | |
| 1006 | + $html = ''; | |
| 1007 | + $html .= ' </body>' . PHP_EOL; | |
| 1008 | + $html .= '</html>' . PHP_EOL; | |
| 1057 | 1009 | |
| 1058 | - return $css; | |
| 1059 | - } | |
| 1010 | + // Return | |
| 1011 | + return $html; | |
| 1012 | + } | |
| 1060 | 1013 | |
| 1061 | - /** | |
| 1062 | - * Generate HTML footer | |
| 1063 | - */ | |
| 1064 | - public function generateHTMLFooter() | |
| 1065 | - { | |
| 1066 | - // Construct HTML | |
| 1067 | - $html = ''; | |
| 1068 | - $html .= ' </body>' . PHP_EOL; | |
| 1069 | - $html .= '</html>' . PHP_EOL; | |
| 1014 | + /** | |
| 1015 | + * Generate table header | |
| 1016 | + * | |
| 1017 | + * @param PHPExcel_Worksheet $pSheet The worksheet for the table we are writing | |
| 1018 | + * @return string | |
| 1019 | + * @throws PHPExcel_Writer_Exception | |
| 1020 | + */ | |
| 1021 | + private function _generateTableHeader($pSheet) { | |
| 1022 | + $sheetIndex = $pSheet->getParent()->getIndex($pSheet); | |
| 1070 | 1023 | |
| 1071 | - return $html; | |
| 1072 | - } | |
| 1024 | + // Construct HTML | |
| 1025 | + $html = ''; | |
| 1026 | + $html .= $this->_setMargins($pSheet); | |
| 1027 | + | |
| 1028 | + if (!$this->_useInlineCss) { | |
| 1029 | + $gridlines = $pSheet->getShowGridlines() ? ' gridlines' : ''; | |
| 1030 | + $html .= ' <table border="0" cellpadding="0" cellspacing="0" id="sheet' . $sheetIndex . '" class="sheet' . $sheetIndex . $gridlines . '">' . PHP_EOL; | |
| 1031 | + } else { | |
| 1032 | + $style = isset($this->_cssStyles['table']) ? | |
| 1033 | + $this->_assembleCSS($this->_cssStyles['table']) : ''; | |
| 1073 | 1034 | |
| 1074 | - /** | |
| 1075 | - * Generate table header | |
| 1076 | - * | |
| 1077 | - * @param PHPExcel_Worksheet $pSheet The worksheet for the table we are writing | |
| 1078 | - * @return string | |
| 1079 | - * @throws PHPExcel_Writer_Exception | |
| 1080 | - */ | |
| 1081 | - private function generateTableHeader($pSheet) | |
| 1082 | - { | |
| 1083 | - $sheetIndex = $pSheet->getParent()->getIndex($pSheet); | |
| 1035 | + if ($this->_isPdf && $pSheet->getShowGridlines()) { | |
| 1036 | + $html .= ' <table border="1" cellpadding="1" id="sheet' . $sheetIndex . '" cellspacing="1" style="' . $style . '">' . PHP_EOL; | |
| 1037 | + } else { | |
| 1038 | + $html .= ' <table border="0" cellpadding="1" id="sheet' . $sheetIndex . '" cellspacing="0" style="' . $style . '">' . PHP_EOL; | |
| 1039 | + } | |
| 1040 | + } | |
| 1084 | 1041 | |
| 1085 | - // Construct HTML | |
| 1086 | - $html = ''; | |
| 1087 | - $html .= $this->setMargins($pSheet); | |
| 1088 | - | |
| 1089 | - if (!$this->useInlineCss) { | |
| 1090 | - $gridlines = $pSheet->getShowGridlines() ? ' gridlines' : ''; | |
| 1091 | - $html .= ' <table border="0" cellpadding="0" cellspacing="0" id="sheet' . $sheetIndex . '" class="sheet' . $sheetIndex . $gridlines . '">' . PHP_EOL; | |
| 1092 | - } else { | |
| 1093 | - $style = isset($this->cssStyles['table']) ? | |
| 1094 | - $this->assembleCSS($this->cssStyles['table']) : ''; | |
| 1042 | + // Write <col> elements | |
| 1043 | + $highestColumnIndex = PHPExcel_Cell::columnIndexFromString($pSheet->getHighestColumn()) - 1; | |
| 1044 | + $i = -1; | |
| 1045 | + while($i++ < $highestColumnIndex) { | |
| 1046 | + if (!$this->_isPdf) { | |
| 1047 | + if (!$this->_useInlineCss) { | |
| 1048 | + $html .= ' <col class="col' . $i . '">' . PHP_EOL; | |
| 1049 | + } else { | |
| 1050 | + $style = isset($this->_cssStyles['table.sheet' . $sheetIndex . ' col.col' . $i]) ? | |
| 1051 | + $this->_assembleCSS($this->_cssStyles['table.sheet' . $sheetIndex . ' col.col' . $i]) : ''; | |
| 1052 | + $html .= ' <col style="' . $style . '">' . PHP_EOL; | |
| 1053 | + } | |
| 1054 | + } | |
| 1055 | + } | |
| 1095 | 1056 | |
| 1096 | - if ($this->isPdf && $pSheet->getShowGridlines()) { | |
| 1097 | - $html .= ' <table border="1" cellpadding="1" id="sheet' . $sheetIndex . '" cellspacing="1" style="' . $style . '">' . PHP_EOL; | |
| 1098 | - } else { | |
| 1099 | - $html .= ' <table border="0" cellpadding="1" id="sheet' . $sheetIndex . '" cellspacing="0" style="' . $style . '">' . PHP_EOL; | |
| 1100 | - } | |
| 1101 | - } | |
| 1057 | + // Return | |
| 1058 | + return $html; | |
| 1059 | + } | |
| 1102 | 1060 | |
| 1103 | - // Write <col> elements | |
| 1104 | - $highestColumnIndex = PHPExcel_Cell::columnIndexFromString($pSheet->getHighestColumn()) - 1; | |
| 1105 | - $i = -1; | |
| 1106 | - while ($i++ < $highestColumnIndex) { | |
| 1107 | - if (!$this->isPdf) { | |
| 1108 | - if (!$this->useInlineCss) { | |
| 1109 | - $html .= ' <col class="col' . $i . '">' . PHP_EOL; | |
| 1110 | - } else { | |
| 1111 | - $style = isset($this->cssStyles['table.sheet' . $sheetIndex . ' col.col' . $i]) ? | |
| 1112 | - $this->assembleCSS($this->cssStyles['table.sheet' . $sheetIndex . ' col.col' . $i]) : ''; | |
| 1113 | - $html .= ' <col style="' . $style . '">' . PHP_EOL; | |
| 1114 | - } | |
| 1115 | - } | |
| 1116 | - } | |
| 1061 | + /** | |
| 1062 | + * Generate table footer | |
| 1063 | + * | |
| 1064 | + * @throws PHPExcel_Writer_Exception | |
| 1065 | + */ | |
| 1066 | + private function _generateTableFooter() { | |
| 1067 | + // Construct HTML | |
| 1068 | + $html = ''; | |
| 1069 | + $html .= ' </table>' . PHP_EOL; | |
| 1117 | 1070 | |
| 1118 | - return $html; | |
| 1119 | - } | |
| 1071 | + // Return | |
| 1072 | + return $html; | |
| 1073 | + } | |
| 1120 | 1074 | |
| 1121 | - /** | |
| 1122 | - * Generate table footer | |
| 1123 | - * | |
| 1124 | - * @throws PHPExcel_Writer_Exception | |
| 1125 | - */ | |
| 1126 | - private function generateTableFooter() | |
| 1127 | - { | |
| 1128 | - $html = ' </table>' . PHP_EOL; | |
| 1075 | + /** | |
| 1076 | + * Generate row | |
| 1077 | + * | |
| 1078 | + * @param PHPExcel_Worksheet $pSheet PHPExcel_Worksheet | |
| 1079 | + * @param array $pValues Array containing cells in a row | |
| 1080 | + * @param int $pRow Row number (0-based) | |
| 1081 | + * @return string | |
| 1082 | + * @throws PHPExcel_Writer_Exception | |
| 1083 | + */ | |
| 1084 | + private function _generateRow(PHPExcel_Worksheet $pSheet, $pValues = null, $pRow = 0, $cellType = 'td') { | |
| 1085 | + if (is_array($pValues)) { | |
| 1086 | + // Construct HTML | |
| 1087 | + $html = ''; | |
| 1129 | 1088 | |
| 1130 | - return $html; | |
| 1131 | - } | |
| 1089 | + // Sheet index | |
| 1090 | + $sheetIndex = $pSheet->getParent()->getIndex($pSheet); | |
| 1132 | 1091 | |
| 1133 | - /** | |
| 1134 | - * Generate row | |
| 1135 | - * | |
| 1136 | - * @param PHPExcel_Worksheet $pSheet PHPExcel_Worksheet | |
| 1137 | - * @param array $pValues Array containing cells in a row | |
| 1138 | - * @param int $pRow Row number (0-based) | |
| 1139 | - * @return string | |
| 1140 | - * @throws PHPExcel_Writer_Exception | |
| 1141 | - */ | |
| 1142 | - private function generateRow(PHPExcel_Worksheet $pSheet, $pValues = null, $pRow = 0, $cellType = 'td') | |
| 1143 | - { | |
| 1144 | - if (is_array($pValues)) { | |
| 1145 | - // Construct HTML | |
| 1146 | - $html = ''; | |
| 1092 | + // DomPDF and breaks | |
| 1093 | + if ($this->_isPdf && count($pSheet->getBreaks()) > 0) { | |
| 1094 | + $breaks = $pSheet->getBreaks(); | |
| 1147 | 1095 | |
| 1148 | - // Sheet index | |
| 1149 | - $sheetIndex = $pSheet->getParent()->getIndex($pSheet); | |
| 1096 | + // check if a break is needed before this row | |
| 1097 | + if (isset($breaks['A' . $pRow])) { | |
| 1098 | + // close table: </table> | |
| 1099 | + $html .= $this->_generateTableFooter(); | |
| 1150 | 1100 | |
| 1151 | - // DomPDF and breaks | |
| 1152 | - if ($this->isPdf && count($pSheet->getBreaks()) > 0) { | |
| 1153 | - $breaks = $pSheet->getBreaks(); | |
| 1101 | + // insert page break | |
| 1102 | + $html .= '<div style="page-break-before:always" />'; | |
| 1154 | 1103 | |
| 1155 | - // check if a break is needed before this row | |
| 1156 | - if (isset($breaks['A' . $pRow])) { | |
| 1157 | - // close table: </table> | |
| 1158 | - $html .= $this->generateTableFooter(); | |
| 1104 | + // open table again: <table> + <col> etc. | |
| 1105 | + $html .= $this->_generateTableHeader($pSheet); | |
| 1106 | + } | |
| 1107 | + } | |
| 1159 | 1108 | |
| 1160 | - // insert page break | |
| 1161 | - $html .= '<div style="page-break-before:always" />'; | |
| 1109 | + // Write row start | |
| 1110 | + if (!$this->_useInlineCss) { | |
| 1111 | + $html .= ' <tr class="row' . $pRow . '">' . PHP_EOL; | |
| 1112 | + } else { | |
| 1113 | + $style = isset($this->_cssStyles['table.sheet' . $sheetIndex . ' tr.row' . $pRow]) | |
| 1114 | + ? $this->_assembleCSS($this->_cssStyles['table.sheet' . $sheetIndex . ' tr.row' . $pRow]) : ''; | |
| 1162 | 1115 | |
| 1163 | - // open table again: <table> + <col> etc. | |
| 1164 | - $html .= $this->generateTableHeader($pSheet); | |
| 1165 | - } | |
| 1166 | - } | |
| 1116 | + $html .= ' <tr style="' . $style . '">' . PHP_EOL; | |
| 1117 | + } | |
| 1167 | 1118 | |
| 1168 | - // Write row start | |
| 1169 | - if (!$this->useInlineCss) { | |
| 1170 | - $html .= ' <tr class="row' . $pRow . '">' . PHP_EOL; | |
| 1171 | - } else { | |
| 1172 | - $style = isset($this->cssStyles['table.sheet' . $sheetIndex . ' tr.row' . $pRow]) | |
| 1173 | - ? $this->assembleCSS($this->cssStyles['table.sheet' . $sheetIndex . ' tr.row' . $pRow]) : ''; | |
| 1174 | - | |
| 1175 | - $html .= ' <tr style="' . $style . '">' . PHP_EOL; | |
| 1176 | - } | |
| 1177 | - | |
| 1178 | - // Write cells | |
| 1179 | - $colNum = 0; | |
| 1180 | - foreach ($pValues as $cellAddress) { | |
| 1119 | + // Write cells | |
| 1120 | + $colNum = 0; | |
| 1121 | + foreach ($pValues as $cellAddress) { | |
| 1181 | 1122 | $cell = ($cellAddress > '') ? $pSheet->getCell($cellAddress) : ''; |
| 1182 | - $coordinate = PHPExcel_Cell::stringFromColumnIndex($colNum) . ($pRow + 1); | |
| 1183 | - if (!$this->useInlineCss) { | |
| 1184 | - $cssClass = ''; | |
| 1185 | - $cssClass = 'column' . $colNum; | |
| 1186 | - } else { | |
| 1187 | - $cssClass = array(); | |
| 1123 | + $coordinate = PHPExcel_Cell::stringFromColumnIndex($colNum) . ($pRow + 1); | |
| 1124 | + if (!$this->_useInlineCss) { | |
| 1125 | + $cssClass = ''; | |
| 1126 | + $cssClass = 'column' . $colNum; | |
| 1127 | + } else { | |
| 1128 | + $cssClass = array(); | |
| 1188 | 1129 | if ($cellType == 'th') { |
| 1189 | - if (isset($this->cssStyles['table.sheet' . $sheetIndex . ' th.column' . $colNum])) { | |
| 1190 | - $this->cssStyles['table.sheet' . $sheetIndex . ' th.column' . $colNum]; | |
| 1130 | + if (isset($this->_cssStyles['table.sheet' . $sheetIndex . ' th.column' . $colNum])) { | |
| 1131 | + $this->_cssStyles['table.sheet' . $sheetIndex . ' th.column' . $colNum]; | |
| 1191 | 1132 | } |
| 1192 | 1133 | } else { |
| 1193 | - if (isset($this->cssStyles['table.sheet' . $sheetIndex . ' td.column' . $colNum])) { | |
| 1194 | - $this->cssStyles['table.sheet' . $sheetIndex . ' td.column' . $colNum]; | |
| 1134 | + if (isset($this->_cssStyles['table.sheet' . $sheetIndex . ' td.column' . $colNum])) { | |
| 1135 | + $this->_cssStyles['table.sheet' . $sheetIndex . ' td.column' . $colNum]; | |
| 1195 | 1136 | } |
| 1196 | 1137 | } |
| 1197 | - } | |
| 1198 | - $colSpan = 1; | |
| 1199 | - $rowSpan = 1; | |
| 1138 | + } | |
| 1139 | + $colSpan = 1; | |
| 1140 | + $rowSpan = 1; | |
| 1200 | 1141 | |
| 1201 | - // initialize | |
| 1202 | - $cellData = ' '; | |
| 1142 | + // initialize | |
| 1143 | + $cellData = ' '; | |
| 1203 | 1144 | |
| 1204 | - // PHPExcel_Cell | |
| 1205 | - if ($cell instanceof PHPExcel_Cell) { | |
| 1206 | - $cellData = ''; | |
| 1207 | - if (is_null($cell->getParent())) { | |
| 1208 | - $cell->attach($pSheet); | |
| 1209 | - } | |
| 1210 | - // Value | |
| 1211 | - if ($cell->getValue() instanceof PHPExcel_RichText) { | |
| 1212 | - // Loop through rich text elements | |
| 1213 | - $elements = $cell->getValue()->getRichTextElements(); | |
| 1214 | - foreach ($elements as $element) { | |
| 1215 | - // Rich text start? | |
| 1216 | - if ($element instanceof PHPExcel_RichText_Run) { | |
| 1217 | - $cellData .= '<span style="' . $this->assembleCSS($this->createCSSStyleFont($element->getFont())) . '">'; | |
| 1145 | + // PHPExcel_Cell | |
| 1146 | + if ($cell instanceof PHPExcel_Cell) { | |
| 1147 | + $cellData = ''; | |
| 1148 | + if (is_null($cell->getParent())) { | |
| 1149 | + $cell->attach($pSheet); | |
| 1150 | + } | |
| 1151 | + // Value | |
| 1152 | + if ($cell->getValue() instanceof PHPExcel_RichText) { | |
| 1153 | + // Loop through rich text elements | |
| 1154 | + $elements = $cell->getValue()->getRichTextElements(); | |
| 1155 | + foreach ($elements as $element) { | |
| 1156 | + // Rich text start? | |
| 1157 | + if ($element instanceof PHPExcel_RichText_Run) { | |
| 1158 | + $cellData .= '<span style="' . $this->_assembleCSS($this->_createCSSStyleFont($element->getFont())) . '">'; | |
| 1218 | 1159 | |
| 1219 | - if ($element->getFont()->getSuperScript()) { | |
| 1220 | - $cellData .= '<sup>'; | |
| 1221 | - } elseif ($element->getFont()->getSubScript()) { | |
| 1222 | - $cellData .= '<sub>'; | |
| 1223 | - } | |
| 1224 | - } | |
| 1160 | + if ($element->getFont()->getSuperScript()) { | |
| 1161 | + $cellData .= '<sup>'; | |
| 1162 | + } else if ($element->getFont()->getSubScript()) { | |
| 1163 | + $cellData .= '<sub>'; | |
| 1164 | + } | |
| 1165 | + } | |
| 1225 | 1166 | |
| 1226 | - // Convert UTF8 data to PCDATA | |
| 1227 | - $cellText = $element->getText(); | |
| 1228 | - $cellData .= htmlspecialchars($cellText); | |
| 1167 | + // Convert UTF8 data to PCDATA | |
| 1168 | + $cellText = $element->getText(); | |
| 1169 | + $cellData .= htmlspecialchars($cellText); | |
| 1229 | 1170 | |
| 1230 | - if ($element instanceof PHPExcel_RichText_Run) { | |
| 1231 | - if ($element->getFont()->getSuperScript()) { | |
| 1232 | - $cellData .= '</sup>'; | |
| 1233 | - } elseif ($element->getFont()->getSubScript()) { | |
| 1234 | - $cellData .= '</sub>'; | |
| 1235 | - } | |
| 1171 | + if ($element instanceof PHPExcel_RichText_Run) { | |
| 1172 | + if ($element->getFont()->getSuperScript()) { | |
| 1173 | + $cellData .= '</sup>'; | |
| 1174 | + } else if ($element->getFont()->getSubScript()) { | |
| 1175 | + $cellData .= '</sub>'; | |
| 1176 | + } | |
| 1236 | 1177 | |
| 1237 | - $cellData .= '</span>'; | |
| 1238 | - } | |
| 1239 | - } | |
| 1240 | - } else { | |
| 1241 | - if ($this->preCalculateFormulas) { | |
| 1242 | - $cellData = PHPExcel_Style_NumberFormat::toFormattedString( | |
| 1243 | - $cell->getCalculatedValue(), | |
| 1244 | - $pSheet->getParent()->getCellXfByIndex($cell->getXfIndex())->getNumberFormat()->getFormatCode(), | |
| 1245 | - array($this, 'formatColor') | |
| 1246 | - ); | |
| 1247 | - } else { | |
| 1248 | - $cellData = PHPExcel_Style_NumberFormat::toFormattedString( | |
| 1249 | - $cell->getValue(), | |
| 1250 | - $pSheet->getParent()->getCellXfByIndex($cell->getXfIndex())->getNumberFormat()->getFormatCode(), | |
| 1251 | - array($this, 'formatColor') | |
| 1252 | - ); | |
| 1253 | - } | |
| 1254 | - $cellData = htmlspecialchars($cellData); | |
| 1255 | - if ($pSheet->getParent()->getCellXfByIndex($cell->getXfIndex())->getFont()->getSuperScript()) { | |
| 1256 | - $cellData = '<sup>'.$cellData.'</sup>'; | |
| 1257 | - } elseif ($pSheet->getParent()->getCellXfByIndex($cell->getXfIndex())->getFont()->getSubScript()) { | |
| 1258 | - $cellData = '<sub>'.$cellData.'</sub>'; | |
| 1259 | - } | |
| 1260 | - } | |
| 1178 | + $cellData .= '</span>'; | |
| 1179 | + } | |
| 1180 | + } | |
| 1181 | + } else { | |
| 1182 | + if ($this->_preCalculateFormulas) { | |
| 1183 | + $cellData = PHPExcel_Style_NumberFormat::toFormattedString( | |
| 1184 | + $cell->getCalculatedValue(), | |
| 1185 | + $pSheet->getParent()->getCellXfByIndex( $cell->getXfIndex() )->getNumberFormat()->getFormatCode(), | |
| 1186 | + array($this, 'formatColor') | |
| 1187 | + ); | |
| 1188 | + } else { | |
| 1189 | + $cellData = PHPExcel_Style_NumberFormat::toFormattedString( | |
| 1190 | + $cell->getValue(), | |
| 1191 | + $pSheet->getParent()->getCellXfByIndex( $cell->getXfIndex() )->getNumberFormat()->getFormatCode(), | |
| 1192 | + array($this, 'formatColor') | |
| 1193 | + ); | |
| 1194 | + } | |
| 1195 | + $cellData = htmlspecialchars($cellData); | |
| 1196 | + if ($pSheet->getParent()->getCellXfByIndex( $cell->getXfIndex() )->getFont()->getSuperScript()) { | |
| 1197 | + $cellData = '<sup>'.$cellData.'</sup>'; | |
| 1198 | + } elseif ($pSheet->getParent()->getCellXfByIndex( $cell->getXfIndex() )->getFont()->getSubScript()) { | |
| 1199 | + $cellData = '<sub>'.$cellData.'</sub>'; | |
| 1200 | + } | |
| 1201 | + } | |
| 1261 | 1202 | |
| 1262 | - // Converts the cell content so that spaces occuring at beginning of each new line are replaced by | |
| 1263 | - // Example: " Hello\n to the world" is converted to " Hello\n to the world" | |
| 1264 | - $cellData = preg_replace("/(?m)(?:^|\\G) /", ' ', $cellData); | |
| 1203 | + // Converts the cell content so that spaces occuring at beginning of each new line are replaced by | |
| 1204 | + // Example: " Hello\n to the world" is converted to " Hello\n to the world" | |
| 1205 | + $cellData = preg_replace("/(?m)(?:^|\\G) /", ' ', $cellData); | |
| 1265 | 1206 | |
| 1266 | - // convert newline "\n" to '<br>' | |
| 1267 | - $cellData = nl2br($cellData); | |
| 1207 | + // convert newline "\n" to '<br>' | |
| 1208 | + $cellData = nl2br($cellData); | |
| 1268 | 1209 | |
| 1269 | - // Extend CSS class? | |
| 1270 | - if (!$this->useInlineCss) { | |
| 1271 | - $cssClass .= ' style' . $cell->getXfIndex(); | |
| 1272 | - $cssClass .= ' ' . $cell->getDataType(); | |
| 1273 | - } else { | |
| 1210 | + // Extend CSS class? | |
| 1211 | + if (!$this->_useInlineCss) { | |
| 1212 | + $cssClass .= ' style' . $cell->getXfIndex(); | |
| 1213 | + $cssClass .= ' ' . $cell->getDataType(); | |
| 1214 | + } else { | |
| 1274 | 1215 | if ($cellType == 'th') { |
| 1275 | - if (isset($this->cssStyles['th.style' . $cell->getXfIndex()])) { | |
| 1276 | - $cssClass = array_merge($cssClass, $this->cssStyles['th.style' . $cell->getXfIndex()]); | |
| 1216 | + if (isset($this->_cssStyles['th.style' . $cell->getXfIndex()])) { | |
| 1217 | + $cssClass = array_merge($cssClass, $this->_cssStyles['th.style' . $cell->getXfIndex()]); | |
| 1277 | 1218 | } |
| 1278 | 1219 | } else { |
| 1279 | - if (isset($this->cssStyles['td.style' . $cell->getXfIndex()])) { | |
| 1280 | - $cssClass = array_merge($cssClass, $this->cssStyles['td.style' . $cell->getXfIndex()]); | |
| 1220 | + if (isset($this->_cssStyles['td.style' . $cell->getXfIndex()])) { | |
| 1221 | + $cssClass = array_merge($cssClass, $this->_cssStyles['td.style' . $cell->getXfIndex()]); | |
| 1281 | 1222 | } |
| 1282 | 1223 | } |
| 1283 | 1224 | |
| 1284 | - // General horizontal alignment: Actual horizontal alignment depends on dataType | |
| 1285 | - $sharedStyle = $pSheet->getParent()->getCellXfByIndex($cell->getXfIndex()); | |
| 1286 | - if ($sharedStyle->getAlignment()->getHorizontal() == PHPExcel_Style_Alignment::HORIZONTAL_GENERAL | |
| 1287 | - && isset($this->cssStyles['.' . $cell->getDataType()]['text-align'])) { | |
| 1288 | - $cssClass['text-align'] = $this->cssStyles['.' . $cell->getDataType()]['text-align']; | |
| 1289 | - } | |
| 1290 | - } | |
| 1291 | - } | |
| 1225 | + // General horizontal alignment: Actual horizontal alignment depends on dataType | |
| 1226 | + $sharedStyle = $pSheet->getParent()->getCellXfByIndex( $cell->getXfIndex() ); | |
| 1227 | + if ($sharedStyle->getAlignment()->getHorizontal() == PHPExcel_Style_Alignment::HORIZONTAL_GENERAL | |
| 1228 | + && isset($this->_cssStyles['.' . $cell->getDataType()]['text-align'])) | |
| 1229 | + { | |
| 1230 | + $cssClass['text-align'] = $this->_cssStyles['.' . $cell->getDataType()]['text-align']; | |
| 1231 | + } | |
| 1232 | + } | |
| 1233 | + } | |
| 1292 | 1234 | |
| 1293 | - // Hyperlink? | |
| 1294 | - if ($pSheet->hyperlinkExists($coordinate) && !$pSheet->getHyperlink($coordinate)->isInternal()) { | |
| 1295 | - $cellData = '<a href="' . htmlspecialchars($pSheet->getHyperlink($coordinate)->getUrl()) . '" title="' . htmlspecialchars($pSheet->getHyperlink($coordinate)->getTooltip()) . '">' . $cellData . '</a>'; | |
| 1296 | - } | |
| 1235 | + // Hyperlink? | |
| 1236 | + if ($pSheet->hyperlinkExists($coordinate) && !$pSheet->getHyperlink($coordinate)->isInternal()) { | |
| 1237 | + $cellData = '<a href="' . htmlspecialchars($pSheet->getHyperlink($coordinate)->getUrl()) . '" title="' . htmlspecialchars($pSheet->getHyperlink($coordinate)->getTooltip()) . '">' . $cellData . '</a>'; | |
| 1238 | + } | |
| 1297 | 1239 | |
| 1298 | - // Should the cell be written or is it swallowed by a rowspan or colspan? | |
| 1299 | - $writeCell = !(isset($this->isSpannedCell[$pSheet->getParent()->getIndex($pSheet)][$pRow + 1][$colNum]) | |
| 1300 | - && $this->isSpannedCell[$pSheet->getParent()->getIndex($pSheet)][$pRow + 1][$colNum]); | |
| 1240 | + // Should the cell be written or is it swallowed by a rowspan or colspan? | |
| 1241 | + $writeCell = ! ( isset($this->_isSpannedCell[$pSheet->getParent()->getIndex($pSheet)][$pRow + 1][$colNum]) | |
| 1242 | + && $this->_isSpannedCell[$pSheet->getParent()->getIndex($pSheet)][$pRow + 1][$colNum] ); | |
| 1301 | 1243 | |
| 1302 | - // Colspan and Rowspan | |
| 1303 | - $colspan = 1; | |
| 1304 | - $rowspan = 1; | |
| 1305 | - if (isset($this->isBaseCell[$pSheet->getParent()->getIndex($pSheet)][$pRow + 1][$colNum])) { | |
| 1306 | - $spans = $this->isBaseCell[$pSheet->getParent()->getIndex($pSheet)][$pRow + 1][$colNum]; | |
| 1307 | - $rowSpan = $spans['rowspan']; | |
| 1308 | - $colSpan = $spans['colspan']; | |
| 1244 | + // Colspan and Rowspan | |
| 1245 | + $colspan = 1; | |
| 1246 | + $rowspan = 1; | |
| 1247 | + if (isset($this->_isBaseCell[$pSheet->getParent()->getIndex($pSheet)][$pRow + 1][$colNum])) { | |
| 1248 | + $spans = $this->_isBaseCell[$pSheet->getParent()->getIndex($pSheet)][$pRow + 1][$colNum]; | |
| 1249 | + $rowSpan = $spans['rowspan']; | |
| 1250 | + $colSpan = $spans['colspan']; | |
| 1309 | 1251 | |
| 1310 | - // Also apply style from last cell in merge to fix borders - | |
| 1311 | - // relies on !important for non-none border declarations in createCSSStyleBorder | |
| 1312 | - $endCellCoord = PHPExcel_Cell::stringFromColumnIndex($colNum + $colSpan - 1) . ($pRow + $rowSpan); | |
| 1313 | - if (!$this->useInlineCss) { | |
| 1314 | - $cssClass .= ' style' . $pSheet->getCell($endCellCoord)->getXfIndex(); | |
| 1315 | - } | |
| 1316 | - } | |
| 1252 | + // Also apply style from last cell in merge to fix borders - | |
| 1253 | + // relies on !important for non-none border declarations in _createCSSStyleBorder | |
| 1254 | + $endCellCoord = PHPExcel_Cell::stringFromColumnIndex($colNum + $colSpan - 1) . ($pRow + $rowSpan); | |
| 1255 | + if (!$this->_useInlineCss) { | |
| 1256 | + $cssClass .= ' style' . $pSheet->getCell($endCellCoord)->getXfIndex(); | |
| 1257 | + } | |
| 1258 | + } | |
| 1317 | 1259 | |
| 1318 | - // Write | |
| 1319 | - if ($writeCell) { | |
| 1320 | - // Column start | |
| 1321 | - $html .= ' <' . $cellType; | |
| 1322 | - if (!$this->useInlineCss) { | |
| 1323 | - $html .= ' class="' . $cssClass . '"'; | |
| 1324 | - } else { | |
| 1325 | - //** Necessary redundant code for the sake of PHPExcel_Writer_PDF ** | |
| 1326 | - // We must explicitly write the width of the <td> element because TCPDF | |
| 1327 | - // does not recognize e.g. <col style="width:42pt"> | |
| 1328 | - $width = 0; | |
| 1329 | - $i = $colNum - 1; | |
| 1330 | - $e = $colNum + $colSpan - 1; | |
| 1331 | - while ($i++ < $e) { | |
| 1332 | - if (isset($this->columnWidths[$sheetIndex][$i])) { | |
| 1333 | - $width += $this->columnWidths[$sheetIndex][$i]; | |
| 1334 | - } | |
| 1335 | - } | |
| 1336 | - $cssClass['width'] = $width . 'pt'; | |
| 1260 | + // Write | |
| 1261 | + if ($writeCell) { | |
| 1262 | + // Column start | |
| 1263 | + $html .= ' <' . $cellType; | |
| 1264 | + if (!$this->_useInlineCss) { | |
| 1265 | + $html .= ' class="' . $cssClass . '"'; | |
| 1266 | + } else { | |
| 1267 | + //** Necessary redundant code for the sake of PHPExcel_Writer_PDF ** | |
| 1268 | + // We must explicitly write the width of the <td> element because TCPDF | |
| 1269 | + // does not recognize e.g. <col style="width:42pt"> | |
| 1270 | + $width = 0; | |
| 1271 | + $i = $colNum - 1; | |
| 1272 | + $e = $colNum + $colSpan - 1; | |
| 1273 | + while($i++ < $e) { | |
| 1274 | + if (isset($this->_columnWidths[$sheetIndex][$i])) { | |
| 1275 | + $width += $this->_columnWidths[$sheetIndex][$i]; | |
| 1276 | + } | |
| 1277 | + } | |
| 1278 | + $cssClass['width'] = $width . 'pt'; | |
| 1337 | 1279 | |
| 1338 | - // We must also explicitly write the height of the <td> element because TCPDF | |
| 1339 | - // does not recognize e.g. <tr style="height:50pt"> | |
| 1340 | - if (isset($this->cssStyles['table.sheet' . $sheetIndex . ' tr.row' . $pRow]['height'])) { | |
| 1341 | - $height = $this->cssStyles['table.sheet' . $sheetIndex . ' tr.row' . $pRow]['height']; | |
| 1342 | - $cssClass['height'] = $height; | |
| 1343 | - } | |
| 1344 | - //** end of redundant code ** | |
| 1280 | + // We must also explicitly write the height of the <td> element because TCPDF | |
| 1281 | + // does not recognize e.g. <tr style="height:50pt"> | |
| 1282 | + if (isset($this->_cssStyles['table.sheet' . $sheetIndex . ' tr.row' . $pRow]['height'])) { | |
| 1283 | + $height = $this->_cssStyles['table.sheet' . $sheetIndex . ' tr.row' . $pRow]['height']; | |
| 1284 | + $cssClass['height'] = $height; | |
| 1285 | + } | |
| 1286 | + //** end of redundant code ** | |
| 1345 | 1287 | |
| 1346 | - $html .= ' style="' . $this->assembleCSS($cssClass) . '"'; | |
| 1347 | - } | |
| 1348 | - if ($colSpan > 1) { | |
| 1349 | - $html .= ' colspan="' . $colSpan . '"'; | |
| 1350 | - } | |
| 1351 | - if ($rowSpan > 1) { | |
| 1352 | - $html .= ' rowspan="' . $rowSpan . '"'; | |
| 1353 | - } | |
| 1354 | - $html .= '>'; | |
| 1288 | + $html .= ' style="' . $this->_assembleCSS($cssClass) . '"'; | |
| 1289 | + } | |
| 1290 | + if ($colSpan > 1) { | |
| 1291 | + $html .= ' colspan="' . $colSpan . '"'; | |
| 1292 | + } | |
| 1293 | + if ($rowSpan > 1) { | |
| 1294 | + $html .= ' rowspan="' . $rowSpan . '"'; | |
| 1295 | + } | |
| 1296 | + $html .= '>'; | |
| 1355 | 1297 | |
| 1356 | - // Image? | |
| 1357 | - $html .= $this->writeImageInCell($pSheet, $coordinate); | |
| 1298 | + // Image? | |
| 1299 | + $html .= $this->_writeImageInCell($pSheet, $coordinate); | |
| 1358 | 1300 | |
| 1359 | - // Chart? | |
| 1360 | - if ($this->includeCharts) { | |
| 1361 | - $html .= $this->writeChartInCell($pSheet, $coordinate); | |
| 1362 | - } | |
| 1301 | + // Chart? | |
| 1302 | + if ($this->_includeCharts) { | |
| 1303 | + $html .= $this->_writeChartInCell($pSheet, $coordinate); | |
| 1304 | + } | |
| 1363 | 1305 | |
| 1364 | - // Cell data | |
| 1365 | - $html .= $cellData; | |
| 1306 | + // Cell data | |
| 1307 | + $html .= $cellData; | |
| 1366 | 1308 | |
| 1367 | - // Column end | |
| 1368 | - $html .= '</'.$cellType.'>' . PHP_EOL; | |
| 1369 | - } | |
| 1309 | + // Column end | |
| 1310 | + $html .= '</'.$cellType.'>' . PHP_EOL; | |
| 1311 | + } | |
| 1370 | 1312 | |
| 1371 | - // Next column | |
| 1372 | - ++$colNum; | |
| 1373 | - } | |
| 1313 | + // Next column | |
| 1314 | + ++$colNum; | |
| 1315 | + } | |
| 1374 | 1316 | |
| 1375 | - // Write row end | |
| 1376 | - $html .= ' </tr>' . PHP_EOL; | |
| 1317 | + // Write row end | |
| 1318 | + $html .= ' </tr>' . PHP_EOL; | |
| 1377 | 1319 | |
| 1378 | - // Return | |
| 1379 | - return $html; | |
| 1380 | - } else { | |
| 1381 | - throw new PHPExcel_Writer_Exception("Invalid parameters passed."); | |
| 1382 | - } | |
| 1383 | - } | |
| 1320 | + // Return | |
| 1321 | + return $html; | |
| 1322 | + } else { | |
| 1323 | + throw new PHPExcel_Writer_Exception("Invalid parameters passed."); | |
| 1324 | + } | |
| 1325 | + } | |
| 1384 | 1326 | |
| 1385 | - /** | |
| 1386 | - * Takes array where of CSS properties / values and converts to CSS string | |
| 1387 | - * | |
| 1388 | - * @param array | |
| 1389 | - * @return string | |
| 1390 | - */ | |
| 1391 | - private function assembleCSS($pValue = array()) | |
| 1392 | - { | |
| 1393 | - $pairs = array(); | |
| 1394 | - foreach ($pValue as $property => $value) { | |
| 1395 | - $pairs[] = $property . ':' . $value; | |
| 1396 | - } | |
| 1397 | - $string = implode('; ', $pairs); | |
| 1327 | + /** | |
| 1328 | + * Takes array where of CSS properties / values and converts to CSS string | |
| 1329 | + * | |
| 1330 | + * @param array | |
| 1331 | + * @return string | |
| 1332 | + */ | |
| 1333 | + private function _assembleCSS($pValue = array()) | |
| 1334 | + { | |
| 1335 | + $pairs = array(); | |
| 1336 | + foreach ($pValue as $property => $value) { | |
| 1337 | + $pairs[] = $property . ':' . $value; | |
| 1338 | + } | |
| 1339 | + $string = implode('; ', $pairs); | |
| 1398 | 1340 | |
| 1399 | - return $string; | |
| 1400 | - } | |
| 1341 | + return $string; | |
| 1342 | + } | |
| 1401 | 1343 | |
| 1402 | - /** | |
| 1403 | - * Get images root | |
| 1404 | - * | |
| 1405 | - * @return string | |
| 1406 | - */ | |
| 1407 | - public function getImagesRoot() | |
| 1408 | - { | |
| 1409 | - return $this->imagesRoot; | |
| 1410 | - } | |
| 1344 | + /** | |
| 1345 | + * Get images root | |
| 1346 | + * | |
| 1347 | + * @return string | |
| 1348 | + */ | |
| 1349 | + public function getImagesRoot() { | |
| 1350 | + return $this->_imagesRoot; | |
| 1351 | + } | |
| 1411 | 1352 | |
| 1412 | - /** | |
| 1413 | - * Set images root | |
| 1414 | - * | |
| 1415 | - * @param string $pValue | |
| 1416 | - * @return PHPExcel_Writer_HTML | |
| 1417 | - */ | |
| 1418 | - public function setImagesRoot($pValue = '.') | |
| 1419 | - { | |
| 1420 | - $this->imagesRoot = $pValue; | |
| 1421 | - return $this; | |
| 1422 | - } | |
| 1353 | + /** | |
| 1354 | + * Set images root | |
| 1355 | + * | |
| 1356 | + * @param string $pValue | |
| 1357 | + * @return PHPExcel_Writer_HTML | |
| 1358 | + */ | |
| 1359 | + public function setImagesRoot($pValue = '.') { | |
| 1360 | + $this->_imagesRoot = $pValue; | |
| 1361 | + return $this; | |
| 1362 | + } | |
| 1423 | 1363 | |
| 1424 | - /** | |
| 1425 | - * Get embed images | |
| 1426 | - * | |
| 1427 | - * @return boolean | |
| 1428 | - */ | |
| 1429 | - public function getEmbedImages() | |
| 1430 | - { | |
| 1431 | - return $this->embedImages; | |
| 1432 | - } | |
| 1364 | + /** | |
| 1365 | + * Get embed images | |
| 1366 | + * | |
| 1367 | + * @return boolean | |
| 1368 | + */ | |
| 1369 | + public function getEmbedImages() { | |
| 1370 | + return $this->_embedImages; | |
| 1371 | + } | |
| 1433 | 1372 | |
| 1434 | - /** | |
| 1435 | - * Set embed images | |
| 1436 | - * | |
| 1437 | - * @param boolean $pValue | |
| 1438 | - * @return PHPExcel_Writer_HTML | |
| 1439 | - */ | |
| 1440 | - public function setEmbedImages($pValue = '.') | |
| 1441 | - { | |
| 1442 | - $this->embedImages = $pValue; | |
| 1443 | - return $this; | |
| 1444 | - } | |
| 1373 | + /** | |
| 1374 | + * Set embed images | |
| 1375 | + * | |
| 1376 | + * @param boolean $pValue | |
| 1377 | + * @return PHPExcel_Writer_HTML | |
| 1378 | + */ | |
| 1379 | + public function setEmbedImages($pValue = '.') { | |
| 1380 | + $this->_embedImages = $pValue; | |
| 1381 | + return $this; | |
| 1382 | + } | |
| 1445 | 1383 | |
| 1446 | - /** | |
| 1447 | - * Get use inline CSS? | |
| 1448 | - * | |
| 1449 | - * @return boolean | |
| 1450 | - */ | |
| 1451 | - public function getUseInlineCss() | |
| 1452 | - { | |
| 1453 | - return $this->useInlineCss; | |
| 1454 | - } | |
| 1384 | + /** | |
| 1385 | + * Get use inline CSS? | |
| 1386 | + * | |
| 1387 | + * @return boolean | |
| 1388 | + */ | |
| 1389 | + public function getUseInlineCss() { | |
| 1390 | + return $this->_useInlineCss; | |
| 1391 | + } | |
| 1455 | 1392 | |
| 1456 | - /** | |
| 1457 | - * Set use inline CSS? | |
| 1458 | - * | |
| 1459 | - * @param boolean $pValue | |
| 1460 | - * @return PHPExcel_Writer_HTML | |
| 1461 | - */ | |
| 1462 | - public function setUseInlineCss($pValue = false) | |
| 1463 | - { | |
| 1464 | - $this->useInlineCss = $pValue; | |
| 1465 | - return $this; | |
| 1466 | - } | |
| 1393 | + /** | |
| 1394 | + * Set use inline CSS? | |
| 1395 | + * | |
| 1396 | + * @param boolean $pValue | |
| 1397 | + * @return PHPExcel_Writer_HTML | |
| 1398 | + */ | |
| 1399 | + public function setUseInlineCss($pValue = false) { | |
| 1400 | + $this->_useInlineCss = $pValue; | |
| 1401 | + return $this; | |
| 1402 | + } | |
| 1467 | 1403 | |
| 1468 | - /** | |
| 1469 | - * Add color to formatted string as inline style | |
| 1470 | - * | |
| 1471 | - * @param string $pValue Plain formatted value without color | |
| 1472 | - * @param string $pFormat Format code | |
| 1473 | - * @return string | |
| 1474 | - */ | |
| 1475 | - public function formatColor($pValue, $pFormat) | |
| 1476 | - { | |
| 1477 | - // Color information, e.g. [Red] is always at the beginning | |
| 1478 | - $color = null; // initialize | |
| 1479 | - $matches = array(); | |
| 1404 | + /** | |
| 1405 | + * Add color to formatted string as inline style | |
| 1406 | + * | |
| 1407 | + * @param string $pValue Plain formatted value without color | |
| 1408 | + * @param string $pFormat Format code | |
| 1409 | + * @return string | |
| 1410 | + */ | |
| 1411 | + public function formatColor($pValue, $pFormat) | |
| 1412 | + { | |
| 1413 | + // Color information, e.g. [Red] is always at the beginning | |
| 1414 | + $color = null; // initialize | |
| 1415 | + $matches = array(); | |
| 1480 | 1416 | |
| 1481 | - $color_regex = '/^\\[[a-zA-Z]+\\]/'; | |
| 1482 | - if (preg_match($color_regex, $pFormat, $matches)) { | |
| 1483 | - $color = str_replace('[', '', $matches[0]); | |
| 1484 | - $color = str_replace(']', '', $color); | |
| 1485 | - $color = strtolower($color); | |
| 1486 | - } | |
| 1417 | + $color_regex = '/^\\[[a-zA-Z]+\\]/'; | |
| 1418 | + if (preg_match($color_regex, $pFormat, $matches)) { | |
| 1419 | + $color = str_replace('[', '', $matches[0]); | |
| 1420 | + $color = str_replace(']', '', $color); | |
| 1421 | + $color = strtolower($color); | |
| 1422 | + } | |
| 1487 | 1423 | |
| 1488 | - // convert to PCDATA | |
| 1489 | - $value = htmlspecialchars($pValue); | |
| 1424 | + // convert to PCDATA | |
| 1425 | + $value = htmlspecialchars($pValue); | |
| 1490 | 1426 | |
| 1491 | - // color span tag | |
| 1492 | - if ($color !== null) { | |
| 1493 | - $value = '<span style="color:' . $color . '">' . $value . '</span>'; | |
| 1494 | - } | |
| 1427 | + // color span tag | |
| 1428 | + if ($color !== null) { | |
| 1429 | + $value = '<span style="color:' . $color . '">' . $value . '</span>'; | |
| 1430 | + } | |
| 1495 | 1431 | |
| 1496 | - return $value; | |
| 1497 | - } | |
| 1432 | + return $value; | |
| 1433 | + } | |
| 1498 | 1434 | |
| 1499 | - /** | |
| 1500 | - * Calculate information about HTML colspan and rowspan which is not always the same as Excel's | |
| 1501 | - */ | |
| 1502 | - private function calculateSpans() | |
| 1503 | - { | |
| 1504 | - // Identify all cells that should be omitted in HTML due to cell merge. | |
| 1505 | - // In HTML only the upper-left cell should be written and it should have | |
| 1506 | - // appropriate rowspan / colspan attribute | |
| 1507 | - $sheetIndexes = $this->sheetIndex !== null ? | |
| 1508 | - array($this->sheetIndex) : range(0, $this->phpExcel->getSheetCount() - 1); | |
| 1435 | + /** | |
| 1436 | + * Calculate information about HTML colspan and rowspan which is not always the same as Excel's | |
| 1437 | + */ | |
| 1438 | + private function _calculateSpans() | |
| 1439 | + { | |
| 1440 | + // Identify all cells that should be omitted in HTML due to cell merge. | |
| 1441 | + // In HTML only the upper-left cell should be written and it should have | |
| 1442 | + // appropriate rowspan / colspan attribute | |
| 1443 | + $sheetIndexes = $this->_sheetIndex !== null ? | |
| 1444 | + array($this->_sheetIndex) : range(0, $this->_phpExcel->getSheetCount() - 1); | |
| 1509 | 1445 | |
| 1510 | - foreach ($sheetIndexes as $sheetIndex) { | |
| 1511 | - $sheet = $this->phpExcel->getSheet($sheetIndex); | |
| 1446 | + foreach ($sheetIndexes as $sheetIndex) { | |
| 1447 | + $sheet = $this->_phpExcel->getSheet($sheetIndex); | |
| 1512 | 1448 | |
| 1513 | - $candidateSpannedRow = array(); | |
| 1449 | + $candidateSpannedRow = array(); | |
| 1514 | 1450 | |
| 1515 | - // loop through all Excel merged cells | |
| 1516 | - foreach ($sheet->getMergeCells() as $cells) { | |
| 1517 | - list($cells,) = PHPExcel_Cell::splitRange($cells); | |
| 1518 | - $first = $cells[0]; | |
| 1519 | - $last = $cells[1]; | |
| 1451 | + // loop through all Excel merged cells | |
| 1452 | + foreach ($sheet->getMergeCells() as $cells) { | |
| 1453 | + list($cells, ) = PHPExcel_Cell::splitRange($cells); | |
| 1454 | + $first = $cells[0]; | |
| 1455 | + $last = $cells[1]; | |
| 1520 | 1456 | |
| 1521 | - list($fc, $fr) = PHPExcel_Cell::coordinateFromString($first); | |
| 1522 | - $fc = PHPExcel_Cell::columnIndexFromString($fc) - 1; | |
| 1457 | + list($fc, $fr) = PHPExcel_Cell::coordinateFromString($first); | |
| 1458 | + $fc = PHPExcel_Cell::columnIndexFromString($fc) - 1; | |
| 1523 | 1459 | |
| 1524 | - list($lc, $lr) = PHPExcel_Cell::coordinateFromString($last); | |
| 1525 | - $lc = PHPExcel_Cell::columnIndexFromString($lc) - 1; | |
| 1460 | + list($lc, $lr) = PHPExcel_Cell::coordinateFromString($last); | |
| 1461 | + $lc = PHPExcel_Cell::columnIndexFromString($lc) - 1; | |
| 1526 | 1462 | |
| 1527 | - // loop through the individual cells in the individual merge | |
| 1528 | - $r = $fr - 1; | |
| 1529 | - while ($r++ < $lr) { | |
| 1530 | - // also, flag this row as a HTML row that is candidate to be omitted | |
| 1531 | - $candidateSpannedRow[$r] = $r; | |
| 1463 | + // loop through the individual cells in the individual merge | |
| 1464 | + $r = $fr - 1; | |
| 1465 | + while($r++ < $lr) { | |
| 1466 | + // also, flag this row as a HTML row that is candidate to be omitted | |
| 1467 | + $candidateSpannedRow[$r] = $r; | |
| 1532 | 1468 | |
| 1533 | - $c = $fc - 1; | |
| 1534 | - while ($c++ < $lc) { | |
| 1535 | - if (!($c == $fc && $r == $fr)) { | |
| 1536 | - // not the upper-left cell (should not be written in HTML) | |
| 1537 | - $this->isSpannedCell[$sheetIndex][$r][$c] = array( | |
| 1538 | - 'baseCell' => array($fr, $fc), | |
| 1539 | - ); | |
| 1540 | - } else { | |
| 1541 | - // upper-left is the base cell that should hold the colspan/rowspan attribute | |
| 1542 | - $this->isBaseCell[$sheetIndex][$r][$c] = array( | |
| 1543 | - 'xlrowspan' => $lr - $fr + 1, // Excel rowspan | |
| 1544 | - 'rowspan' => $lr - $fr + 1, // HTML rowspan, value may change | |
| 1545 | - 'xlcolspan' => $lc - $fc + 1, // Excel colspan | |
| 1546 | - 'colspan' => $lc - $fc + 1, // HTML colspan, value may change | |
| 1547 | - ); | |
| 1548 | - } | |
| 1549 | - } | |
| 1550 | - } | |
| 1551 | - } | |
| 1469 | + $c = $fc - 1; | |
| 1470 | + while($c++ < $lc) { | |
| 1471 | + if ( !($c == $fc && $r == $fr) ) { | |
| 1472 | + // not the upper-left cell (should not be written in HTML) | |
| 1473 | + $this->_isSpannedCell[$sheetIndex][$r][$c] = array( | |
| 1474 | + 'baseCell' => array($fr, $fc), | |
| 1475 | + ); | |
| 1476 | + } else { | |
| 1477 | + // upper-left is the base cell that should hold the colspan/rowspan attribute | |
| 1478 | + $this->_isBaseCell[$sheetIndex][$r][$c] = array( | |
| 1479 | + 'xlrowspan' => $lr - $fr + 1, // Excel rowspan | |
| 1480 | + 'rowspan' => $lr - $fr + 1, // HTML rowspan, value may change | |
| 1481 | + 'xlcolspan' => $lc - $fc + 1, // Excel colspan | |
| 1482 | + 'colspan' => $lc - $fc + 1, // HTML colspan, value may change | |
| 1483 | + ); | |
| 1484 | + } | |
| 1485 | + } | |
| 1486 | + } | |
| 1487 | + } | |
| 1552 | 1488 | |
| 1553 | - // Identify which rows should be omitted in HTML. These are the rows where all the cells | |
| 1554 | - // participate in a merge and the where base cells are somewhere above. | |
| 1555 | - $countColumns = PHPExcel_Cell::columnIndexFromString($sheet->getHighestColumn()); | |
| 1556 | - foreach ($candidateSpannedRow as $rowIndex) { | |
| 1557 | - if (isset($this->isSpannedCell[$sheetIndex][$rowIndex])) { | |
| 1558 | - if (count($this->isSpannedCell[$sheetIndex][$rowIndex]) == $countColumns) { | |
| 1559 | - $this->isSpannedRow[$sheetIndex][$rowIndex] = $rowIndex; | |
| 1560 | - }; | |
| 1561 | - } | |
| 1562 | - } | |
| 1489 | + // Identify which rows should be omitted in HTML. These are the rows where all the cells | |
| 1490 | + // participate in a merge and the where base cells are somewhere above. | |
| 1491 | + $countColumns = PHPExcel_Cell::columnIndexFromString($sheet->getHighestColumn()); | |
| 1492 | + foreach ($candidateSpannedRow as $rowIndex) { | |
| 1493 | + if (isset($this->_isSpannedCell[$sheetIndex][$rowIndex])) { | |
| 1494 | + if (count($this->_isSpannedCell[$sheetIndex][$rowIndex]) == $countColumns) { | |
| 1495 | + $this->_isSpannedRow[$sheetIndex][$rowIndex] = $rowIndex; | |
| 1496 | + }; | |
| 1497 | + } | |
| 1498 | + } | |
| 1563 | 1499 | |
| 1564 | - // For each of the omitted rows we found above, the affected rowspans should be subtracted by 1 | |
| 1565 | - if (isset($this->isSpannedRow[$sheetIndex])) { | |
| 1566 | - foreach ($this->isSpannedRow[$sheetIndex] as $rowIndex) { | |
| 1567 | - $adjustedBaseCells = array(); | |
| 1568 | - $c = -1; | |
| 1569 | - $e = $countColumns - 1; | |
| 1570 | - while ($c++ < $e) { | |
| 1571 | - $baseCell = $this->isSpannedCell[$sheetIndex][$rowIndex][$c]['baseCell']; | |
| 1500 | + // For each of the omitted rows we found above, the affected rowspans should be subtracted by 1 | |
| 1501 | + if ( isset($this->_isSpannedRow[$sheetIndex]) ) { | |
| 1502 | + foreach ($this->_isSpannedRow[$sheetIndex] as $rowIndex) { | |
| 1503 | + $adjustedBaseCells = array(); | |
| 1504 | + $c = -1; | |
| 1505 | + $e = $countColumns - 1; | |
| 1506 | + while($c++ < $e) { | |
| 1507 | + $baseCell = $this->_isSpannedCell[$sheetIndex][$rowIndex][$c]['baseCell']; | |
| 1572 | 1508 | |
| 1573 | - if (!in_array($baseCell, $adjustedBaseCells)) { | |
| 1574 | - // subtract rowspan by 1 | |
| 1575 | - --$this->isBaseCell[$sheetIndex][ $baseCell[0] ][ $baseCell[1] ]['rowspan']; | |
| 1576 | - $adjustedBaseCells[] = $baseCell; | |
| 1577 | - } | |
| 1578 | - } | |
| 1579 | - } | |
| 1580 | - } | |
| 1509 | + if ( !in_array($baseCell, $adjustedBaseCells) ) { | |
| 1510 | + // subtract rowspan by 1 | |
| 1511 | + --$this->_isBaseCell[$sheetIndex][ $baseCell[0] ][ $baseCell[1] ]['rowspan']; | |
| 1512 | + $adjustedBaseCells[] = $baseCell; | |
| 1513 | + } | |
| 1514 | + } | |
| 1515 | + } | |
| 1516 | + } | |
| 1581 | 1517 | |
| 1582 | - // TODO: Same for columns | |
| 1583 | - } | |
| 1518 | + // TODO: Same for columns | |
| 1519 | + } | |
| 1584 | 1520 | |
| 1585 | - // We have calculated the spans | |
| 1586 | - $this->spansAreCalculated = true; | |
| 1587 | - } | |
| 1521 | + // We have calculated the spans | |
| 1522 | + $this->_spansAreCalculated = true; | |
| 1523 | + } | |
| 1588 | 1524 | |
| 1589 | - private function setMargins(PHPExcel_Worksheet $pSheet) | |
| 1590 | - { | |
| 1591 | - $htmlPage = '@page { '; | |
| 1592 | - $htmlBody = 'body { '; | |
| 1525 | + private function _setMargins(PHPExcel_Worksheet $pSheet) { | |
| 1526 | + $htmlPage = '@page { '; | |
| 1527 | + $htmlBody = 'body { '; | |
| 1593 | 1528 | |
| 1594 | - $left = PHPExcel_Shared_String::FormatNumber($pSheet->getPageMargins()->getLeft()) . 'in; '; | |
| 1595 | - $htmlPage .= 'margin-left: ' . $left; | |
| 1596 | - $htmlBody .= 'margin-left: ' . $left; | |
| 1597 | - $right = PHPExcel_Shared_String::FormatNumber($pSheet->getPageMargins()->getRight()) . 'in; '; | |
| 1598 | - $htmlPage .= 'margin-right: ' . $right; | |
| 1599 | - $htmlBody .= 'margin-right: ' . $right; | |
| 1600 | - $top = PHPExcel_Shared_String::FormatNumber($pSheet->getPageMargins()->getTop()) . 'in; '; | |
| 1601 | - $htmlPage .= 'margin-top: ' . $top; | |
| 1602 | - $htmlBody .= 'margin-top: ' . $top; | |
| 1603 | - $bottom = PHPExcel_Shared_String::FormatNumber($pSheet->getPageMargins()->getBottom()) . 'in; '; | |
| 1604 | - $htmlPage .= 'margin-bottom: ' . $bottom; | |
| 1605 | - $htmlBody .= 'margin-bottom: ' . $bottom; | |
| 1529 | + $left = PHPExcel_Shared_String::FormatNumber($pSheet->getPageMargins()->getLeft()) . 'in; '; | |
| 1530 | + $htmlPage .= 'left-margin: ' . $left; | |
| 1531 | + $htmlBody .= 'left-margin: ' . $left; | |
| 1532 | + $right = PHPExcel_Shared_String::FormatNumber($pSheet->getPageMargins()->getRight()) . 'in; '; | |
| 1533 | + $htmlPage .= 'right-margin: ' . $right; | |
| 1534 | + $htmlBody .= 'right-margin: ' . $right; | |
| 1535 | + $top = PHPExcel_Shared_String::FormatNumber($pSheet->getPageMargins()->getTop()) . 'in; '; | |
| 1536 | + $htmlPage .= 'top-margin: ' . $top; | |
| 1537 | + $htmlBody .= 'top-margin: ' . $top; | |
| 1538 | + $bottom = PHPExcel_Shared_String::FormatNumber($pSheet->getPageMargins()->getBottom()) . 'in; '; | |
| 1539 | + $htmlPage .= 'bottom-margin: ' . $bottom; | |
| 1540 | + $htmlBody .= 'bottom-margin: ' . $bottom; | |
| 1606 | 1541 | |
| 1607 | - $htmlPage .= "}\n"; | |
| 1608 | - $htmlBody .= "}\n"; | |
| 1542 | + $htmlPage .= "}\n"; | |
| 1543 | + $htmlBody .= "}\n"; | |
| 1609 | 1544 | |
| 1610 | - return "<style>\n" . $htmlPage . $htmlBody . "</style>\n"; | |
| 1611 | - } | |
| 1545 | + return "<style>\n" . $htmlPage . $htmlBody . "</style>\n"; | |
| 1546 | + } | |
| 1547 | + | |
| 1612 | 1548 | } |