diff --git a/Classes/PHPExcel/Writer/HTML.php b/Classes/PHPExcel/Writer/HTML.php index 63328477..cad3205d 100644 --- a/Classes/PHPExcel/Writer/HTML.php +++ b/Classes/PHPExcel/Writer/HTML.php @@ -986,7 +986,6 @@ class PHPExcel_Writer_HTML implements PHPExcel_Writer_IWriter { } $colSpan = 1; $rowSpan = 1; - $writeCell = true; // Write cell // initialize $cellData = ''; @@ -1042,11 +1041,12 @@ class PHPExcel_Writer_HTML implements PHPExcel_Writer_IWriter { } } - // replace leading spaces on each line with   - $cellData = $this->_convertNbsp($cellData); + // Converts the cell content so that spaces occuring at beginning of each new line are replaced by   + // Example: " Hello\n to the world" is converted to "  Hello\n to the world" + $cellData = preg_replace("/(?m)(?:^|\\G) /", ' ', $cellData); // convert newline "\n" to '
' - $cellData = str_replace("\n", '
', $cellData); + $cellData = nl2br($cellData); // Extend CSS class? if (!$this->_useInlineCss) { @@ -1222,28 +1222,6 @@ class PHPExcel_Writer_HTML implements PHPExcel_Writer_IWriter { return $this; } - /** - * Converts a string so that spaces occuring at beginning of each new line are replaced by   - * Example: " Hello\n to the world" is converted to "  Hello\n to the world" - * - * @param string $pValue - * @return string - */ - private function _convertNbsp($pValue = '') - { - $explodes = explode("\n", $pValue); - foreach ($explodes as $explode) { - $matches = array(); - if (preg_match('/^( )+/', $explode, $matches)) { - $explode = str_repeat(' ', strlen($matches[0])) . substr($explode, strlen($matches[0])); - } - $implodes[] = $explode; - } - - $string = implode("\n", $implodes); - return $string; - } - /** * Add color to formatted string as inline style *