| 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 const SHEET_VIEW_TYPES = [ |
| 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 |
* ShowZeros. |
| 40 |
* |
| 41 |
* If true, "null" values from a calculation will be shown as "0". This is the default Excel behaviour and can be changed |
| 42 |
* with the advanced worksheet option "Show a zero in cells that have zero value" |
| 43 |
* |
| 44 |
* @var bool |
| 45 |
*/ |
| 46 |
private $showZeros = true; |
| 47 |
|
| 48 |
/** |
| 49 |
* View. |
| 50 |
* |
| 51 |
* Valid values range from 10 to 400. |
| 52 |
* |
| 53 |
* @var string |
| 54 |
*/ |
| 55 |
private $sheetviewType = self::SHEETVIEW_NORMAL; |
| 56 |
|
| 57 |
/** |
| 58 |
* Create a new SheetView. |
| 59 |
*/ |
| 60 |
public function __construct() |
| 61 |
{ |
| 62 |
} |
| 63 |
|
| 64 |
/** |
| 65 |
* Get ZoomScale. |
| 66 |
* |
| 67 |
* @return ?int |
| 68 |
*/ |
| 69 |
public function getZoomScale() |
| 70 |
{ |
| 71 |
return $this->zoomScale; |
| 72 |
} |
| 73 |
|
| 74 |
/** |
| 75 |
* Set ZoomScale. |
| 76 |
* Valid values range from 10 to 400. |
| 77 |
* |
| 78 |
* @param ?int $zoomScale |
| 79 |
* |
| 80 |
* @return $this |
| 81 |
*/ |
| 82 |
public function setZoomScale($zoomScale) |
| 83 |
{ |
| 84 |
// Microsoft Office Excel 2007 only allows setting a scale between 10 and 400 via the user interface, |
| 85 |
// but it is apparently still able to handle any scale >= 1 |
| 86 |
if ($zoomScale === null || $zoomScale >= 1) { |
| 87 |
$this->zoomScale = $zoomScale; |
| 88 |
} else { |
| 89 |
throw new PhpSpreadsheetException('Scale must be greater than or equal to 1.'); |
| 90 |
} |
| 91 |
|
| 92 |
return $this; |
| 93 |
} |
| 94 |
|
| 95 |
/** |
| 96 |
* Get ZoomScaleNormal. |
| 97 |
* |
| 98 |
* @return ?int |
| 99 |
*/ |
| 100 |
public function getZoomScaleNormal() |
| 101 |
{ |
| 102 |
return $this->zoomScaleNormal; |
| 103 |
} |
| 104 |
|
| 105 |
/** |
| 106 |
* Set ZoomScale. |
| 107 |
* Valid values range from 10 to 400. |
| 108 |
* |
| 109 |
* @param ?int $zoomScaleNormal |
| 110 |
* |
| 111 |
* @return $this |
| 112 |
*/ |
| 113 |
public function setZoomScaleNormal($zoomScaleNormal) |
| 114 |
{ |
| 115 |
if ($zoomScaleNormal === null || $zoomScaleNormal >= 1) { |
| 116 |
$this->zoomScaleNormal = $zoomScaleNormal; |
| 117 |
} else { |
| 118 |
throw new PhpSpreadsheetException('Scale must be greater than or equal to 1.'); |
| 119 |
} |
| 120 |
|
| 121 |
return $this; |
| 122 |
} |
| 123 |
|
| 124 |
/** |
| 125 |
* Set ShowZeroes setting. |
| 126 |
* |
| 127 |
* @param bool $showZeros |
| 128 |
*/ |
| 129 |
public function setShowZeros($showZeros): void |
| 130 |
{ |
| 131 |
$this->showZeros = $showZeros; |
| 132 |
} |
| 133 |
|
| 134 |
/** |
| 135 |
* @return bool |
| 136 |
*/ |
| 137 |
public function getShowZeros() |
| 138 |
{ |
| 139 |
return $this->showZeros; |
| 140 |
} |
| 141 |
|
| 142 |
/** |
| 143 |
* Get View. |
| 144 |
* |
| 145 |
* @return string |
| 146 |
*/ |
| 147 |
public function getView() |
| 148 |
{ |
| 149 |
return $this->sheetviewType; |
| 150 |
} |
| 151 |
|
| 152 |
/** |
| 153 |
* Set View. |
| 154 |
* |
| 155 |
* Valid values are |
| 156 |
* 'normal' self::SHEETVIEW_NORMAL |
| 157 |
* 'pageLayout' self::SHEETVIEW_PAGE_LAYOUT |
| 158 |
* 'pageBreakPreview' self::SHEETVIEW_PAGE_BREAK_PREVIEW |
| 159 |
* |
| 160 |
* @param ?string $sheetViewType |
| 161 |
* |
| 162 |
* @return $this |
| 163 |
*/ |
| 164 |
public function setView($sheetViewType) |
| 165 |
{ |
| 166 |
// MS Excel 2007 allows setting the view to 'normal', 'pageLayout' or 'pageBreakPreview' via the user interface |
| 167 |
if ($sheetViewType === null) { |
| 168 |
$sheetViewType = self::SHEETVIEW_NORMAL; |
| 169 |
} |
| 170 |
if (in_array($sheetViewType, self::SHEET_VIEW_TYPES)) { |
| 171 |
$this->sheetviewType = $sheetViewType; |
| 172 |
} else { |
| 173 |
throw new PhpSpreadsheetException('Invalid sheetview layout type.'); |
| 174 |
} |
| 175 |
|
| 176 |
return $this; |
| 177 |
} |
| 178 |
} |
| 179 |
|