From f71aeebd30cc4b12ca1c6433778272fd00d56b3a Mon Sep 17 00:00:00 2001 From: Mark Baker Date: Wed, 15 Dec 2010 17:19:30 +0000 Subject: [PATCH] Minor performance/memory tweaks to the Excel2007 Writer git-svn-id: https://phpexcel.svn.codeplex.com/svn/trunk@65356 2327b42d-5241-43d6-9e2a-de5ac946f064 --- Classes/PHPExcel/Cell.php | 7 ++++--- Classes/PHPExcel/Writer/Excel2007.php | 13 ++++--------- Classes/PHPExcel/Writer/Excel2007/WriterPart.php | 13 +++++++++++++ 3 files changed, 21 insertions(+), 12 deletions(-) diff --git a/Classes/PHPExcel/Cell.php b/Classes/PHPExcel/Cell.php index 454de210..66363355 100644 --- a/Classes/PHPExcel/Cell.php +++ b/Classes/PHPExcel/Cell.php @@ -140,7 +140,9 @@ class PHPExcel_Cell $this->_parent = $pSheet; // Set datatype? - if ($pDataType !== NULL) { + if ($pDataType !== null) { + if ($pDataType == PHPExcel_Cell_DataType::TYPE_STRING2) + $pDataType = PHPExcel_Cell_DataType::TYPE_STRING; $this->_dataType = $pDataType; } else { if (!self::getValueBinder()->bindValue($this, $pValue)) { @@ -624,8 +626,7 @@ class PHPExcel_Cell // Extract range if (strpos($pRange, ':') === false) { - $rangeA = $pRange; - $rangeB = $pRange; + $rangeA = $rangeB = $pRange; } else { list($rangeA, $rangeB) = explode(':', $pRange); } diff --git a/Classes/PHPExcel/Writer/Excel2007.php b/Classes/PHPExcel/Writer/Excel2007.php index c87de9b0..9efdbd8f 100644 --- a/Classes/PHPExcel/Writer/Excel2007.php +++ b/Classes/PHPExcel/Writer/Excel2007.php @@ -54,7 +54,7 @@ class PHPExcel_Writer_Excel2007 implements PHPExcel_Writer_IWriter * * @var PHPExcel_Writer_Excel2007_WriterPart[] */ - private $_writerParts; + private $_writerParts = array(); /** * Private PHPExcel @@ -68,7 +68,7 @@ class PHPExcel_Writer_Excel2007 implements PHPExcel_Writer_IWriter * * @var string[] */ - private $_stringTable; + private $_stringTable = array(); /** * Private unique PHPExcel_Style_Conditional HashTable @@ -124,7 +124,7 @@ class PHPExcel_Writer_Excel2007 implements PHPExcel_Writer_IWriter * * @var string */ - private $_diskCachingDirectory; + private $_diskCachingDirectory = './'; /** * Create a new PHPExcel_Writer_Excel2007 @@ -136,9 +136,6 @@ class PHPExcel_Writer_Excel2007 implements PHPExcel_Writer_IWriter // Assign PHPExcel $this->setPHPExcel($pPHPExcel); - // Set up disk caching location - $this->_diskCachingDirectory = './'; - $writerPartsArray = array( 'stringtable' => 'PHPExcel_Writer_Excel2007_StringTable', 'contenttypes' => 'PHPExcel_Writer_Excel2007_ContentTypes', 'docprops' => 'PHPExcel_Writer_Excel2007_DocProps', @@ -154,8 +151,7 @@ class PHPExcel_Writer_Excel2007 implements PHPExcel_Writer_IWriter // Initialise writer parts // and Assign their parent IWriters foreach ($writerPartsArray as $writer => $class) { - $this->_writerParts[$writer] = new $class(); - $this->_writerParts[$writer]->setParentWriter($this); + $this->_writerParts[$writer] = new $class($this); } $hashTablesArray = array( '_stylesConditionalHashTable', '_fillHashTable', '_fontHashTable', @@ -163,7 +159,6 @@ class PHPExcel_Writer_Excel2007 implements PHPExcel_Writer_IWriter ); // Set HashTable variables - $this->_stringTable = array(); foreach ($hashTablesArray as $tableName) { $this->$tableName = new PHPExcel_HashTable(); } diff --git a/Classes/PHPExcel/Writer/Excel2007/WriterPart.php b/Classes/PHPExcel/Writer/Excel2007/WriterPart.php index 93d7fbde..58270d19 100644 --- a/Classes/PHPExcel/Writer/Excel2007/WriterPart.php +++ b/Classes/PHPExcel/Writer/Excel2007/WriterPart.php @@ -65,4 +65,17 @@ abstract class PHPExcel_Writer_Excel2007_WriterPart throw new Exception("No parent PHPExcel_Writer_IWriter assigned."); } } + + /** + * Set parent IWriter object + * + * @param PHPExcel_Writer_IWriter $pWriter + * @throws Exception + */ + public function __construct(PHPExcel_Writer_IWriter $pWriter = null) { + if (!is_null($pWriter)) { + $this->_parentWriter = $pWriter; + } + } + }