PageRenderTime 44ms CodeModel.GetById 22ms RepoModel.GetById 1ms app.codeStats 0ms

/branches/v1.5.0/Classes/PHPExcel/Worksheet/PageSetup.php

#
PHP | 350 lines | 134 code | 20 blank | 196 comment | 9 complexity | 62b72b013982650eacbeef215f25dc9a MD5 | raw file
Possible License(s): AGPL-1.0, LGPL-2.0, LGPL-2.1, GPL-3.0, LGPL-3.0
  1. <?php
  2. /**
  3. * PHPExcel
  4. *
  5. * Copyright (c) 2006 - 2007 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 - 2007 PHPExcel (http://www.codeplex.com/PHPExcel)
  24. * @license http://www.gnu.org/licenses/lgpl.txt LGPL
  25. * @version ##VERSION##, ##DATE##
  26. */
  27. /**
  28. * PHPExcel_Worksheet_PageSetup
  29. *
  30. * <code>
  31. * Paper size taken from Office Open XML Part 4 - Markup Language Reference, page 1988:
  32. *
  33. * 1 = Letter paper (8.5 in. by 11 in.)
  34. * 2 = Letter small paper (8.5 in. by 11 in.)
  35. * 3 = Tabloid paper (11 in. by 17 in.)
  36. * 4 = Ledger paper (17 in. by 11 in.)
  37. * 5 = Legal paper (8.5 in. by 14 in.)
  38. * 6 = Statement paper (5.5 in. by 8.5 in.)
  39. * 7 = Executive paper (7.25 in. by 10.5 in.)
  40. * 8 = A3 paper (297 mm by 420 mm)
  41. * 9 = A4 paper (210 mm by 297 mm)
  42. * 10 = A4 small paper (210 mm by 297 mm)
  43. * 11 = A5 paper (148 mm by 210 mm)
  44. * 12 = B4 paper (250 mm by 353 mm)
  45. * 13 = B5 paper (176 mm by 250 mm)
  46. * 14 = Folio paper (8.5 in. by 13 in.)
  47. * 15 = Quarto paper (215 mm by 275 mm)
  48. * 16 = Standard paper (10 in. by 14 in.)
  49. * 17 = Standard paper (11 in. by 17 in.)
  50. * 18 = Note paper (8.5 in. by 11 in.)
  51. * 19 = #9 envelope (3.875 in. by 8.875 in.)
  52. * 20 = #10 envelope (4.125 in. by 9.5 in.)
  53. * 21 = #11 envelope (4.5 in. by 10.375 in.)
  54. * 22 = #12 envelope (4.75 in. by 11 in.)
  55. * 23 = #14 envelope (5 in. by 11.5 in.)
  56. * 24 = C paper (17 in. by 22 in.)
  57. * 25 = D paper (22 in. by 34 in.)
  58. * 26 = E paper (34 in. by 44 in.)
  59. * 27 = DL envelope (110 mm by 220 mm)
  60. * 28 = C5 envelope (162 mm by 229 mm)
  61. * 29 = C3 envelope (324 mm by 458 mm)
  62. * 30 = C4 envelope (229 mm by 324 mm)
  63. * 31 = C6 envelope (114 mm by 162 mm)
  64. * 32 = C65 envelope (114 mm by 229 mm)
  65. * 33 = B4 envelope (250 mm by 353 mm)
  66. * 34 = B5 envelope (176 mm by 250 mm)
  67. * 35 = B6 envelope (176 mm by 125 mm)
  68. * 36 = Italy envelope (110 mm by 230 mm)
  69. * 37 = Monarch envelope (3.875 in. by 7.5 in.).
  70. * 38 = 6 3/4 envelope (3.625 in. by 6.5 in.)
  71. * 39 = US standard fanfold (14.875 in. by 11 in.)
  72. * 40 = German standard fanfold (8.5 in. by 12 in.)
  73. * 41 = German legal fanfold (8.5 in. by 13 in.)
  74. * 42 = ISO B4 (250 mm by 353 mm)
  75. * 43 = Japanese double postcard (200 mm by 148 mm)
  76. * 44 = Standard paper (9 in. by 11 in.)
  77. * 45 = Standard paper (10 in. by 11 in.)
  78. * 46 = Standard paper (15 in. by 11 in.)
  79. * 47 = Invite envelope (220 mm by 220 mm)
  80. * 50 = Letter extra paper (9.275 in. by 12 in.)
  81. * 51 = Legal extra paper (9.275 in. by 15 in.)
  82. * 52 = Tabloid extra paper (11.69 in. by 18 in.)
  83. * 53 = A4 extra paper (236 mm by 322 mm)
  84. * 54 = Letter transverse paper (8.275 in. by 11 in.)
  85. * 55 = A4 transverse paper (210 mm by 297 mm)
  86. * 56 = Letter extra transverse paper (9.275 in. by 12 in.)
  87. * 57 = SuperA/SuperA/A4 paper (227 mm by 356 mm)
  88. * 58 = SuperB/SuperB/A3 paper (305 mm by 487 mm)
  89. * 59 = Letter plus paper (8.5 in. by 12.69 in.)
  90. * 60 = A4 plus paper (210 mm by 330 mm)
  91. * 61 = A5 transverse paper (148 mm by 210 mm)
  92. * 62 = JIS B5 transverse paper (182 mm by 257 mm)
  93. * 63 = A3 extra paper (322 mm by 445 mm)
  94. * 64 = A5 extra paper (174 mm by 235 mm)
  95. * 65 = ISO B5 extra paper (201 mm by 276 mm)
  96. * 66 = A2 paper (420 mm by 594 mm)
  97. * 67 = A3 transverse paper (297 mm by 420 mm)
  98. * 68 = A3 extra transverse paper (322 mm by 445 mm)
  99. * </code>
  100. *
  101. * @category PHPExcel
  102. * @package PHPExcel_Worksheet
  103. * @copyright Copyright (c) 2006 - 2007 PHPExcel (http://www.codeplex.com/PHPExcel)
  104. */
  105. class PHPExcel_Worksheet_PageSetup
  106. {
  107. /* Paper size */
  108. const PAPERSIZE_LETTER = 1;
  109. const PAPERSIZE_LETTER_SMALL = 2;
  110. const PAPERSIZE_TABLOID = 3;
  111. const PAPERSIZE_LEDGER = 4;
  112. const PAPERSIZE_LEGAL = 5;
  113. const PAPERSIZE_STATEMENT = 6;
  114. const PAPERSIZE_EXECUTIVE = 7;
  115. const PAPERSIZE_A3 = 8;
  116. const PAPERSIZE_A4 = 9;
  117. const PAPERSIZE_A4_SMALL = 10;
  118. const PAPERSIZE_A5 = 11;
  119. const PAPERSIZE_B4 = 12;
  120. const PAPERSIZE_B5 = 13;
  121. const PAPERSIZE_FOLIO = 14;
  122. const PAPERSIZE_QUARTO = 15;
  123. const PAPERSIZE_STANDARD_1 = 16;
  124. const PAPERSIZE_STANDARD_2 = 17;
  125. const PAPERSIZE_NOTE = 18;
  126. const PAPERSIZE_NO9_ENVELOPE = 19;
  127. const PAPERSIZE_NO10_ENVELOPE = 20;
  128. const PAPERSIZE_NO11_ENVELOPE = 21;
  129. const PAPERSIZE_NO12_ENVELOPE = 22;
  130. const PAPERSIZE_NO14_ENVELOPE = 23;
  131. const PAPERSIZE_C = 24;
  132. const PAPERSIZE_D = 25;
  133. const PAPERSIZE_E = 26;
  134. const PAPERSIZE_DL_ENVELOPE = 27;
  135. const PAPERSIZE_C5_ENVELOPE = 28;
  136. const PAPERSIZE_C3_ENVELOPE = 29;
  137. const PAPERSIZE_C4_ENVELOPE = 30;
  138. const PAPERSIZE_C6_ENVELOPE = 31;
  139. const PAPERSIZE_C65_ENVELOPE = 32;
  140. const PAPERSIZE_B4_ENVELOPE = 33;
  141. const PAPERSIZE_B5_ENVELOPE = 34;
  142. const PAPERSIZE_B6_ENVELOPE = 35;
  143. const PAPERSIZE_ITALY_ENVELOPE = 36;
  144. const PAPERSIZE_MONARCH_ENVELOPE = 37;
  145. const PAPERSIZE_6_3_4_ENVELOPE = 38;
  146. const PAPERSIZE_US_STANDARD_FANFOLD = 39;
  147. const PAPERSIZE_GERMAN_STANDARD_FANFOLD = 40;
  148. const PAPERSIZE_GERMAN_LEGAL_FANFOLD = 41;
  149. const PAPERSIZE_ISO_B4 = 42;
  150. const PAPERSIZE_JAPANESE_DOUBLE_POSTCARD = 43;
  151. const PAPERSIZE_STANDARD_PAPER_1 = 44;
  152. const PAPERSIZE_STANDARD_PAPER_2 = 45;
  153. const PAPERSIZE_STANDARD_PAPER_3 = 46;
  154. const PAPERSIZE_INVITE_ENVELOPE = 47;
  155. const PAPERSIZE_LETTER_EXTRA_PAPER = 48;
  156. const PAPERSIZE_LEGAL_EXTRA_PAPER = 49;
  157. const PAPERSIZE_TABLOID_EXTRA_PAPER = 50;
  158. const PAPERSIZE_A4_EXTRA_PAPER = 51;
  159. const PAPERSIZE_LETTER_TRANSVERSE_PAPER = 52;
  160. const PAPERSIZE_A4_TRANSVERSE_PAPER = 53;
  161. const PAPERSIZE_LETTER_EXTRA_TRANSVERSE_PAPER = 54;
  162. const PAPERSIZE_SUPERA_SUPERA_A4_PAPER = 55;
  163. const PAPERSIZE_SUPERB_SUPERB_A3_PAPER = 56;
  164. const PAPERSIZE_LETTER_PLUS_PAPER = 57;
  165. const PAPERSIZE_A4_PLUS_PAPER = 58;
  166. const PAPERSIZE_A5_TRANSVERSE_PAPER = 59;
  167. const PAPERSIZE_JIS_B5_TRANSVERSE_PAPER = 60;
  168. const PAPERSIZE_A3_EXTRA_PAPER = 61;
  169. const PAPERSIZE_A5_EXTRA_PAPER = 62;
  170. const PAPERSIZE_ISO_B5_EXTRA_PAPER = 63;
  171. const PAPERSIZE_A2_PAPER = 64;
  172. const PAPERSIZE_A3_TRANSVERSE_PAPER = 65;
  173. const PAPERSIZE_A3_EXTRA_TRANSVERSE_PAPER = 66;
  174. /* Page orientation */
  175. const ORIENTATION_DEFAULT = 'default';
  176. const ORIENTATION_LANDSCAPE = 'landscape';
  177. const ORIENTATION_PORTRAIT = 'portrait';
  178. /**
  179. * Paper size
  180. *
  181. * @var int
  182. */
  183. private $_paperSize;
  184. /**
  185. * Orientation
  186. *
  187. * @var string
  188. */
  189. private $_orientation;
  190. /**
  191. * Scale (Print Scale)
  192. *
  193. * Print scaling. Valid values range from 10 to 400
  194. * This setting is overridden when fitToWidth and/or fitToHeight are in use
  195. *
  196. * @var int?
  197. */
  198. private $_scale;
  199. /**
  200. * Fit To Height
  201. * Number of vertical pages to fit on
  202. *
  203. * @var int?
  204. */
  205. private $_fitToHeight;
  206. /**
  207. * Fit To Width
  208. * Number of horizontal pages to fit on
  209. *
  210. * @var int?
  211. */
  212. private $_fitToWidth;
  213. /**
  214. * Create a new PHPExcel_Worksheet_PageSetup
  215. */
  216. public function __construct()
  217. {
  218. // Initialise values
  219. $this->_paperSize = PHPExcel_Worksheet_PageSetup::PAPERSIZE_LETTER;
  220. $this->_orientation = PHPExcel_Worksheet_PageSetup::ORIENTATION_DEFAULT;
  221. $this->_scale = null;
  222. $this->_fitToHeight = null;
  223. $this->_fitToWidth = null;
  224. }
  225. /**
  226. * Get Paper Size
  227. *
  228. * @return int
  229. */
  230. public function getPaperSize() {
  231. return $this->_paperSize;
  232. }
  233. /**
  234. * Set Paper Size
  235. *
  236. * @param int $pValue
  237. */
  238. public function setPaperSize($pValue = PHPExcel_Worksheet_PageSetup::PAPERSIZE_LETTER) {
  239. $this->_paperSize = $pValue;
  240. }
  241. /**
  242. * Get Orientation
  243. *
  244. * @return string
  245. */
  246. public function getOrientation() {
  247. return $this->_orientation;
  248. }
  249. /**
  250. * Set Orientation
  251. *
  252. * @param string $pValue
  253. */
  254. public function setOrientation($pValue = PHPExcel_Worksheet_PageSetup::ORIENTATION_DEFAULT) {
  255. $this->_orientation = $pValue;
  256. }
  257. /**
  258. * Get Scale
  259. *
  260. * @return int?
  261. */
  262. public function getScale() {
  263. return $this->_scale;
  264. }
  265. /**
  266. * Set Scale
  267. *
  268. * Print scaling. Valid values range from 10 to 400
  269. * This setting is overridden when fitToWidth and/or fitToHeight are in use
  270. *
  271. * @param int? $pValue
  272. * @throws Exception
  273. */
  274. public function setScale($pValue = 100) {
  275. if ($pValue >= 10 && $pValue <= 400) {
  276. $this->_scale = $pValue;
  277. } else {
  278. throw new Exception("Valid scale is between 10 and 400.");
  279. }
  280. }
  281. /**
  282. * Get Fit To Height
  283. *
  284. * @return int?
  285. */
  286. public function getFitToHeight() {
  287. return $this->_fitToHeight;
  288. }
  289. /**
  290. * Set Fit To Height
  291. *
  292. * @param int? $pValue
  293. */
  294. public function setFitToHeight($pValue = 1) {
  295. if ($pValue != '') {
  296. $this->_fitToHeight = $pValue;
  297. }
  298. }
  299. /**
  300. * Get Fit To Width
  301. *
  302. * @return int?
  303. */
  304. public function getFitToWidth() {
  305. return $this->_fitToWidth;
  306. }
  307. /**
  308. * Set Fit To Width
  309. *
  310. * @param int? $pValue
  311. */
  312. public function setFitToWidth($pValue = 1) {
  313. if ($pValue != '') {
  314. $this->_fitToWidth = $pValue;
  315. }
  316. }
  317. /**
  318. * Implement PHP __clone to create a deep clone, not just a shallow copy.
  319. */
  320. public function __clone() {
  321. $vars = get_object_vars($this);
  322. foreach ($vars as $key => $value) {
  323. if (is_object($value)) {
  324. $this->$key = clone $value;
  325. } else {
  326. $this->$key = $value;
  327. }
  328. }
  329. }
  330. }