From dbcd7fb1affe16cbf15a1b5f3fd5ca76ae7b1901 Mon Sep 17 00:00:00 2001 From: Mark Baker Date: Wed, 17 Nov 2010 18:04:55 +0000 Subject: [PATCH] Minor performance tweaks to the HTML Writer git-svn-id: https://phpexcel.svn.codeplex.com/svn/trunk@63829 2327b42d-5241-43d6-9e2a-de5ac946f064 --- Classes/PHPExcel/Writer/HTML.php | 30 ++++-------------------------- 1 file changed, 4 insertions(+), 26 deletions(-) diff --git a/Classes/PHPExcel/Writer/HTML.php b/Classes/PHPExcel/Writer/HTML.php index 6332847..cad3205 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 *