From d24e64080166f04e36a3a077fb5ba6271eb2b334 Mon Sep 17 00:00:00 2001 From: k1LoW Date: Thu, 9 Aug 2012 10:13:05 +0900 Subject: [PATCH] Support SheetView `view` param --- Classes/PHPExcel/Worksheet/SheetView.php | 42 +++++++++++++++++++ .../PHPExcel/Writer/Excel2007/Worksheet.php | 5 +++ 2 files changed, 47 insertions(+) diff --git a/Classes/PHPExcel/Worksheet/SheetView.php b/Classes/PHPExcel/Worksheet/SheetView.php index 418e45a..e76cec5 100644 --- a/Classes/PHPExcel/Worksheet/SheetView.php +++ b/Classes/PHPExcel/Worksheet/SheetView.php @@ -35,6 +35,11 @@ */ class PHPExcel_Worksheet_SheetView { + + /* Fill types */ + const VIEW_PAGE_LAYOUT = 'pageLayout'; + const VIEW_PAGE_BREAK_PREVIEW = 'pageBreakPreview'; + /** * ZoomScale * @@ -53,6 +58,15 @@ class PHPExcel_Worksheet_SheetView */ private $_zoomScaleNormal = 100; + /** + * View + * + * Valid values range from 10 to 400. + * + * @var string + */ + private $_view = false; + /** * Create a new PHPExcel_Worksheet_SheetView */ @@ -116,6 +130,34 @@ class PHPExcel_Worksheet_SheetView return $this; } + /** + * Get View + * + * @return int + */ + public function getView() { + return $this->_view; + } + + /** + * Set View + * + * Valid values range from 10 to 400. + * + * @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; + } else { + throw new Exception("Invalid view."); + } + return $this; + } + /** * Implement PHP __clone to create a deep clone, not just a shallow copy. */ diff --git a/Classes/PHPExcel/Writer/Excel2007/Worksheet.php b/Classes/PHPExcel/Writer/Excel2007/Worksheet.php index b97648d..036f4b7 100644 --- a/Classes/PHPExcel/Writer/Excel2007/Worksheet.php +++ b/Classes/PHPExcel/Writer/Excel2007/Worksheet.php @@ -218,6 +218,11 @@ class PHPExcel_Writer_Excel2007_Worksheet extends PHPExcel_Writer_Excel2007_Writ $objWriter->writeAttribute('zoomScaleNormal', $pSheet->getSheetView()->getZoomScaleNormal()); } + // View + if ($pSheet->getSheetView()->getView() != false) { + $objWriter->writeAttribute('view', $pSheet->getSheetView()->getView()); + } + // Gridlines if ($pSheet->getShowGridlines()) { $objWriter->writeAttribute('showGridLines', 'true');