From 496b76e70a3851d953bdede580e7d9a4390584fa Mon Sep 17 00:00:00 2001 From: Mark Baker Date: Wed, 8 Jan 2014 10:15:07 +0000 Subject: [PATCH] Bugfix: Work Item CP20604 - Adding Sheet to Workbook Bug --- Classes/PHPExcel.php | 5 +++++ Classes/PHPExcel/Worksheet.php | 16 +++++++++------- changelog.txt | 1 + 3 files changed, 15 insertions(+), 7 deletions(-) diff --git a/Classes/PHPExcel.php b/Classes/PHPExcel.php index 29d0aa0f..e01581a2 100644 --- a/Classes/PHPExcel.php +++ b/Classes/PHPExcel.php @@ -527,6 +527,11 @@ class PHPExcel ++$this->_activeSheetIndex; } } + + if ($pSheet->getParent() === null) { + $pSheet->rebindParent($this); + } + return $pSheet; } diff --git a/Classes/PHPExcel/Worksheet.php b/Classes/PHPExcel/Worksheet.php index 753e9c2a..b61f76e6 100644 --- a/Classes/PHPExcel/Worksheet.php +++ b/Classes/PHPExcel/Worksheet.php @@ -794,14 +794,16 @@ class PHPExcel_Worksheet implements PHPExcel_IComparable * @return PHPExcel_Worksheet */ public function rebindParent(PHPExcel $parent) { - $namedRanges = $this->_parent->getNamedRanges(); - foreach ($namedRanges as $namedRange) { - $parent->addNamedRange($namedRange); - } + if ($this->_parent !== null) { + $namedRanges = $this->_parent->getNamedRanges(); + foreach ($namedRanges as $namedRange) { + $parent->addNamedRange($namedRange); + } - $this->_parent->removeSheetByIndex( - $this->_parent->getIndex($this) - ); + $this->_parent->removeSheetByIndex( + $this->_parent->getIndex($this) + ); + } $this->_parent = $parent; return $this; diff --git a/changelog.txt b/changelog.txt index 96f97c6d..1d1222b9 100644 --- a/changelog.txt +++ b/changelog.txt @@ -46,6 +46,7 @@ Fixed in develop branch for release v1.8.0: - Bugfix: (Roy Shahbazian) Work Item GH-299 - Fixed typo in Chart/Layout set/getYMode() - Bugfix: (EliuFlorez) Work item GH-279 - Fatal error: Call to a member function cellExists() line: 3327 in calculation.php if referenced worksheet doesn't exist - Bugfix: (MBaker) Work Item GH-290 - AdvancedValueBinder "Division by zero"-error +- Bugfix: (MBaker) Work Item CP20604 - Adding Sheet to Workbook Bug - Feature: (amerov) - Implementation of the Excel HLOOKUP() function - Feature: (MBaker) - Added "Quote Prefix" to style settings (Excel2007 Reader and Writer only) - Feature: (MBaker) - Added Horizontal FILL alignment for Excel5 and Excel2007 Readers/Writers, and Horizontal DISTRIBUTED alignment for Excel2007 Reader/Writer