From db2a7cbabfc42dabb45ef74481eb37f68da02163 Mon Sep 17 00:00:00 2001 From: Andrey Mironov Date: Tue, 30 Oct 2012 16:46:18 +0600 Subject: [PATCH] Search style by identity in PHPExcel_Worksheet::duplicateStyle() --- Classes/PHPExcel.php | 16 ++++++++++++++++ Classes/PHPExcel/Worksheet.php | 6 +++--- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/Classes/PHPExcel.php b/Classes/PHPExcel.php index cc70286d..f60a15cf 100644 --- a/Classes/PHPExcel.php +++ b/Classes/PHPExcel.php @@ -607,6 +607,22 @@ class PHPExcel return false; } + /** + * Check if style exists in style collection + * + * @param PHPExcel_Style $style + * @return boolean + */ + public function cellXfExists($pCellStyle = null) + { + foreach ($this->_cellXfCollection as $cellXf) { + if ($cellXf === $pCellStyle) { + return true; + } + } + return false; + } + /** * Get default style * diff --git a/Classes/PHPExcel/Worksheet.php b/Classes/PHPExcel/Worksheet.php index bc58a696..4ffd94f3 100644 --- a/Classes/PHPExcel/Worksheet.php +++ b/Classes/PHPExcel/Worksheet.php @@ -1454,9 +1454,9 @@ class PHPExcel_Worksheet implements PHPExcel_IComparable // Add the style to the workbook if necessary $workbook = $this->_parent; - if ($existingStyle = $this->_parent->getCellXfByHashCode($pCellStyle->getHashCode())) { - // there is already such cell Xf in our collection - $xfIndex = $existingStyle->getIndex(); + if ($this->_parent->cellXfExists($pCellStyle)) { + // there is already this cell Xf in our collection + $xfIndex = $pCellStyle->getIndex(); } else { // we don't have such a cell Xf, need to add $workbook->addCellXf($pCellStyle);