From 5404406884fb63aed8525448ea6ba9ff0a7d7a93 Mon Sep 17 00:00:00 2001 From: Mark Baker Date: Fri, 21 Jan 2011 17:58:35 +0000 Subject: [PATCH] Feature: Added some support for cell annotations in the Excel5 Reader... now handles annotation blocks beyond the 2,048 character limit for any individual annotation block. (for BIFF5-7 only at present... BIFF8 support is still outstanding) git-svn-id: https://phpexcel.svn.codeplex.com/svn/trunk@67192 2327b42d-5241-43d6-9e2a-de5ac946f064 --- Classes/PHPExcel/Reader/Excel5.php | 36 ++++++++++++++++++++++-------- 1 file changed, 27 insertions(+), 9 deletions(-) diff --git a/Classes/PHPExcel/Reader/Excel5.php b/Classes/PHPExcel/Reader/Excel5.php index 225fd6b..e7d0d97 100644 --- a/Classes/PHPExcel/Reader/Excel5.php +++ b/Classes/PHPExcel/Reader/Excel5.php @@ -1334,6 +1334,11 @@ class PHPExcel_Reader_Excel5 implements PHPExcel_Reader_IReader $this->_pos += 4 + $length; } + + /** + * The NOTE record specifies a comment associated with a particular cell. In Excel 95 (BIFF7) and earlier versions, + * this record stores a note (cell note). This feature was significantly enhanced in Excel 97. + */ private function _readNote() { // echo 'Read Cell Annotation
'; @@ -1351,23 +1356,36 @@ class PHPExcel_Reader_Excel5 implements PHPExcel_Reader_IReader if ($this->_version == self::XLS_BIFF8) { $noteObjID = self::_GetInt2d($recordData, 6); $noteAuthor = trim(substr($recordData, 8)); - // echo 'Note Address=',$cellAddress,'
'; // echo 'Note Object ID=',$noteObjID,'
'; // echo 'Note Author=',$noteAuthor,'
'; } else { - $cellAddress = str_replace('$','',$cellAddress); -// $noteLength = self::_GetInt2d($recordData, 4); - $noteText = trim(substr($recordData, 6)); - - + $extension = false; + if ($cellAddress == '$B$65536') { + // If the address row is -1 and the column is 0, (which translates as $B$65536) then this is a continuation + // note from the previous cell annotation. We're not yet handling this, so annotations longer than the + // max 2048 bytes will probably throw a wobbly. + $row = self::_GetInt2d($recordData, 0); + $extension = true; + $cellAddress = array_pop(array_keys($this->_phpSheet->getComments())); + } // echo 'Note Address=',$cellAddress,'
'; + + $cellAddress = str_replace('$','',$cellAddress); + $noteLength = self::_GetInt2d($recordData, 4); + $noteText = trim(substr($recordData, 6)); // echo 'Note Length=',$noteLength,'
'; // echo 'Note Text=',$noteText,'
'; - $this->_phpSheet->getComment( $cellAddress ) -// ->setAuthor( $author ) - ->setText($this->_parseRichText($noteText) ); + if ($extension) { + $comment = $this->_phpSheet->getComment( $cellAddress ); + $commentText = $comment->getText()->getPlainText(); + $comment->setText($this->_parseRichText($commentText.$noteText) ); + } else { + $this->_phpSheet->getComment( $cellAddress ) +// ->setAuthor( $author ) + ->setText($this->_parseRichText($noteText) ); + } } }