Feature: (k1LoW) Support SheetView `view` attribute (Excel2007)

modified to add reader support, and refactored validation
This commit is contained in:
unknown 2012-08-09 12:35:04 +01:00
parent f830c0f3a8
commit 14686dbb42
4 changed files with 34 additions and 15 deletions

View File

@ -775,6 +775,10 @@ class PHPExcel_Reader_Excel2007 implements PHPExcel_Reader_IReader
$docSheet->getSheetView()->setZoomScaleNormal( intval($xmlSheet->sheetViews->sheetView['zoomScaleNormal']) ); $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'])) { if (isset($xmlSheet->sheetViews->sheetView['showGridLines'])) {
$docSheet->setShowGridLines((string)$xmlSheet->sheetViews->sheetView['showGridLines'] ? true : false); $docSheet->setShowGridLines((string)$xmlSheet->sheetViews->sheetView['showGridLines'] ? true : false);
} }

View File

@ -36,9 +36,16 @@
class PHPExcel_Worksheet_SheetView class PHPExcel_Worksheet_SheetView
{ {
/* Fill types */ /* Sheet View types */
const VIEW_PAGE_LAYOUT = 'pageLayout'; const SHEETVIEW_NORMAL = 'normal';
const VIEW_PAGE_BREAK_PREVIEW = 'pageBreakPreview'; 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 * ZoomScale
@ -65,7 +72,7 @@ class PHPExcel_Worksheet_SheetView
* *
* @var string * @var string
*/ */
private $_view = false; private $_sheetviewType = self::SHEETVIEW_NORMAL;
/** /**
* Create a new PHPExcel_Worksheet_SheetView * Create a new PHPExcel_Worksheet_SheetView
@ -133,28 +140,35 @@ class PHPExcel_Worksheet_SheetView
/** /**
* Get View * Get View
* *
* @return int * @return string
*/ */
public function getView() { public function getView() {
return $this->_view; return $this->_sheetviewType;
} }
/** /**
* Set View * 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 * @param string $pValue
* @throws Exception * @throws Exception
* @return PHPExcel_Worksheet_SheetView * @return PHPExcel_Worksheet_SheetView
*/ */
public function setView($pValue = false) { public function setView($pValue = NULL) {
// Microsoft Office Excel 2007 only allows setting a view 'pageLayout' or 'pageBreakPreview' via the user interface, // MS Excel 2007 allows setting the view to 'normal', 'pageLayout' or 'pageBreakPreview'
if (($pValue === false) || in_array($pValue, array(self::VIEW_PAGE_LAYOUT, self::VIEW_PAGE_BREAK_PREVIEW))) { // via the user interface
$this->_view = $pValue; if ($pValue === NULL)
$pValue = self::SHEETVIEW_NORMAL;
if (in_array($pValue, self::$_sheetViewTypes)) {
$this->_sheetviewType = $pValue;
} else { } else {
throw new Exception("Invalid view."); throw new Exception("Invalid sheetview layout type.");
} }
return $this; return $this;
} }

View File

@ -194,7 +194,7 @@ class PHPExcel_Writer_Excel2007_Worksheet extends PHPExcel_Writer_Excel2007_Writ
* @param PHPExcel_Worksheet $pSheet Worksheet * @param PHPExcel_Worksheet $pSheet Worksheet
* @throws Exception * @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 // sheetViews
$objWriter->startElement('sheetViews'); $objWriter->startElement('sheetViews');
@ -218,8 +218,8 @@ class PHPExcel_Writer_Excel2007_Worksheet extends PHPExcel_Writer_Excel2007_Writ
$objWriter->writeAttribute('zoomScaleNormal', $pSheet->getSheetView()->getZoomScaleNormal()); $objWriter->writeAttribute('zoomScaleNormal', $pSheet->getSheetView()->getZoomScaleNormal());
} }
// View // View Layout Type
if ($pSheet->getSheetView()->getView() != false) { if ($pSheet->getSheetView()->getView() !== PHPExcel_Worksheet_SheetView::SHEETVIEW_NORMAL) {
$objWriter->writeAttribute('view', $pSheet->getSheetView()->getView()); $objWriter->writeAttribute('view', $pSheet->getSheetView()->getView());
} }

View File

@ -79,6 +79,7 @@ Fixed in develop branch:
- Feature: (MBaker) Initial version of HTML Reader - Feature: (MBaker) Initial version of HTML Reader
- Feature: (Progi1984) & (blazzy) Work items 9605 - Implement support for AutoFilter in PHPExcel_Writer_Excel5 - 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: (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: (alexgann) Add Currency detection to the Advanced Value Binder
- General: (MBaker) Work item 18404 - setCellValueExplicitByColumnAndRow() do not return PHPExcel_Worksheet - 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 - General: (MBaker) Work item 18324 - Reader factory doesn't read anymore XLTX and XLT files