SheetView.php 3.8 KB

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