From 9c213cc1cb09017594cee0eb9c4138d2a1ab0e6c Mon Sep 17 00:00:00 2001 From: Mark Baker Date: Wed, 7 Nov 2012 09:34:31 +0000 Subject: [PATCH] xlsx files written by LibreOffice use "true" and "false" for boolean properties rather than "1" and "0" found in MS Excel generated xlsx files; modify Excel2007 Reader to handle both options --- Classes/PHPExcel/Reader/Excel2007.php | 26 ++++++++++++++------- Classes/PHPExcel/Reader/Excel2007/Chart.php | 2 +- 2 files changed, 18 insertions(+), 10 deletions(-) diff --git a/Classes/PHPExcel/Reader/Excel2007.php b/Classes/PHPExcel/Reader/Excel2007.php index ddb4258..fc52480 100644 --- a/Classes/PHPExcel/Reader/Excel2007.php +++ b/Classes/PHPExcel/Reader/Excel2007.php @@ -626,15 +626,15 @@ class PHPExcel_Reader_Excel2007 extends PHPExcel_Reader_Abstract implements PHPE } if (isset($xmlSheet->sheetViews->sheetView['showGridLines'])) { - $docSheet->setShowGridLines((string)$xmlSheet->sheetViews->sheetView['showGridLines'] ? true : false); + $docSheet->setShowGridLines(self::boolean((string)$xmlSheet->sheetViews->sheetView['showGridLines'])); } if (isset($xmlSheet->sheetViews->sheetView['showRowColHeaders'])) { - $docSheet->setShowRowColHeaders((string)$xmlSheet->sheetViews->sheetView['showRowColHeaders'] ? true : false); + $docSheet->setShowRowColHeaders(self::boolean((string)$xmlSheet->sheetViews->sheetView['showRowColHeaders'])); } if (isset($xmlSheet->sheetViews->sheetView['rightToLeft'])) { - $docSheet->setRightToLeft((string)$xmlSheet->sheetViews->sheetView['rightToLeft'] ? true : false); + $docSheet->setRightToLeft(self::boolean((string)$xmlSheet->sheetViews->sheetView['rightToLeft'])); } if (isset($xmlSheet->sheetViews->sheetView->pane)) { @@ -688,7 +688,7 @@ class PHPExcel_Reader_Excel2007 extends PHPExcel_Reader_Abstract implements PHPE } if (isset($xmlSheet->sheetPr) && isset($xmlSheet->sheetPr->pageSetUpPr)) { - if (isset($xmlSheet->sheetPr->pageSetUpPr['fitToPage']) && $xmlSheet->sheetPr->pageSetUpPr['fitToPage'] == false) { + if (isset($xmlSheet->sheetPr->pageSetUpPr['fitToPage']) && !self::boolean((string) $xmlSheet->sheetPr->pageSetUpPr['fitToPage'])) { $docSheet->getPageSetup()->setFitToPage(false); } else { $docSheet->getPageSetup()->setFitToPage(true); @@ -714,13 +714,13 @@ class PHPExcel_Reader_Excel2007 extends PHPExcel_Reader_Abstract implements PHPE if ($col["style"] && !$this->_readDataOnly) { $docSheet->getColumnDimension(PHPExcel_Cell::stringFromColumnIndex($i))->setXfIndex(intval($col["style"])); } - if ($col["bestFit"]) { + if (self::boolean($col["bestFit"])) { //$docSheet->getColumnDimension(PHPExcel_Cell::stringFromColumnIndex($i))->setAutoSize(true); } - if ($col["hidden"]) { + if (self::boolean($col["hidden"])) { $docSheet->getColumnDimension(PHPExcel_Cell::stringFromColumnIndex($i))->setVisible(false); } - if ($col["collapsed"]) { + if (self::boolean($col["collapsed"])) { $docSheet->getColumnDimension(PHPExcel_Cell::stringFromColumnIndex($i))->setCollapsed(true); } if ($col["outlineLevel"] > 0) { @@ -757,10 +757,10 @@ class PHPExcel_Reader_Excel2007 extends PHPExcel_Reader_Abstract implements PHPE if ($row["ht"] && !$this->_readDataOnly) { $docSheet->getRowDimension(intval($row["r"]))->setRowHeight(floatval($row["ht"])); } - if ($row["hidden"] && !$this->_readDataOnly) { + if (self::boolean($row["hidden"]) && !$this->_readDataOnly) { $docSheet->getRowDimension(intval($row["r"]))->setVisible(false); } - if ($row["collapsed"]) { + if (self::boolean($row["collapsed"])) { $docSheet->getRowDimension(intval($row["r"]))->setCollapsed(true); } if ($row["outlineLevel"] > 0) { @@ -1956,4 +1956,12 @@ class PHPExcel_Reader_Excel2007 extends PHPExcel_Reader_Abstract implements PHPE return $style; } + + private static function boolean($value) + { + if (is_numeric($value)) { + return (boolean) $value; + } + return ($value === 'true') ? TRUE : FALSE; + } } diff --git a/Classes/PHPExcel/Reader/Excel2007/Chart.php b/Classes/PHPExcel/Reader/Excel2007/Chart.php index f695c4a..c7fcdaf 100644 --- a/Classes/PHPExcel/Reader/Excel2007/Chart.php +++ b/Classes/PHPExcel/Reader/Excel2007/Chart.php @@ -42,7 +42,7 @@ class PHPExcel_Reader_Excel2007_Chart } elseif ($format == 'integer') { return (integer) $attributes[$name]; } elseif ($format == 'boolean') { - return (boolean) ($attributes[$name] == '0') ? false : true; + return (boolean) ($attributes[$name] === '0' || $attributes[$name] !== 'true') ? false : true; } else { return (float) $attributes[$name]; }