diff --git a/Classes/PHPExcel/Reader/Excel2007.php b/Classes/PHPExcel/Reader/Excel2007.php index a98a1061..16284837 100644 --- a/Classes/PHPExcel/Reader/Excel2007.php +++ b/Classes/PHPExcel/Reader/Excel2007.php @@ -775,6 +775,10 @@ class PHPExcel_Reader_Excel2007 implements PHPExcel_Reader_IReader $docSheet->getSheetView()->setZoomScaleNormal( intval($xmlSheet->sheetViews->sheetView['zoomScaleNormal']) ); } + if (isset($xmlSheet->sheetViews->sheetView['view'])) { + $docSheet->getSheetView()->setView((string) $xmlSheet->sheetViews->sheetView['view']); + } + if (isset($xmlSheet->sheetViews->sheetView['showGridLines'])) { $docSheet->setShowGridLines((string)$xmlSheet->sheetViews->sheetView['showGridLines'] ? true : false); } diff --git a/Classes/PHPExcel/Worksheet/SheetView.php b/Classes/PHPExcel/Worksheet/SheetView.php index e76cec5e..9ae4bf06 100644 --- a/Classes/PHPExcel/Worksheet/SheetView.php +++ b/Classes/PHPExcel/Worksheet/SheetView.php @@ -36,9 +36,16 @@ class PHPExcel_Worksheet_SheetView { - /* Fill types */ - const VIEW_PAGE_LAYOUT = 'pageLayout'; - const VIEW_PAGE_BREAK_PREVIEW = 'pageBreakPreview'; + /* Sheet View types */ + const SHEETVIEW_NORMAL = 'normal'; + const SHEETVIEW_PAGE_LAYOUT = 'pageLayout'; + const SHEETVIEW_PAGE_BREAK_PREVIEW = 'pageBreakPreview'; + + private static $_sheetViewTypes = array( + self::SHEETVIEW_NORMAL, + self::SHEETVIEW_PAGE_LAYOUT, + self::SHEETVIEW_PAGE_BREAK_PREVIEW, + ); /** * ZoomScale @@ -65,7 +72,7 @@ class PHPExcel_Worksheet_SheetView * * @var string */ - private $_view = false; + private $_sheetviewType = self::SHEETVIEW_NORMAL; /** * Create a new PHPExcel_Worksheet_SheetView @@ -133,28 +140,35 @@ class PHPExcel_Worksheet_SheetView /** * Get View * - * @return int + * @return string */ public function getView() { - return $this->_view; + return $this->_sheetviewType; } /** * Set View * - * Valid values range from 10 to 400. + * Valid values are + * 'normal' self::SHEETVIEW_NORMAL + * 'pageLayout' self::SHEETVIEW_PAGE_LAYOUT + * 'pageBreakPreview' self::SHEETVIEW_PAGE_BREAK_PREVIEW * * @param string $pValue * @throws Exception * @return PHPExcel_Worksheet_SheetView */ - public function setView($pValue = false) { - // Microsoft Office Excel 2007 only allows setting a view 'pageLayout' or 'pageBreakPreview' via the user interface, - if (($pValue === false) || in_array($pValue, array(self::VIEW_PAGE_LAYOUT, self::VIEW_PAGE_BREAK_PREVIEW))) { - $this->_view = $pValue; + public function setView($pValue = NULL) { + // MS Excel 2007 allows setting the view to 'normal', 'pageLayout' or 'pageBreakPreview' + // via the user interface + if ($pValue === NULL) + $pValue = self::SHEETVIEW_NORMAL; + if (in_array($pValue, self::$_sheetViewTypes)) { + $this->_sheetviewType = $pValue; } else { - throw new Exception("Invalid view."); + throw new Exception("Invalid sheetview layout type."); } + return $this; } diff --git a/Classes/PHPExcel/Writer/Excel2007/Worksheet.php b/Classes/PHPExcel/Writer/Excel2007/Worksheet.php index 036f4b73..29e0aed3 100644 --- a/Classes/PHPExcel/Writer/Excel2007/Worksheet.php +++ b/Classes/PHPExcel/Writer/Excel2007/Worksheet.php @@ -194,7 +194,7 @@ class PHPExcel_Writer_Excel2007_Worksheet extends PHPExcel_Writer_Excel2007_Writ * @param PHPExcel_Worksheet $pSheet Worksheet * @throws Exception */ - private function _writeSheetViews(PHPExcel_Shared_XMLWriter $objWriter = null, PHPExcel_Worksheet $pSheet = null) + private function _writeSheetViews(PHPExcel_Shared_XMLWriter $objWriter = NULL, PHPExcel_Worksheet $pSheet = NULL) { // sheetViews $objWriter->startElement('sheetViews'); @@ -218,8 +218,8 @@ class PHPExcel_Writer_Excel2007_Worksheet extends PHPExcel_Writer_Excel2007_Writ $objWriter->writeAttribute('zoomScaleNormal', $pSheet->getSheetView()->getZoomScaleNormal()); } - // View - if ($pSheet->getSheetView()->getView() != false) { + // View Layout Type + if ($pSheet->getSheetView()->getView() !== PHPExcel_Worksheet_SheetView::SHEETVIEW_NORMAL) { $objWriter->writeAttribute('view', $pSheet->getSheetView()->getView()); } diff --git a/changelog.txt b/changelog.txt index faac4ebd..337a81ee 100644 --- a/changelog.txt +++ b/changelog.txt @@ -79,6 +79,7 @@ Fixed in develop branch: - Feature: (MBaker) Initial version of HTML Reader - Feature: (Progi1984) & (blazzy) Work items 9605 - Implement support for AutoFilter in PHPExcel_Writer_Excel5 - Feature: (MBaker) Modified ERF and ERFC Engineering functions to accept Excel 2010's modified acceptance of negative arguments +- Feature: (k1LoW) Support SheetView `view` attribute (Excel2007) - General: (alexgann) Add Currency detection to the Advanced Value Binder - General: (MBaker) Work item 18404 - setCellValueExplicitByColumnAndRow() do not return PHPExcel_Worksheet - General: (MBaker) Work item 18324 - Reader factory doesn't read anymore XLTX and XLT files