| 1 |
<?php |
| 2 |
|
| 3 |
namespace PhpOffice\PhpSpreadsheet\Worksheet; |
| 4 |
|
| 5 |
use PhpOffice\PhpSpreadsheet\Exception as PhpSpreadsheetException; |
| 6 |
|
| 7 |
class SheetView |
| 8 |
{ |
| 9 |
// Sheet View types |
| 10 |
const SHEETVIEW_NORMAL = 'normal'; |
| 11 |
const SHEETVIEW_PAGE_LAYOUT = 'pageLayout'; |
| 12 |
const SHEETVIEW_PAGE_BREAK_PREVIEW = 'pageBreakPreview'; |
| 13 |
|
| 14 |
private static $sheetViewTypes = [ |
| 15 |
self::SHEETVIEW_NORMAL, |
| 16 |
self::SHEETVIEW_PAGE_LAYOUT, |
| 17 |
self::SHEETVIEW_PAGE_BREAK_PREVIEW, |
| 18 |
]; |
| 19 |
|
| 20 |
/** |
| 21 |
* ZoomScale. |
| 22 |
* |
| 23 |
* Valid values range from 10 to 400. |
| 24 |
* |
| 25 |
* @var int |
| 26 |
*/ |
| 27 |
private $zoomScale = 100; |
| 28 |
|
| 29 |
/** |
| 30 |
* ZoomScaleNormal. |
| 31 |
* |
| 32 |
* Valid values range from 10 to 400. |
| 33 |
* |
| 34 |
* @var int |
| 35 |
*/ |
| 36 |
private $zoomScaleNormal = 100; |
| 37 |
|
| 38 |
/** |
| 39 |
* View. |
| 40 |
* |
| 41 |
* Valid values range from 10 to 400. |
| 42 |
* |
| 43 |
* @var string |
| 44 |
*/ |
| 45 |
private $sheetviewType = self::SHEETVIEW_NORMAL; |
| 46 |
|
| 47 |
/** |
| 48 |
* Create a new SheetView. |
| 49 |
*/ |
| 50 |
public function __construct() |
| 51 |
{ |
| 52 |
} |
| 53 |
|
| 54 |
/** |
| 55 |
* Get ZoomScale. |
| 56 |
* |
| 57 |
* @return int |
| 58 |
*/ |
| 59 |
public function getZoomScale() |
| 60 |
{ |
| 61 |
return $this->zoomScale; |
| 62 |
} |
| 63 |
|
| 64 |
/** |
| 65 |
* Set ZoomScale. |
| 66 |
* Valid values range from 10 to 400. |
| 67 |
* |
| 68 |
* @param int $pValue |
| 69 |
* |
| 70 |
* @throws PhpSpreadsheetException |
| 71 |
* |
| 72 |
* @return SheetView |
| 73 |
*/ |
| 74 |
public function setZoomScale($pValue) |
| 75 |
{ |
| 76 |
// Microsoft Office Excel 2007 only allows setting a scale between 10 and 400 via the user interface, |
| 77 |
// but it is apparently still able to handle any scale >= 1 |
| 78 |
if (($pValue >= 1) || $pValue === null) { |
| 79 |
$this->zoomScale = $pValue; |
| 80 |
} else { |
| 81 |
throw new PhpSpreadsheetException('Scale must be greater than or equal to 1.'); |
| 82 |
} |
| 83 |
|
| 84 |
return $this; |
| 85 |
} |
| 86 |
|
| 87 |
/** |
| 88 |
* Get ZoomScaleNormal. |
| 89 |
* |
| 90 |
* @return int |
| 91 |
*/ |
| 92 |
public function getZoomScaleNormal() |
| 93 |
{ |
| 94 |
return $this->zoomScaleNormal; |
| 95 |
} |
| 96 |
|
| 97 |
/** |
| 98 |
* Set ZoomScale. |
| 99 |
* Valid values range from 10 to 400. |
| 100 |
* |
| 101 |
* @param int $pValue |
| 102 |
* |
| 103 |
* @throws PhpSpreadsheetException |
| 104 |
* |
| 105 |
* @return SheetView |
| 106 |
*/ |
| 107 |
public function setZoomScaleNormal($pValue) |
| 108 |
{ |
| 109 |
if (($pValue >= 1) || $pValue === null) { |
| 110 |
$this->zoomScaleNormal = $pValue; |
| 111 |
} else { |
| 112 |
throw new PhpSpreadsheetException('Scale must be greater than or equal to 1.'); |
| 113 |
} |
| 114 |
|
| 115 |
return $this; |
| 116 |
} |
| 117 |
|
| 118 |
/** |
| 119 |
* Get View. |
| 120 |
* |
| 121 |
* @return string |
| 122 |
*/ |
| 123 |
public function getView() |
| 124 |
{ |
| 125 |
return $this->sheetviewType; |
| 126 |
} |
| 127 |
|
| 128 |
/** |
| 129 |
* Set View. |
| 130 |
* |
| 131 |
* Valid values are |
| 132 |
* 'normal' self::SHEETVIEW_NORMAL |
| 133 |
* 'pageLayout' self::SHEETVIEW_PAGE_LAYOUT |
| 134 |
* 'pageBreakPreview' self::SHEETVIEW_PAGE_BREAK_PREVIEW |
| 135 |
* |
| 136 |
* @param string $pValue |
| 137 |
* |
| 138 |
* @throws PhpSpreadsheetException |
| 139 |
* |
| 140 |
* @return SheetView |
| 141 |
*/ |
| 142 |
public function setView($pValue) |
| 143 |
{ |
| 144 |
// MS Excel 2007 allows setting the view to 'normal', 'pageLayout' or 'pageBreakPreview' via the user interface |
| 145 |
if ($pValue === null) { |
| 146 |
$pValue = self::SHEETVIEW_NORMAL; |
| 147 |
} |
| 148 |
if (in_array($pValue, self::$sheetViewTypes)) { |
| 149 |
$this->sheetviewType = $pValue; |
| 150 |
} else { |
| 151 |
throw new PhpSpreadsheetException('Invalid sheetview layout type.'); |
| 152 |
} |
| 153 |
|
| 154 |
return $this; |
| 155 |
} |
| 156 |
|
| 157 |
/** |
| 158 |
* Implement PHP __clone to create a deep clone, not just a shallow copy. |
| 159 |
*/ |
| 160 |
public function __clone() |
| 161 |
{ |
| 162 |
$vars = get_object_vars($this); |
| 163 |
foreach ($vars as $key => $value) { |
| 164 |
if (is_object($value)) { |
| 165 |
$this->$key = clone $value; |
| 166 |
} else { |
| 167 |
$this->$key = $value; |
| 168 |
} |
| 169 |
} |
| 170 |
} |
| 171 |
} |
| 172 |
|