Bugfix: takaakik) Work Item 15455 - getNestingLevel() Error on Excel5 Read

Bugfix: ix to Excel5 Reader when cell annotations are defined before their referenced text objects
This commit is contained in:
Mark Baker 2012-08-01 17:25:10 +01:00
parent f12189b29d
commit 0b60b61104
5 changed files with 122 additions and 92 deletions

View File

@ -339,6 +339,12 @@ class PHPExcel_Chart_DataSeries
foreach($this->_plotValues as $plotValues) { foreach($this->_plotValues as $plotValues) {
$plotValues->refresh($worksheet); $plotValues->refresh($worksheet);
} }
foreach($this->_plotLabel as $plotValues) {
$plotValues->refresh($worksheet);
}
foreach($this->_plotCategory as $plotValues) {
$plotValues->refresh($worksheet);
}
} }
} }

View File

@ -944,101 +944,92 @@ class PHPExcel_Reader_Excel5 implements PHPExcel_Reader_IReader
// 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]; if (isset($allSpContainers[$n + 1]) && is_object($allSpContainers[$n + 1])) {
$spContainer = $allSpContainers[$n + 1];
// we skip all spContainers that are a part of a group shape since we cannot yet handle those // we skip all spContainers that are a part of a group shape since we cannot yet handle those
if ($spContainer->getNestingLevel() > 1) { if ($spContainer->getNestingLevel() > 1) {
continue; continue;
}
// calculate the width and height of the shape
list($startColumn, $startRow) = PHPExcel_Cell::coordinateFromString($spContainer->getStartCoordinates());
list($endColumn, $endRow) = PHPExcel_Cell::coordinateFromString($spContainer->getEndCoordinates());
$startOffsetX = $spContainer->getStartOffsetX();
$startOffsetY = $spContainer->getStartOffsetY();
$endOffsetX = $spContainer->getEndOffsetX();
$endOffsetY = $spContainer->getEndOffsetY();
$width = PHPExcel_Shared_Excel5::getDistanceX($this->_phpSheet, $startColumn, $startOffsetX, $endColumn, $endOffsetX);
$height = PHPExcel_Shared_Excel5::getDistanceY($this->_phpSheet, $startRow, $startOffsetY, $endRow, $endOffsetY);
// calculate offsetX and offsetY of the shape
$offsetX = $startOffsetX * PHPExcel_Shared_Excel5::sizeCol($this->_phpSheet, $startColumn) / 1024;
$offsetY = $startOffsetY * PHPExcel_Shared_Excel5::sizeRow($this->_phpSheet, $startRow) / 256;
switch ($obj['otObjType']) {
case 0x19:
// Note
// echo 'Cell Annotation Object<br />';
// echo 'Object ID is ',$obj['idObjID'],'<br />';
//
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 />';
}
break;
case 0x08:
// echo 'Picture Object<br />';
// picture
// get index to BSE entry (1-based)
$BSEindex = $spContainer->getOPT(0x0104);
$BSECollection = $escherWorkbook->getDggContainer()->getBstoreContainer()->getBSECollection();
$BSE = $BSECollection[$BSEindex - 1];
$blipType = $BSE->getBlipType();
// need check because some blip types are not supported by Escher reader such as EMF
if ($blip = $BSE->getBlip()) {
$ih = imagecreatefromstring($blip->getData());
$drawing = new PHPExcel_Worksheet_MemoryDrawing();
$drawing->setImageResource($ih);
// width, height, offsetX, offsetY
$drawing->setResizeProportional(false);
$drawing->setWidth($width);
$drawing->setHeight($height);
$drawing->setOffsetX($offsetX);
$drawing->setOffsetY($offsetY);
switch ($blipType) {
case PHPExcel_Shared_Escher_DggContainer_BstoreContainer_BSE::BLIPTYPE_JPEG:
$drawing->setRenderingFunction(PHPExcel_Worksheet_MemoryDrawing::RENDERING_JPEG);
$drawing->setMimeType(PHPExcel_Worksheet_MemoryDrawing::MIMETYPE_JPEG);
break;
case PHPExcel_Shared_Escher_DggContainer_BstoreContainer_BSE::BLIPTYPE_PNG:
$drawing->setRenderingFunction(PHPExcel_Worksheet_MemoryDrawing::RENDERING_PNG);
$drawing->setMimeType(PHPExcel_Worksheet_MemoryDrawing::MIMETYPE_PNG);
break;
}
$drawing->setWorksheet($this->_phpSheet);
$drawing->setCoordinates($spContainer->getStartCoordinates());
} }
break; // calculate the width and height of the shape
list($startColumn, $startRow) = PHPExcel_Cell::coordinateFromString($spContainer->getStartCoordinates());
list($endColumn, $endRow) = PHPExcel_Cell::coordinateFromString($spContainer->getEndCoordinates());
default: $startOffsetX = $spContainer->getStartOffsetX();
// other object type $startOffsetY = $spContainer->getStartOffsetY();
break; $endOffsetX = $spContainer->getEndOffsetX();
$endOffsetY = $spContainer->getEndOffsetY();
$width = PHPExcel_Shared_Excel5::getDistanceX($this->_phpSheet, $startColumn, $startOffsetX, $endColumn, $endOffsetX);
$height = PHPExcel_Shared_Excel5::getDistanceY($this->_phpSheet, $startRow, $startOffsetY, $endRow, $endOffsetY);
// calculate offsetX and offsetY of the shape
$offsetX = $startOffsetX * PHPExcel_Shared_Excel5::sizeCol($this->_phpSheet, $startColumn) / 1024;
$offsetY = $startOffsetY * PHPExcel_Shared_Excel5::sizeRow($this->_phpSheet, $startRow) / 256;
switch ($obj['otObjType']) {
case 0x19:
// Note
// echo 'Cell Annotation Object<br />';
// echo 'Object ID is ',$obj['idObjID'],'<br />';
//
if (isset($this->_cellNotes[$obj['idObjID']])) {
$cellNote = $this->_cellNotes[$obj['idObjID']];
if (isset($this->_textObjects[$obj['idObjID']])) {
$textObject = $this->_textObjects[$obj['idObjID']];
$this->_cellNotes[$obj['idObjID']]['objTextData'] = $textObject;
}
}
break;
case 0x08:
// echo 'Picture Object<br />';
// picture
// get index to BSE entry (1-based)
$BSEindex = $spContainer->getOPT(0x0104);
$BSECollection = $escherWorkbook->getDggContainer()->getBstoreContainer()->getBSECollection();
$BSE = $BSECollection[$BSEindex - 1];
$blipType = $BSE->getBlipType();
// need check because some blip types are not supported by Escher reader such as EMF
if ($blip = $BSE->getBlip()) {
$ih = imagecreatefromstring($blip->getData());
$drawing = new PHPExcel_Worksheet_MemoryDrawing();
$drawing->setImageResource($ih);
// width, height, offsetX, offsetY
$drawing->setResizeProportional(false);
$drawing->setWidth($width);
$drawing->setHeight($height);
$drawing->setOffsetX($offsetX);
$drawing->setOffsetY($offsetY);
switch ($blipType) {
case PHPExcel_Shared_Escher_DggContainer_BstoreContainer_BSE::BLIPTYPE_JPEG:
$drawing->setRenderingFunction(PHPExcel_Worksheet_MemoryDrawing::RENDERING_JPEG);
$drawing->setMimeType(PHPExcel_Worksheet_MemoryDrawing::MIMETYPE_JPEG);
break;
case PHPExcel_Shared_Escher_DggContainer_BstoreContainer_BSE::BLIPTYPE_PNG:
$drawing->setRenderingFunction(PHPExcel_Worksheet_MemoryDrawing::RENDERING_PNG);
$drawing->setMimeType(PHPExcel_Worksheet_MemoryDrawing::MIMETYPE_PNG);
break;
}
$drawing->setWorksheet($this->_phpSheet);
$drawing->setCoordinates($spContainer->getStartCoordinates());
}
break;
default:
// other object type
break;
}
} }
} }
@ -1055,6 +1046,14 @@ class PHPExcel_Reader_Excel5 implements PHPExcel_Reader_IReader
if (!empty($this->_cellNotes)) { if (!empty($this->_cellNotes)) {
foreach($this->_cellNotes as $note => $noteDetails) { foreach($this->_cellNotes as $note => $noteDetails) {
if (!isset($noteDetails['objTextData'])) {
if (isset($this->_textObjects[$note])) {
$textObject = $this->_textObjects[$note];
$noteDetails['objTextData'] = $textObject;
} else {
$noteDetails['objTextData']['text'] = '';
}
}
// echo '<b>Cell annotation ',$note,'</b><br />'; // echo '<b>Cell annotation ',$note,'</b><br />';
// var_dump($noteDetails); // var_dump($noteDetails);
// echo '<br />'; // echo '<br />';

View File

@ -238,7 +238,11 @@ class PHPExcel_Shared_Date
* @return boolean * @return boolean
*/ */
public static function isDateTime(PHPExcel_Cell $pCell) { public static function isDateTime(PHPExcel_Cell $pCell) {
return self::isDateTimeFormat($pCell->getParent()->getStyle($pCell->getCoordinate())->getNumberFormat()); return self::isDateTimeFormat(
$pCell->getParent()->getStyle(
$pCell->getCoordinate()
)->getNumberFormat()
);
} // function isDateTime() } // function isDateTime()

View File

@ -50,16 +50,34 @@ $objWorksheet->fromArray(
); );
// Set the Labels for each data series we want to plot // Set the Labels for each data series we want to plot
// Datatype
// Cell reference for data
// Format Code
// Number of datapoints in series
// Data values
// Data Marker
$dataseriesLabels = array( $dataseriesLabels = array(
new PHPExcel_Chart_DataSeriesValues('String', 'Worksheet!$B$1', null, 1), // 2010 new PHPExcel_Chart_DataSeriesValues('String', 'Worksheet!$B$1', null, 1), // 2010
new PHPExcel_Chart_DataSeriesValues('String', 'Worksheet!$C$1', null, 1), // 2011 new PHPExcel_Chart_DataSeriesValues('String', 'Worksheet!$C$1', null, 1), // 2011
new PHPExcel_Chart_DataSeriesValues('String', 'Worksheet!$D$1', null, 1), // 2012 new PHPExcel_Chart_DataSeriesValues('String', 'Worksheet!$D$1', null, 1), // 2012
); );
// Set the X-Axis Labels // Set the X-Axis Labels
// Datatype
// Cell reference for data
// Format Code
// Number of datapoints in series
// Data values
// Data Marker
$xAxisTickValues = array( $xAxisTickValues = array(
new PHPExcel_Chart_DataSeriesValues('String', 'Worksheet!$A$2:$A$5', null, 4), // Q1 to Q4 new PHPExcel_Chart_DataSeriesValues('String', 'Worksheet!$A$2:$A$5', null, 4), // Q1 to Q4
); );
// Set the Data values for each data series we want to plot // Set the Data values for each data series we want to plot
// Datatype
// Cell reference for data
// Format Code
// Number of datapoints in series
// Data values
// Data Marker
$dataSeriesValues = array( $dataSeriesValues = array(
new PHPExcel_Chart_DataSeriesValues('Number', 'Worksheet!$B$2:$B$5', null, 4), new PHPExcel_Chart_DataSeriesValues('Number', 'Worksheet!$B$2:$B$5', null, 4),
new PHPExcel_Chart_DataSeriesValues('Number', 'Worksheet!$C$2:$C$5', null, 4), new PHPExcel_Chart_DataSeriesValues('Number', 'Worksheet!$C$2:$C$5', null, 4),
@ -76,6 +94,7 @@ $series = new PHPExcel_Chart_DataSeries(
$dataSeriesValues // plotValues $dataSeriesValues // plotValues
); );
// Set additional dataseries parameters // Set additional dataseries parameters
// Make it a vertical column rather than a horizontal bar graph
$series->setPlotDirection(PHPExcel_Chart_DataSeries::DIRECTION_COL); $series->setPlotDirection(PHPExcel_Chart_DataSeries::DIRECTION_COL);
// Set the series in the plot area // Set the series in the plot area

View File

@ -92,7 +92,9 @@ Fixed in develop branch:
- Bugfix: (MBaker) Various fixes to Chart handling - Bugfix: (MBaker) Various fixes to Chart handling
- Bugfix: (MBaker) Work item 18370 - Error loading xlsx file with column breaks - Bugfix: (MBaker) Work item 18370 - Error loading xlsx file with column breaks
- Bugfix: (MBaker) OOCalc Reader now handles percentage and currency data types - Bugfix: (MBaker) OOCalc Reader now handles percentage and currency data types
- Bugfix: (MBaker) Work Item 18415- mb_stripos empty delimiter - Bugfix: (MBaker) Work Item 18415 - mb_stripos empty delimiter
- Bugfix: (takaakik) Work Item 15455 - getNestingLevel() Error on Excel5 Read
- Bugfix: (MBaker) Fix to Excel5 Reader when cell annotations are defined before their referenced text objects
2012-05-19 (v1.7.7): 2012-05-19 (v1.7.7):