Minor performance tweaks

git-svn-id: https://phpexcel.svn.codeplex.com/svn/trunk@63697 2327b42d-5241-43d6-9e2a-de5ac946f064
This commit is contained in:
Mark Baker 2010-11-14 00:17:32 +00:00
parent 51dc3403ff
commit 270ea1df05
2 changed files with 150 additions and 150 deletions

View File

@ -19,10 +19,10 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* @category PHPExcel
* @package PHPExcel_Writer
* @package PHPExcel_Writer
* @copyright Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/PHPExcel)
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version ##VERSION##, ##DATE##
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version ##VERSION##, ##DATE##
*/
@ -30,7 +30,7 @@
* PHPExcel_Writer_CSV
*
* @category PHPExcel
* @package PHPExcel_Writer
* @package PHPExcel_Writer
* @copyright Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/PHPExcel)
*/
class PHPExcel_Writer_CSV implements PHPExcel_Writer_IWriter {
@ -86,21 +86,21 @@ class PHPExcel_Writer_CSV implements PHPExcel_Writer_IWriter {
/**
* Create a new PHPExcel_Writer_CSV
*
* @param PHPExcel $phpExcel PHPExcel object
* @param PHPExcel $phpExcel PHPExcel object
*/
public function __construct(PHPExcel $phpExcel) {
$this->_phpExcel = $phpExcel;
$this->_delimiter = ',';
$this->_enclosure = '"';
$this->_lineEnding = PHP_EOL;
$this->_sheetIndex = 0;
$this->_phpExcel = $phpExcel;
$this->_delimiter = ',';
$this->_enclosure = '"';
$this->_lineEnding = PHP_EOL;
$this->_sheetIndex = 0;
}
/**
* Save PHPExcel to file
*
* @param string $pFileName
* @throws Exception
* @param string $pFileName
* @throws Exception
*/
public function save($pFilename = null) {
// Fetch sheet
@ -112,7 +112,7 @@ class PHPExcel_Writer_CSV implements PHPExcel_Writer_IWriter {
PHPExcel_Calculation::setArrayReturnType(PHPExcel_Calculation::RETURN_ARRAY_AS_VALUE);
// Open file
$fileHandle = fopen($pFilename, 'w');
$fileHandle = fopen($pFilename, 'wb+');
if ($fileHandle === false) {
throw new Exception("Could not open file $pFilename for writing.");
}
@ -280,23 +280,23 @@ class PHPExcel_Writer_CSV implements PHPExcel_Writer_IWriter {
}
}
/**
* Get Pre-Calculate Formulas
*
* @return boolean
*/
public function getPreCalculateFormulas() {
return $this->_preCalculateFormulas;
}
/**
* Get Pre-Calculate Formulas
*
* @return boolean
*/
public function getPreCalculateFormulas() {
return $this->_preCalculateFormulas;
}
/**
* Set Pre-Calculate Formulas
*
* @param boolean $pValue Pre-Calculate Formulas?
* @return PHPExcel_Writer_CSV
*/
public function setPreCalculateFormulas($pValue = true) {
$this->_preCalculateFormulas = $pValue;
return $this;
}
/**
* Set Pre-Calculate Formulas
*
* @param boolean $pValue Pre-Calculate Formulas?
* @return PHPExcel_Writer_CSV
*/
public function setPreCalculateFormulas($pValue = true) {
$this->_preCalculateFormulas = $pValue;
return $this;
}
}

View File

@ -19,10 +19,10 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* @category PHPExcel
* @package PHPExcel_Writer
* @package PHPExcel_Writer
* @copyright Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/PHPExcel)
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version ##VERSION##, ##DATE##
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version ##VERSION##, ##DATE##
*/
@ -30,7 +30,7 @@
* PHPExcel_Writer_HTML
*
* @category PHPExcel
* @package PHPExcel_Writer
* @package PHPExcel_Writer
* @copyright Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/PHPExcel)
*/
class PHPExcel_Writer_HTML implements PHPExcel_Writer_IWriter {
@ -135,7 +135,7 @@ class PHPExcel_Writer_HTML implements PHPExcel_Writer_IWriter {
/**
* Create a new PHPExcel_Writer_HTML
*
* @param PHPExcel $phpExcel PHPExcel object
* @param PHPExcel $phpExcel PHPExcel object
*/
public function __construct(PHPExcel $phpExcel) {
$this->_phpExcel = $phpExcel;
@ -145,15 +145,15 @@ class PHPExcel_Writer_HTML implements PHPExcel_Writer_IWriter {
$this->_spansAreCalculated = false;
$this->_isSpannedCell = array();
$this->_isBaseCell = array();
$this->_isBaseCell = array();
$this->_isSpannedRow = array();
}
/**
* Save PHPExcel to file
*
* @param string $pFileName
* @throws Exception
* @param string $pFileName
* @throws Exception
*/
public function save($pFilename = null) {
// garbage collect
@ -168,7 +168,7 @@ class PHPExcel_Writer_HTML implements PHPExcel_Writer_IWriter {
$this->buildCSS(!$this->_useInlineCss);
// Open file
$fileHandle = fopen($pFilename, 'w');
$fileHandle = fopen($pFilename, 'wb+');
if ($fileHandle === false) {
throw new Exception("Could not open file $pFilename for writing.");
}
@ -313,8 +313,8 @@ class PHPExcel_Writer_HTML implements PHPExcel_Writer_IWriter {
$html .= '<!-- Generated by PHPExcel - http://www.phpexcel.net -->' . "\r\n";
$html .= '<html>' . "\r\n";
$html .= ' <head>' . "\r\n";
$html .= ' <meta http-equiv="Content-Type" content="text/html; charset=utf-8">' . "\r\n";
$html .= ' <title>' . htmlspecialchars($this->_phpExcel->getProperties()->getTitle()) . '</title>' . "\r\n";
$html .= ' <meta http-equiv="Content-Type" content="text/html; charset=utf-8">' . "\r\n";
$html .= ' <title>' . htmlspecialchars($this->_phpExcel->getProperties()->getTitle()) . '</title>' . "\r\n";
if ($pIncludeStyles) {
$html .= $this->generateStyles(true);
}
@ -360,20 +360,20 @@ class PHPExcel_Writer_HTML implements PHPExcel_Writer_IWriter {
// Write table header
$html .= $this->_generateTableHeader($sheet);
// Get worksheet dimension
$dimension = explode(':', $sheet->calculateWorksheetDimension());
$dimension[0] = PHPExcel_Cell::coordinateFromString($dimension[0]);
$dimension[0][0] = PHPExcel_Cell::columnIndexFromString($dimension[0][0]) - 1;
$dimension[1] = PHPExcel_Cell::coordinateFromString($dimension[1]);
$dimension[1][0] = PHPExcel_Cell::columnIndexFromString($dimension[1][0]) - 1;
// Get worksheet dimension
$dimension = explode(':', $sheet->calculateWorksheetDimension());
$dimension[0] = PHPExcel_Cell::coordinateFromString($dimension[0]);
$dimension[0][0] = PHPExcel_Cell::columnIndexFromString($dimension[0][0]) - 1;
$dimension[1] = PHPExcel_Cell::coordinateFromString($dimension[1]);
$dimension[1][0] = PHPExcel_Cell::columnIndexFromString($dimension[1][0]) - 1;
// row min,max
// row min,max
$rowMin = $dimension[0][1];
$rowMax = $dimension[1][1];
// calculate start of <tbody>, <thead>
$tbodyStart = $rowMin;
$tbodyEnd = $rowMax;
$tbodyEnd = $rowMax;
$theadStart = 0; // default: no <thead>
$theadEnd = 0; // default: no </thead>
if ($sheet->getPageSetup()->isRowsToRepeatAtTopSet()) {
@ -388,29 +388,29 @@ class PHPExcel_Writer_HTML implements PHPExcel_Writer_IWriter {
}
// Loop through cells
$rowData = null;
for ($row = $rowMin; $row <= $rowMax; ++$row) {
$rowData = null;
for ($row = $rowMin; $row <= $rowMax; ++$row) {
// Start a new row
$rowData = array();
// Loop through columns
for ($column = $dimension[0][0]; $column <= $dimension[1][0]; ++$column) {
// Cell exists?
if ($sheet->cellExistsByColumnAndRow($column, $row)) {
$rowData[$column] = $cell = $sheet->getCellByColumnAndRow($column, $row);
} else {
$rowData[$column] = '';
}
}
// <thead> ?
if ($row == $theadStart) {
$html .= ' <thead>' . "\r\n";
for ($column = $dimension[0][0]; $column <= $dimension[1][0]; ++$column) {
// Cell exists?
if ($sheet->cellExistsByColumnAndRow($column, $row)) {
$rowData[$column] = $cell = $sheet->getCellByColumnAndRow($column, $row);
} else {
$rowData[$column] = '';
}
}
// <tbody> ?
// <thead> ?
if ($row == $theadStart) {
$html .= ' <thead>' . "\r\n";
}
// <tbody> ?
if ($row == $tbodyStart) {
$html .= ' <tbody>' . "\r\n";
$html .= ' <tbody>' . "\r\n";
}
// Write row if there are HTML table cells in it
@ -418,16 +418,16 @@ class PHPExcel_Writer_HTML implements PHPExcel_Writer_IWriter {
$html .= $this->_generateRow($sheet, $rowData, $row - 1);
}
// </thead> ?
// </thead> ?
if ($row == $theadEnd) {
$html .= ' </thead>' . "\r\n";
$html .= ' </thead>' . "\r\n";
}
// </tbody> ?
// </tbody> ?
if ($row == $tbodyEnd) {
$html .= ' </tbody>' . "\r\n";
$html .= ' </tbody>' . "\r\n";
}
}
}
// Write table footer
$html .= $this->_generateTableFooter();
@ -493,7 +493,7 @@ class PHPExcel_Writer_HTML implements PHPExcel_Writer_IWriter {
/**
* Generate image tag in cell
*
* @param PHPExcel_Worksheet $pSheet PHPExcel_Worksheet
* @param PHPExcel_Worksheet $pSheet PHPExcel_Worksheet
* @param string $coordinates Cell coordinates
* @return string
* @throws Exception
@ -525,7 +525,7 @@ class PHPExcel_Writer_HTML implements PHPExcel_Writer_IWriter {
$filename = htmlspecialchars($filename);
$html .= "\r\n";
$html .= ' <img style="position: relative; left: ' . $drawing->getOffsetX() . 'px; top: ' . $drawing->getOffsetY() . 'px; width: ' . $drawing->getWidth() . 'px; height: ' . $drawing->getHeight() . 'px;" src="' . $filename . '" border="0" width="' . $drawing->getWidth() . '" height="' . $drawing->getHeight() . '" />' . "\r\n";
$html .= ' <img style="position: relative; left: ' . $drawing->getOffsetX() . 'px; top: ' . $drawing->getOffsetY() . 'px; width: ' . $drawing->getWidth() . 'px; height: ' . $drawing->getHeight() . 'px;" src="' . $filename . '" border="0" width="' . $drawing->getWidth() . '" height="' . $drawing->getHeight() . '" />' . "\r\n";
}
}
}
@ -555,20 +555,20 @@ class PHPExcel_Writer_HTML implements PHPExcel_Writer_IWriter {
// Start styles
if ($generateSurroundingHTML) {
$html .= ' <style type="text/css">' . "\r\n";
$html .= ' html { ' . $this->_assembleCSS($css['html']) . ' }' . "\r\n";
$html .= ' <style type="text/css">' . "\r\n";
$html .= ' html { ' . $this->_assembleCSS($css['html']) . ' }' . "\r\n";
}
// Write all other styles
foreach ($css as $styleName => $styleDefinition) {
if ($styleName != 'html') {
$html .= ' ' . $styleName . ' { ' . $this->_assembleCSS($styleDefinition) . ' }' . "\r\n";
$html .= ' ' . $styleName . ' { ' . $this->_assembleCSS($styleDefinition) . ' }' . "\r\n";
}
}
// End styles
if ($generateSurroundingHTML) {
$html .= ' </style>' . "\r\n";
$html .= ' </style>' . "\r\n";
}
// Return
@ -604,8 +604,8 @@ class PHPExcel_Writer_HTML implements PHPExcel_Writer_IWriter {
// Start styles
if ($generateSurroundingHTML) {
// html { }
$css['html']['font-family'] = 'Calibri, Arial, Helvetica, sans-serif';
$css['html']['font-size'] = '11pt';
$css['html']['font-family'] = 'Calibri, Arial, Helvetica, sans-serif';
$css['html']['font-size'] = '11pt';
$css['html']['background-color'] = 'white';
}
@ -692,7 +692,7 @@ class PHPExcel_Writer_HTML implements PHPExcel_Writer_IWriter {
}
$css['table.sheet' . $sheetIndex . ' tr']['height'] = $pt_height . 'pt';
if ($rowDimension->getVisible() === false) {
$css['table.sheet' . $sheetIndex . ' tr']['display'] = 'none';
$css['table.sheet' . $sheetIndex . ' tr']['display'] = 'none';
$css['table.sheet' . $sheetIndex . ' tr']['visibility'] = 'hidden';
}
@ -728,7 +728,7 @@ class PHPExcel_Writer_HTML implements PHPExcel_Writer_IWriter {
/**
* Create CSS style
*
* @param PHPExcel_Style $pStyle PHPExcel_Style
* @param PHPExcel_Style $pStyle PHPExcel_Style
* @return array
*/
private function _createCSSStyle(PHPExcel_Style $pStyle) {
@ -750,7 +750,7 @@ class PHPExcel_Writer_HTML implements PHPExcel_Writer_IWriter {
/**
* Create CSS style (PHPExcel_Style_Alignment)
*
* @param PHPExcel_Style_Alignment $pStyle PHPExcel_Style_Alignment
* @param PHPExcel_Style_Alignment $pStyle PHPExcel_Style_Alignment
* @return array
*/
private function _createCSSStyleAlignment(PHPExcel_Style_Alignment $pStyle) {
@ -770,7 +770,7 @@ class PHPExcel_Writer_HTML implements PHPExcel_Writer_IWriter {
/**
* Create CSS style (PHPExcel_Style_Font)
*
* @param PHPExcel_Style_Font $pStyle PHPExcel_Style_Font
* @param PHPExcel_Style_Font $pStyle PHPExcel_Style_Font
* @return array
*/
private function _createCSSStyleFont(PHPExcel_Style_Font $pStyle) {
@ -803,7 +803,7 @@ class PHPExcel_Writer_HTML implements PHPExcel_Writer_IWriter {
/**
* Create CSS style (PHPExcel_Style_Borders)
*
* @param PHPExcel_Style_Borders $pStyle PHPExcel_Style_Borders
* @param PHPExcel_Style_Borders $pStyle PHPExcel_Style_Borders
* @return array
*/
private function _createCSSStyleBorders(PHPExcel_Style_Borders $pStyle) {
@ -872,7 +872,7 @@ class PHPExcel_Writer_HTML implements PHPExcel_Writer_IWriter {
/**
* Generate table header
*
* @param PHPExcel_Worksheet $pSheet The worksheet for the table we are writing
* @param PHPExcel_Worksheet $pSheet The worksheet for the table we are writing
* @return string
* @throws Exception
*/
@ -884,15 +884,15 @@ class PHPExcel_Writer_HTML implements PHPExcel_Writer_IWriter {
if (!$this->_useInlineCss) {
$gridlines = $pSheet->getShowGridLines() ? ' gridlines' : '';
$html .= ' <table border="0" cellpadding="0" cellspacing="0" id="sheet' . $sheetIndex . '" class="sheet' . $sheetIndex . $gridlines . '">' . "\r\n";
$html .= ' <table border="0" cellpadding="0" cellspacing="0" id="sheet' . $sheetIndex . '" class="sheet' . $sheetIndex . $gridlines . '">' . "\r\n";
} else {
$style = isset($this->_cssStyles['table']) ?
$this->_assembleCSS($this->_cssStyles['table']) : '';
if ($this->_isPdf && $pSheet->getShowGridLines()) {
$html .= ' <table border="1" cellpadding="0" id="sheet' . $sheetIndex . '" cellspacing="0" style="' . $style . '">' . "\r\n";
$html .= ' <table border="1" cellpadding="0" id="sheet' . $sheetIndex . '" cellspacing="0" style="' . $style . '">' . "\r\n";
} else {
$html .= ' <table border="0" cellpadding="0" id="sheet' . $sheetIndex . '" cellspacing="0" style="' . $style . '">' . "\r\n";
$html .= ' <table border="0" cellpadding="0" id="sheet' . $sheetIndex . '" cellspacing="0" style="' . $style . '">' . "\r\n";
}
}
@ -900,11 +900,11 @@ class PHPExcel_Writer_HTML implements PHPExcel_Writer_IWriter {
$highestColumnIndex = PHPExcel_Cell::columnIndexFromString($pSheet->getHighestColumn()) - 1;
for ($i = 0; $i <= $highestColumnIndex; ++$i) {
if (!$this->_useInlineCss) {
$html .= ' <col class="col' . $i . '">' . "\r\n";
$html .= ' <col class="col' . $i . '">' . "\r\n";
} else {
$style = isset($this->_cssStyles['table.sheet' . $sheetIndex . ' col.col' . $i]) ?
$this->_assembleCSS($this->_cssStyles['table.sheet' . $sheetIndex . ' col.col' . $i]) : '';
$html .= ' <col style="' . $style . '">' . "\r\n";
$html .= ' <col style="' . $style . '">' . "\r\n";
}
}
@ -920,7 +920,7 @@ class PHPExcel_Writer_HTML implements PHPExcel_Writer_IWriter {
private function _generateTableFooter() {
// Construct HTML
$html = '';
$html .= ' </table>' . "\r\n";
$html .= ' </table>' . "\r\n";
// Return
return $html;
@ -929,7 +929,7 @@ class PHPExcel_Writer_HTML implements PHPExcel_Writer_IWriter {
/**
* Generate row
*
* @param PHPExcel_Worksheet $pSheet PHPExcel_Worksheet
* @param PHPExcel_Worksheet $pSheet PHPExcel_Worksheet
* @param array $pValues Array containing cells in a row
* @param int $pRow Row number (0-based)
* @return string
@ -962,12 +962,12 @@ class PHPExcel_Writer_HTML implements PHPExcel_Writer_IWriter {
// Write row start
if (!$this->_useInlineCss) {
$html .= ' <tr class="row' . $pRow . '">' . "\r\n";
$html .= ' <tr class="row' . $pRow . '">' . "\r\n";
} else {
$style = isset($this->_cssStyles['table.sheet' . $sheetIndex . ' tr.row' . $pRow])
? $this->_assembleCSS($this->_cssStyles['table.sheet' . $sheetIndex . ' tr.row' . $pRow]) : '';
$html .= ' <tr style="' . $style . '">' . "\r\n";
$html .= ' <tr style="' . $style . '">' . "\r\n";
}
// Write cells
@ -1088,7 +1088,7 @@ class PHPExcel_Writer_HTML implements PHPExcel_Writer_IWriter {
// Write
if ($writeCell) {
// Column start
$html .= ' <td';
$html .= ' <td';
if (!$this->_useInlineCss) {
$html .= ' class="' . $cssClass . '"';
} else {
@ -1136,7 +1136,7 @@ class PHPExcel_Writer_HTML implements PHPExcel_Writer_IWriter {
}
// Write row end
$html .= ' </tr>' . "\r\n";
$html .= ' </tr>' . "\r\n";
// Return
return $html;
@ -1162,65 +1162,65 @@ class PHPExcel_Writer_HTML implements PHPExcel_Writer_IWriter {
return $string;
}
/**
* Get Pre-Calculate Formulas
*
* @return boolean
*/
public function getPreCalculateFormulas() {
return $this->_preCalculateFormulas;
}
/**
* Get Pre-Calculate Formulas
*
* @return boolean
*/
public function getPreCalculateFormulas() {
return $this->_preCalculateFormulas;
}
/**
* Set Pre-Calculate Formulas
*
* @param boolean $pValue Pre-Calculate Formulas?
* @return PHPExcel_Writer_HTML
*/
public function setPreCalculateFormulas($pValue = true) {
$this->_preCalculateFormulas = $pValue;
return $this;
}
/**
* Set Pre-Calculate Formulas
*
* @param boolean $pValue Pre-Calculate Formulas?
* @return PHPExcel_Writer_HTML
*/
public function setPreCalculateFormulas($pValue = true) {
$this->_preCalculateFormulas = $pValue;
return $this;
}
/**
* Get images root
*
* @return string
*/
public function getImagesRoot() {
return $this->_imagesRoot;
}
/**
* Get images root
*
* @return string
*/
public function getImagesRoot() {
return $this->_imagesRoot;
}
/**
* Set images root
*
* @param string $pValue
* @return PHPExcel_Writer_HTML
*/
public function setImagesRoot($pValue = '.') {
$this->_imagesRoot = $pValue;
return $this;
}
/**
* Set images root
*
* @param string $pValue
* @return PHPExcel_Writer_HTML
*/
public function setImagesRoot($pValue = '.') {
$this->_imagesRoot = $pValue;
return $this;
}
/**
* Get use inline CSS?
*
* @return boolean
*/
public function getUseInlineCss() {
return $this->_useInlineCss;
}
/**
* Get use inline CSS?
*
* @return boolean
*/
public function getUseInlineCss() {
return $this->_useInlineCss;
}
/**
* Set use inline CSS?
*
* @param boolean $pValue
* @return PHPExcel_Writer_HTML
*/
public function setUseInlineCss($pValue = false) {
$this->_useInlineCss = $pValue;
return $this;
}
/**
* Set use inline CSS?
*
* @param boolean $pValue
* @return PHPExcel_Writer_HTML
*/
public function setUseInlineCss($pValue = false) {
$this->_useInlineCss = $pValue;
return $this;
}
/**
* Converts a string so that spaces occuring at beginning of each new line are replaced by &nbsp;