Performance improvement for readers that reduces overheads when setting titles in multi-worksheet workbooks, by avoiding re-iterating through all worksheet/cells whenever a sheet title is set

git-svn-id: https://phpexcel.svn.codeplex.com/svn/trunk@83603 2327b42d-5241-43d6-9e2a-de5ac946f064
This commit is contained in:
Mark Baker 2011-12-04 11:24:59 +00:00
parent c345c0e8ca
commit 5fb3ffceb0
6 changed files with 32 additions and 10 deletions

View File

@ -571,7 +571,10 @@ class PHPExcel_Reader_Excel2003XML implements PHPExcel_Reader_IReader
$objPHPExcel->setActiveSheetIndex($worksheetID);
if (isset($worksheet_ss['Name'])) {
$worksheetName = self::_convertStringEncoding((string) $worksheet_ss['Name'],$this->_charSet);
$objPHPExcel->getActiveSheet()->setTitle($worksheetName);
// Use false for $updateFormulaCellReferences to prevent adjustment of worksheet references in
// formula cells... during the load, all formulae should be correct, and we're simply bringing
// the worksheet name in line with the formula, not the reverse
$objPHPExcel->getActiveSheet()->setTitle($worksheetName,false);
}
$columnID = 'A';

View File

@ -622,7 +622,11 @@ class PHPExcel_Reader_Excel2007 implements PHPExcel_Reader_IReader
// Load sheet
$docSheet = $excel->createSheet();
$docSheet->setTitle((string) $eleSheet["name"]);
// Use false for $updateFormulaCellReferences to prevent adjustment of worksheet
// references in formula cells... during the load, all formulae should be correct,
// and we're simply bringing the worksheet name in line with the formula, not the
// reverse
$docSheet->setTitle((string) $eleSheet["name"],false);
$fileWorksheet = $worksheets[(string) self::array_item($eleSheet->attributes("http://schemas.openxmlformats.org/officeDocument/2006/relationships"), "id")];
$xmlSheet = simplexml_load_string($this->_getFromZipArchive($zip, "$dir/$fileWorksheet")); //~ http://schemas.openxmlformats.org/spreadsheetml/2006/main");

View File

@ -727,7 +727,10 @@ class PHPExcel_Reader_Excel5 implements PHPExcel_Reader_IReader
// add sheet to PHPExcel object
$this->_phpSheet = $this->_phpExcel->createSheet();
$this->_phpSheet->setTitle($sheet['name']);
// Use false for $updateFormulaCellReferences to prevent adjustment of worksheet references in formula
// cells... during the load, all formulae should be correct, and we're simply bringing the worksheet
// name in line with the formula, not the reverse
$this->_phpSheet->setTitle($sheet['name'],false);
$this->_phpSheet->setSheetState($sheet['sheetState']);
$this->_pos = $sheet['offset'];

View File

@ -414,7 +414,10 @@ class PHPExcel_Reader_Gnumeric implements PHPExcel_Reader_IReader
// Create new Worksheet
$objPHPExcel->createSheet();
$objPHPExcel->setActiveSheetIndex($worksheetID);
$objPHPExcel->getActiveSheet()->setTitle($worksheetName);
// Use false for $updateFormulaCellReferences to prevent adjustment of worksheet references in formula
// cells... during the load, all formulae should be correct, and we're simply bringing the worksheet
// name in line with the formula, not the reverse
$objPHPExcel->getActiveSheet()->setTitle($worksheetName,false);
if ((!$this->_readDataOnly) && (isset($sheet->PrintInformation))) {
if (isset($sheet->PrintInformation->Margins)) {

View File

@ -396,7 +396,10 @@ class PHPExcel_Reader_OOCalc implements PHPExcel_Reader_IReader
$objPHPExcel->setActiveSheetIndex($worksheetID);
if (isset($worksheetDataAttributes['name'])) {
$worksheetName = (string) $worksheetDataAttributes['name'];
$objPHPExcel->getActiveSheet()->setTitle($worksheetName);
// Use false for $updateFormulaCellReferences to prevent adjustment of worksheet references in
// formula cells... during the load, all formulae should be correct, and we're simply
// bringing the worksheet name in line with the formula, not the reverse
$objPHPExcel->getActiveSheet()->setTitle($worksheetName,false);
}
$rowID = 1;

View File

@ -644,9 +644,14 @@ class PHPExcel_Worksheet implements PHPExcel_IComparable
* Set title
*
* @param string $pValue String containing the dimension of this worksheet
* @param string $updateFormulaCellReferences boolean Flag indicating whether cell references in formulae should
* be updated to reflect the new sheet name.
* This should be left as the default true, unless you are
* certain that no formula cells on any worksheet contain
* references to this worksheet
* @return PHPExcel_Worksheet
*/
public function setTitle($pValue = 'Worksheet')
public function setTitle($pValue = 'Worksheet', $updateFormulaCellReferences = true)
{
// Is this a 'rename' or not?
if ($this->getTitle() == $pValue) {
@ -690,6 +695,7 @@ class PHPExcel_Worksheet implements PHPExcel_IComparable
// New title
$newTitle = $this->getTitle();
if ($updateFormulaCellReferences)
PHPExcel_ReferenceHelper::getInstance()->updateNamedFormulas($this->getParent(), $oldTitle, $newTitle);
return $this;
@ -2260,7 +2266,6 @@ class PHPExcel_Worksheet implements PHPExcel_IComparable
// Identify the range that we need to extract from the worksheet
$maxCol = $this->getHighestColumn();
$maxRow = $this->getHighestRow();
// Return
return $this->rangeToArray( 'A1:'.$maxCol.$maxRow,
$nullValue, $calculateFormulas, $formatData, $returnCellRef);
@ -2269,10 +2274,11 @@ class PHPExcel_Worksheet implements PHPExcel_IComparable
/**
* Get row iterator
*
* @param integer $startRow The row number at which to start iterating
* @return PHPExcel_Worksheet_RowIterator
*/
public function getRowIterator() {
return new PHPExcel_Worksheet_RowIterator($this);
public function getRowIterator($startRow = 1) {
return new PHPExcel_Worksheet_RowIterator($this,$startRow);
}
/**