Minor performance tweaks to the HTML Writer

git-svn-id: https://phpexcel.svn.codeplex.com/svn/trunk@63829 2327b42d-5241-43d6-9e2a-de5ac946f064
This commit is contained in:
Mark Baker 2010-11-17 18:04:55 +00:00
parent 06bfeaaea0
commit dbcd7fb1af
1 changed files with 4 additions and 26 deletions

View File

@ -986,7 +986,6 @@ class PHPExcel_Writer_HTML implements PHPExcel_Writer_IWriter {
} }
$colSpan = 1; $colSpan = 1;
$rowSpan = 1; $rowSpan = 1;
$writeCell = true; // Write cell
// initialize // initialize
$cellData = ''; $cellData = '';
@ -1042,11 +1041,12 @@ class PHPExcel_Writer_HTML implements PHPExcel_Writer_IWriter {
} }
} }
// replace leading spaces on each line with   // Converts the cell content so that spaces occuring at beginning of each new line are replaced by  
$cellData = $this->_convertNbsp($cellData); // Example: " Hello\n to the world" is converted to "  Hello\n to the world"
$cellData = preg_replace("/(?m)(?:^|\\G) /", ' ', $cellData);
// convert newline "\n" to '<br>' // convert newline "\n" to '<br>'
$cellData = str_replace("\n", '<br/>', $cellData); $cellData = nl2br($cellData);
// Extend CSS class? // Extend CSS class?
if (!$this->_useInlineCss) { if (!$this->_useInlineCss) {
@ -1222,28 +1222,6 @@ class PHPExcel_Writer_HTML implements PHPExcel_Writer_IWriter {
return $this; return $this;
} }
/**
* Converts a string so that spaces occuring at beginning of each new line are replaced by &nbsp;
* Example: " Hello\n to the world" is converted to "&nbsp;&nbsp;Hello\n&nbsp;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('&nbsp;', strlen($matches[0])) . substr($explode, strlen($matches[0]));
}
$implodes[] = $explode;
}
$string = implode("\n", $implodes);
return $string;
}
/** /**
* Add color to formatted string as inline style * Add color to formatted string as inline style
* *