SheetView.Class.php 3.8 KB

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