SheetView.php 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. <?php
  2. /**
  3. * PHPExcel_Worksheet_SheetView
  4. *
  5. * Copyright (c) 2006 - 2015 PHPExcel
  6. *
  7. * This library is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU Lesser General Public
  9. * License as published by the Free Software Foundation; either
  10. * version 2.1 of the License, or (at your option) any later version.
  11. *
  12. * This library is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. * Lesser General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU Lesser General Public
  18. * License along with this library; if not, write to the Free Software
  19. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  20. *
  21. * @category PHPExcel
  22. * @package PHPExcel_Worksheet
  23. * @copyright Copyright (c) 2006 - 2015 PHPExcel (http://www.codeplex.com/PHPExcel)
  24. * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
  25. * @version ##VERSION##, ##DATE##
  26. */
  27. class PHPExcel_Worksheet_SheetView
  28. {
  29. /* Sheet View types */
  30. const SHEETVIEW_NORMAL = 'normal';
  31. const SHEETVIEW_PAGE_LAYOUT = 'pageLayout';
  32. const SHEETVIEW_PAGE_BREAK_PREVIEW = 'pageBreakPreview';
  33. private static $sheetViewTypes = array(
  34. self::SHEETVIEW_NORMAL,
  35. self::SHEETVIEW_PAGE_LAYOUT,
  36. self::SHEETVIEW_PAGE_BREAK_PREVIEW,
  37. );
  38. /**
  39. * ZoomScale
  40. *
  41. * Valid values range from 10 to 400.
  42. *
  43. * @var int
  44. */
  45. private $zoomScale = 100;
  46. /**
  47. * ZoomScaleNormal
  48. *
  49. * Valid values range from 10 to 400.
  50. *
  51. * @var int
  52. */
  53. private $zoomScaleNormal = 100;
  54. /**
  55. * View
  56. *
  57. * Valid values range from 10 to 400.
  58. *
  59. * @var string
  60. */
  61. private $sheetviewType = self::SHEETVIEW_NORMAL;
  62. /**
  63. * Create a new PHPExcel_Worksheet_SheetView
  64. */
  65. public function __construct()
  66. {
  67. }
  68. /**
  69. * Get ZoomScale
  70. *
  71. * @return int
  72. */
  73. public function getZoomScale()
  74. {
  75. return $this->zoomScale;
  76. }
  77. /**
  78. * Set ZoomScale
  79. *
  80. * Valid values range from 10 to 400.
  81. *
  82. * @param int $pValue
  83. * @throws PHPExcel_Exception
  84. * @return PHPExcel_Worksheet_SheetView
  85. */
  86. public function setZoomScale($pValue = 100)
  87. {
  88. // Microsoft Office Excel 2007 only allows setting a scale between 10 and 400 via the user interface,
  89. // but it is apparently still able to handle any scale >= 1
  90. if (($pValue >= 1) || is_null($pValue)) {
  91. $this->zoomScale = $pValue;
  92. } else {
  93. throw new PHPExcel_Exception("Scale must be greater than or equal to 1.");
  94. }
  95. return $this;
  96. }
  97. /**
  98. * Get ZoomScaleNormal
  99. *
  100. * @return int
  101. */
  102. public function getZoomScaleNormal()
  103. {
  104. return $this->zoomScaleNormal;
  105. }
  106. /**
  107. * Set ZoomScale
  108. *
  109. * Valid values range from 10 to 400.
  110. *
  111. * @param int $pValue
  112. * @throws PHPExcel_Exception
  113. * @return PHPExcel_Worksheet_SheetView
  114. */
  115. public function setZoomScaleNormal($pValue = 100)
  116. {
  117. if (($pValue >= 1) || is_null($pValue)) {
  118. $this->zoomScaleNormal = $pValue;
  119. } else {
  120. throw new PHPExcel_Exception("Scale must be greater than or equal to 1.");
  121. }
  122. return $this;
  123. }
  124. /**
  125. * Get View
  126. *
  127. * @return string
  128. */
  129. public function getView()
  130. {
  131. return $this->sheetviewType;
  132. }
  133. /**
  134. * Set View
  135. *
  136. * Valid values are
  137. * 'normal' self::SHEETVIEW_NORMAL
  138. * 'pageLayout' self::SHEETVIEW_PAGE_LAYOUT
  139. * 'pageBreakPreview' self::SHEETVIEW_PAGE_BREAK_PREVIEW
  140. *
  141. * @param string $pValue
  142. * @throws PHPExcel_Exception
  143. * @return PHPExcel_Worksheet_SheetView
  144. */
  145. public function setView($pValue = null)
  146. {
  147. // MS Excel 2007 allows setting the view to 'normal', 'pageLayout' or 'pageBreakPreview' via the user interface
  148. if ($pValue === null) {
  149. $pValue = self::SHEETVIEW_NORMAL;
  150. }
  151. if (in_array($pValue, self::$sheetViewTypes)) {
  152. $this->sheetviewType = $pValue;
  153. } else {
  154. throw new PHPExcel_Exception("Invalid sheetview layout type.");
  155. }
  156. return $this;
  157. }
  158. /**
  159. * Implement PHP __clone to create a deep clone, not just a shallow copy.
  160. */
  161. public function __clone()
  162. {
  163. $vars = get_object_vars($this);
  164. foreach ($vars as $key => $value) {
  165. if (is_object($value)) {
  166. $this->$key = clone $value;
  167. } else {
  168. $this->$key = $value;
  169. }
  170. }
  171. }
  172. }