Feature: Support for cell comments in the Excel5 Reader... fixed some problems with the comments in BIFF8 comments

git-svn-id: https://phpexcel.svn.codeplex.com/svn/trunk@67501 2327b42d-5241-43d6-9e2a-de5ac946f064
This commit is contained in:
Mark Baker 2011-01-28 12:56:38 +00:00
parent 545c2a0f19
commit c6d58661e1
1 changed files with 52 additions and 28 deletions

View File

@ -726,17 +726,18 @@ class PHPExcel_Reader_Excel5 implements PHPExcel_Reader_IReader
// Initialize objs // Initialize objs
$this->_objs = array(); $this->_objs = array();
// Initialize text objs
$this->_textObjects = array();
// Initialize shared formula parts // Initialize shared formula parts
$this->_sharedFormulaParts = array(); $this->_sharedFormulaParts = array();
// Initialize shared formulas // Initialize shared formulas
$this->_sharedFormulas = array(); $this->_sharedFormulas = array();
// Initialize text objs
$this->_textObjects = array();
// Initialize cell annotations // Initialize cell annotations
$this->_cellNotes = array(); $this->_cellNotes = array();
$this->textObjRef = -1;
while ($this->_pos <= $this->_dataSize - 4) { while ($this->_pos <= $this->_dataSize - 4) {
$code = self::_GetInt2d($this->_data, $this->_pos); $code = self::_GetInt2d($this->_data, $this->_pos);
@ -815,10 +816,10 @@ class PHPExcel_Reader_Excel5 implements PHPExcel_Reader_IReader
// treat OBJ records // treat OBJ records
foreach ($this->_objs as $n => $obj) { foreach ($this->_objs as $n => $obj) {
// echo '<b>Object</b> ID is ',$n,'<br />'; // echo '<hr /><b>Object</b> reference is ',$n,'<br />';
// var_dump($obj); // var_dump($obj);
// echo '<br />'; // echo '<br />';
//
// the first shape container never has a corresponding OBJ record, hence $n + 1 // the first shape container never has a corresponding OBJ record, hence $n + 1
$spContainer = $allSpContainers[$n + 1]; $spContainer = $allSpContainers[$n + 1];
@ -848,12 +849,30 @@ class PHPExcel_Reader_Excel5 implements PHPExcel_Reader_IReader
case 0x19: case 0x19:
// Note // Note
// echo 'Cell Annotation Object<br />'; // echo 'Cell Annotation Object<br />';
$this->_objs[$n]['objTextData'] = $this->_textObjects[$obj['idObjID']-1]; // echo 'Object ID is ',$obj['idObjID'],'<br />';
$text = $this->_textObjects[$obj['idObjID']-1]['text']; //
if (isset($this->_cellNotes[$obj['idObjID']])) {
$cellNote = $this->_cellNotes[$obj['idObjID']];
// echo '_cellNotes[',$obj['idObjID'],']: ';
// var_dump($cellNote);
// echo '<br />';
//
if (isset($this->_textObjects[$obj['idObjID']])) {
$textObject = $this->_textObjects[$obj['idObjID']];
// echo '_textObject: ';
// var_dump($textObject);
// echo '<br />';
//
$this->_cellNotes[$obj['idObjID']]['objTextData'] = $textObject;
$text = $textObject['text'];
}
// echo $text,'<br />'; // echo $text,'<br />';
}
break; break;
case 0x08: case 0x08:
// echo 'Picture Object<br />';
// picture // picture
// get index to BSE entry (1-based) // get index to BSE entry (1-based)
@ -915,15 +934,11 @@ class PHPExcel_Reader_Excel5 implements PHPExcel_Reader_IReader
foreach($this->_cellNotes as $note => $noteDetails) { foreach($this->_cellNotes as $note => $noteDetails) {
// echo '<b>Cell annotation ',$note,'</b><br />'; // echo '<b>Cell annotation ',$note,'</b><br />';
// var_dump($noteDetails); // var_dump($noteDetails);
// echo '<br />';
if (isset($this->_objs[$noteDetails['objectID']-1])) {
// var_dump($this->_objs[$noteDetails['objectID']-1]);
// echo '<br />'; // echo '<br />';
$cellAddress = str_replace('$','',$noteDetails['cellRef']); $cellAddress = str_replace('$','',$noteDetails['cellRef']);
$this->_phpSheet->getComment( $cellAddress ) $this->_phpSheet->getComment( $cellAddress )
->setAuthor( $noteDetails['author'] ) ->setAuthor( $noteDetails['author'] )
->setText($this->_parseRichText($this->_objs[$noteDetails['objectID']-1]['objTextData']['text']) ); ->setText($this->_parseRichText($noteDetails['objTextData']['text']) );
}
} }
} }
} }
@ -1397,12 +1412,13 @@ class PHPExcel_Reader_Excel5 implements PHPExcel_Reader_IReader
$cellAddress = $this->_readBIFF8CellAddress(substr($recordData, 0, 4)); $cellAddress = $this->_readBIFF8CellAddress(substr($recordData, 0, 4));
if ($this->_version == self::XLS_BIFF8) { if ($this->_version == self::XLS_BIFF8) {
$noteObjID = self::_GetInt2d($recordData, 6); $noteObjID = self::_GetInt2d($recordData, 6);
$noteAuthor = trim(substr($recordData, 8)); $noteAuthor = self::_readUnicodeStringLong(substr($recordData, 8));
$noteAuthor = $noteAuthor['value'];
// echo 'Note Address=',$cellAddress,'<br />'; // echo 'Note Address=',$cellAddress,'<br />';
// echo 'Note Object ID=',$noteObjID,'<br />'; // echo 'Note Object ID=',$noteObjID,'<br />';
// echo 'Note Author=',$noteAuthor,'<hr />'; // echo 'Note Author=',$noteAuthor,'<hr />';
// //
$this->_cellNotes[] = array('cellRef' => $cellAddress, $this->_cellNotes[$noteObjID] = array('cellRef' => $cellAddress,
'objectID' => $noteObjID, 'objectID' => $noteObjID,
'author' => $noteAuthor 'author' => $noteAuthor
); );
@ -1444,7 +1460,6 @@ class PHPExcel_Reader_Excel5 implements PHPExcel_Reader_IReader
*/ */
private function _readTextObject() private function _readTextObject()
{ {
// echo '<b>Read Text Object</b><br />';
$length = self::_GetInt2d($this->_data, $this->_pos + 2); $length = self::_GetInt2d($this->_data, $this->_pos + 2);
$recordData = substr($this->_data, $this->_pos + 4, $length); $recordData = substr($this->_data, $this->_pos + 4, $length);
@ -1460,18 +1475,23 @@ class PHPExcel_Reader_Excel5 implements PHPExcel_Reader_IReader
// rot: 2 bytes; rotation // rot: 2 bytes; rotation
// cchText: 2 bytes; length of the text (in the first continue record) // cchText: 2 bytes; length of the text (in the first continue record)
// cbRuns: 2 bytes; length of the formatting (in the second continue record) // cbRuns: 2 bytes; length of the formatting (in the second continue record)
// followed by the continuation records containing the actual text and formatting
$grbitOpts = self::_GetInt2d($recordData, 0); $grbitOpts = self::_GetInt2d($recordData, 0);
$rot = self::_GetInt2d($recordData, 2); $rot = self::_GetInt2d($recordData, 2);
$cchText = self::_GetInt2d($recordData, 10); $cchText = self::_GetInt2d($recordData, 10);
$cbRuns = self::_GetInt2d($recordData, 12); $cbRuns = self::_GetInt2d($recordData, 12);
$text = $this->_getSplicedRecordData(); $text = $this->_getSplicedRecordData();
$this->_textObjects[] = array( 'text' => substr($text["recordData"],$text["spliceOffsets"][0]+1,$cchText), $this->_textObjects[$this->textObjRef] = array(
'text' => substr($text["recordData"],$text["spliceOffsets"][0]+1,$cchText),
'format' => substr($text["recordData"],$text["spliceOffsets"][1],$cbRuns), 'format' => substr($text["recordData"],$text["spliceOffsets"][1],$cbRuns),
'alignment' => $grbitOpts, 'alignment' => $grbitOpts,
'rotation' => $rot 'rotation' => $rot
); );
// echo '<b>_readTextObject()</b><br />';
// var_dump($this->_textObjects[$this->textObjRef]);
// echo '<br />';
} }
/** /**
@ -3884,7 +3904,11 @@ class PHPExcel_Reader_Excel5 implements PHPExcel_Reader_IReader
'idObjID' => $idObjID, 'idObjID' => $idObjID,
'grbitOpts' => $grbitOpts 'grbitOpts' => $grbitOpts
); );
$this->textObjRef = $idObjID;
// echo '<b>_readObj()</b><br />';
// var_dump(end($this->_objs));
// echo '<br />';
} }
/** /**