0
0

PageSetup.php 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839
  1. <?php
  2. /**
  3. * PHPExcel
  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. /**
  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 - 2015 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. /* Print Range Set Method */
  179. const SETPRINTRANGE_OVERWRITE = 'O';
  180. const SETPRINTRANGE_INSERT = 'I';
  181. /**
  182. * Paper size
  183. *
  184. * @var int
  185. */
  186. private $paperSize = PHPExcel_Worksheet_PageSetup::PAPERSIZE_LETTER;
  187. /**
  188. * Orientation
  189. *
  190. * @var string
  191. */
  192. private $orientation = PHPExcel_Worksheet_PageSetup::ORIENTATION_DEFAULT;
  193. /**
  194. * Scale (Print Scale)
  195. *
  196. * Print scaling. Valid values range from 10 to 400
  197. * This setting is overridden when fitToWidth and/or fitToHeight are in use
  198. *
  199. * @var int?
  200. */
  201. private $scale = 100;
  202. /**
  203. * Fit To Page
  204. * Whether scale or fitToWith / fitToHeight applies
  205. *
  206. * @var boolean
  207. */
  208. private $fitToPage = false;
  209. /**
  210. * Fit To Height
  211. * Number of vertical pages to fit on
  212. *
  213. * @var int?
  214. */
  215. private $fitToHeight = 1;
  216. /**
  217. * Fit To Width
  218. * Number of horizontal pages to fit on
  219. *
  220. * @var int?
  221. */
  222. private $fitToWidth = 1;
  223. /**
  224. * Columns to repeat at left
  225. *
  226. * @var array Containing start column and end column, empty array if option unset
  227. */
  228. private $columnsToRepeatAtLeft = array('', '');
  229. /**
  230. * Rows to repeat at top
  231. *
  232. * @var array Containing start row number and end row number, empty array if option unset
  233. */
  234. private $rowsToRepeatAtTop = array(0, 0);
  235. /**
  236. * Center page horizontally
  237. *
  238. * @var boolean
  239. */
  240. private $horizontalCentered = false;
  241. /**
  242. * Center page vertically
  243. *
  244. * @var boolean
  245. */
  246. private $verticalCentered = false;
  247. /**
  248. * Print area
  249. *
  250. * @var string
  251. */
  252. private $printArea = null;
  253. /**
  254. * First page number
  255. *
  256. * @var int
  257. */
  258. private $firstPageNumber = null;
  259. /**
  260. * Create a new PHPExcel_Worksheet_PageSetup
  261. */
  262. public function __construct()
  263. {
  264. }
  265. /**
  266. * Get Paper Size
  267. *
  268. * @return int
  269. */
  270. public function getPaperSize()
  271. {
  272. return $this->paperSize;
  273. }
  274. /**
  275. * Set Paper Size
  276. *
  277. * @param int $pValue
  278. * @return PHPExcel_Worksheet_PageSetup
  279. */
  280. public function setPaperSize($pValue = PHPExcel_Worksheet_PageSetup::PAPERSIZE_LETTER)
  281. {
  282. $this->paperSize = $pValue;
  283. return $this;
  284. }
  285. /**
  286. * Get Orientation
  287. *
  288. * @return string
  289. */
  290. public function getOrientation()
  291. {
  292. return $this->orientation;
  293. }
  294. /**
  295. * Set Orientation
  296. *
  297. * @param string $pValue
  298. * @return PHPExcel_Worksheet_PageSetup
  299. */
  300. public function setOrientation($pValue = PHPExcel_Worksheet_PageSetup::ORIENTATION_DEFAULT)
  301. {
  302. $this->orientation = $pValue;
  303. return $this;
  304. }
  305. /**
  306. * Get Scale
  307. *
  308. * @return int?
  309. */
  310. public function getScale()
  311. {
  312. return $this->scale;
  313. }
  314. /**
  315. * Set Scale
  316. *
  317. * Print scaling. Valid values range from 10 to 400
  318. * This setting is overridden when fitToWidth and/or fitToHeight are in use
  319. *
  320. * @param int? $pValue
  321. * @param boolean $pUpdate Update fitToPage so scaling applies rather than fitToHeight / fitToWidth
  322. * @return PHPExcel_Worksheet_PageSetup
  323. * @throws PHPExcel_Exception
  324. */
  325. public function setScale($pValue = 100, $pUpdate = true)
  326. {
  327. // Microsoft Office Excel 2007 only allows setting a scale between 10 and 400 via the user interface,
  328. // but it is apparently still able to handle any scale >= 0, where 0 results in 100
  329. if (($pValue >= 0) || is_null($pValue)) {
  330. $this->scale = $pValue;
  331. if ($pUpdate) {
  332. $this->fitToPage = false;
  333. }
  334. } else {
  335. throw new PHPExcel_Exception("Scale must not be negative");
  336. }
  337. return $this;
  338. }
  339. /**
  340. * Get Fit To Page
  341. *
  342. * @return boolean
  343. */
  344. public function getFitToPage()
  345. {
  346. return $this->fitToPage;
  347. }
  348. /**
  349. * Set Fit To Page
  350. *
  351. * @param boolean $pValue
  352. * @return PHPExcel_Worksheet_PageSetup
  353. */
  354. public function setFitToPage($pValue = true)
  355. {
  356. $this->fitToPage = $pValue;
  357. return $this;
  358. }
  359. /**
  360. * Get Fit To Height
  361. *
  362. * @return int?
  363. */
  364. public function getFitToHeight()
  365. {
  366. return $this->fitToHeight;
  367. }
  368. /**
  369. * Set Fit To Height
  370. *
  371. * @param int? $pValue
  372. * @param boolean $pUpdate Update fitToPage so it applies rather than scaling
  373. * @return PHPExcel_Worksheet_PageSetup
  374. */
  375. public function setFitToHeight($pValue = 1, $pUpdate = true)
  376. {
  377. $this->fitToHeight = $pValue;
  378. if ($pUpdate) {
  379. $this->fitToPage = true;
  380. }
  381. return $this;
  382. }
  383. /**
  384. * Get Fit To Width
  385. *
  386. * @return int?
  387. */
  388. public function getFitToWidth()
  389. {
  390. return $this->fitToWidth;
  391. }
  392. /**
  393. * Set Fit To Width
  394. *
  395. * @param int? $pValue
  396. * @param boolean $pUpdate Update fitToPage so it applies rather than scaling
  397. * @return PHPExcel_Worksheet_PageSetup
  398. */
  399. public function setFitToWidth($pValue = 1, $pUpdate = true)
  400. {
  401. $this->fitToWidth = $pValue;
  402. if ($pUpdate) {
  403. $this->fitToPage = true;
  404. }
  405. return $this;
  406. }
  407. /**
  408. * Is Columns to repeat at left set?
  409. *
  410. * @return boolean
  411. */
  412. public function isColumnsToRepeatAtLeftSet()
  413. {
  414. if (is_array($this->columnsToRepeatAtLeft)) {
  415. if ($this->columnsToRepeatAtLeft[0] != '' && $this->columnsToRepeatAtLeft[1] != '') {
  416. return true;
  417. }
  418. }
  419. return false;
  420. }
  421. /**
  422. * Get Columns to repeat at left
  423. *
  424. * @return array Containing start column and end column, empty array if option unset
  425. */
  426. public function getColumnsToRepeatAtLeft()
  427. {
  428. return $this->columnsToRepeatAtLeft;
  429. }
  430. /**
  431. * Set Columns to repeat at left
  432. *
  433. * @param array $pValue Containing start column and end column, empty array if option unset
  434. * @return PHPExcel_Worksheet_PageSetup
  435. */
  436. public function setColumnsToRepeatAtLeft($pValue = null)
  437. {
  438. if (is_array($pValue)) {
  439. $this->columnsToRepeatAtLeft = $pValue;
  440. }
  441. return $this;
  442. }
  443. /**
  444. * Set Columns to repeat at left by start and end
  445. *
  446. * @param string $pStart
  447. * @param string $pEnd
  448. * @return PHPExcel_Worksheet_PageSetup
  449. */
  450. public function setColumnsToRepeatAtLeftByStartAndEnd($pStart = 'A', $pEnd = 'A')
  451. {
  452. $this->columnsToRepeatAtLeft = array($pStart, $pEnd);
  453. return $this;
  454. }
  455. /**
  456. * Is Rows to repeat at top set?
  457. *
  458. * @return boolean
  459. */
  460. public function isRowsToRepeatAtTopSet()
  461. {
  462. if (is_array($this->rowsToRepeatAtTop)) {
  463. if ($this->rowsToRepeatAtTop[0] != 0 && $this->rowsToRepeatAtTop[1] != 0) {
  464. return true;
  465. }
  466. }
  467. return false;
  468. }
  469. /**
  470. * Get Rows to repeat at top
  471. *
  472. * @return array Containing start column and end column, empty array if option unset
  473. */
  474. public function getRowsToRepeatAtTop()
  475. {
  476. return $this->rowsToRepeatAtTop;
  477. }
  478. /**
  479. * Set Rows to repeat at top
  480. *
  481. * @param array $pValue Containing start column and end column, empty array if option unset
  482. * @return PHPExcel_Worksheet_PageSetup
  483. */
  484. public function setRowsToRepeatAtTop($pValue = null)
  485. {
  486. if (is_array($pValue)) {
  487. $this->rowsToRepeatAtTop = $pValue;
  488. }
  489. return $this;
  490. }
  491. /**
  492. * Set Rows to repeat at top by start and end
  493. *
  494. * @param int $pStart
  495. * @param int $pEnd
  496. * @return PHPExcel_Worksheet_PageSetup
  497. */
  498. public function setRowsToRepeatAtTopByStartAndEnd($pStart = 1, $pEnd = 1)
  499. {
  500. $this->rowsToRepeatAtTop = array($pStart, $pEnd);
  501. return $this;
  502. }
  503. /**
  504. * Get center page horizontally
  505. *
  506. * @return bool
  507. */
  508. public function getHorizontalCentered()
  509. {
  510. return $this->horizontalCentered;
  511. }
  512. /**
  513. * Set center page horizontally
  514. *
  515. * @param bool $value
  516. * @return PHPExcel_Worksheet_PageSetup
  517. */
  518. public function setHorizontalCentered($value = false)
  519. {
  520. $this->horizontalCentered = $value;
  521. return $this;
  522. }
  523. /**
  524. * Get center page vertically
  525. *
  526. * @return bool
  527. */
  528. public function getVerticalCentered()
  529. {
  530. return $this->verticalCentered;
  531. }
  532. /**
  533. * Set center page vertically
  534. *
  535. * @param bool $value
  536. * @return PHPExcel_Worksheet_PageSetup
  537. */
  538. public function setVerticalCentered($value = false)
  539. {
  540. $this->verticalCentered = $value;
  541. return $this;
  542. }
  543. /**
  544. * Get print area
  545. *
  546. * @param int $index Identifier for a specific print area range if several ranges have been set
  547. * Default behaviour, or a index value of 0, will return all ranges as a comma-separated string
  548. * Otherwise, the specific range identified by the value of $index will be returned
  549. * Print areas are numbered from 1
  550. * @throws PHPExcel_Exception
  551. * @return string
  552. */
  553. public function getPrintArea($index = 0)
  554. {
  555. if ($index == 0) {
  556. return $this->printArea;
  557. }
  558. $printAreas = explode(',', $this->printArea);
  559. if (isset($printAreas[$index-1])) {
  560. return $printAreas[$index-1];
  561. }
  562. throw new PHPExcel_Exception("Requested Print Area does not exist");
  563. }
  564. /**
  565. * Is print area set?
  566. *
  567. * @param int $index Identifier for a specific print area range if several ranges have been set
  568. * Default behaviour, or an index value of 0, will identify whether any print range is set
  569. * Otherwise, existence of the range identified by the value of $index will be returned
  570. * Print areas are numbered from 1
  571. * @return boolean
  572. */
  573. public function isPrintAreaSet($index = 0)
  574. {
  575. if ($index == 0) {
  576. return !is_null($this->printArea);
  577. }
  578. $printAreas = explode(',', $this->printArea);
  579. return isset($printAreas[$index-1]);
  580. }
  581. /**
  582. * Clear a print area
  583. *
  584. * @param int $index Identifier for a specific print area range if several ranges have been set
  585. * Default behaviour, or an index value of 0, will clear all print ranges that are set
  586. * Otherwise, the range identified by the value of $index will be removed from the series
  587. * Print areas are numbered from 1
  588. * @return PHPExcel_Worksheet_PageSetup
  589. */
  590. public function clearPrintArea($index = 0)
  591. {
  592. if ($index == 0) {
  593. $this->printArea = null;
  594. } else {
  595. $printAreas = explode(',', $this->printArea);
  596. if (isset($printAreas[$index-1])) {
  597. unset($printAreas[$index-1]);
  598. $this->printArea = implode(',', $printAreas);
  599. }
  600. }
  601. return $this;
  602. }
  603. /**
  604. * Set print area. e.g. 'A1:D10' or 'A1:D10,G5:M20'
  605. *
  606. * @param string $value
  607. * @param int $index Identifier for a specific print area range allowing several ranges to be set
  608. * When the method is "O"verwrite, then a positive integer index will overwrite that indexed
  609. * entry in the print areas list; a negative index value will identify which entry to
  610. * overwrite working bacward through the print area to the list, with the last entry as -1.
  611. * Specifying an index value of 0, will overwrite <b>all</b> existing print ranges.
  612. * When the method is "I"nsert, then a positive index will insert after that indexed entry in
  613. * the print areas list, while a negative index will insert before the indexed entry.
  614. * Specifying an index value of 0, will always append the new print range at the end of the
  615. * list.
  616. * Print areas are numbered from 1
  617. * @param string $method Determines the method used when setting multiple print areas
  618. * Default behaviour, or the "O" method, overwrites existing print area
  619. * The "I" method, inserts the new print area before any specified index, or at the end of the list
  620. * @return PHPExcel_Worksheet_PageSetup
  621. * @throws PHPExcel_Exception
  622. */
  623. public function setPrintArea($value, $index = 0, $method = self::SETPRINTRANGE_OVERWRITE)
  624. {
  625. if (strpos($value, '!') !== false) {
  626. throw new PHPExcel_Exception('Cell coordinate must not specify a worksheet.');
  627. } elseif (strpos($value, ':') === false) {
  628. throw new PHPExcel_Exception('Cell coordinate must be a range of cells.');
  629. } elseif (strpos($value, '$') !== false) {
  630. throw new PHPExcel_Exception('Cell coordinate must not be absolute.');
  631. }
  632. $value = strtoupper($value);
  633. if ($method == self::SETPRINTRANGE_OVERWRITE) {
  634. if ($index == 0) {
  635. $this->printArea = $value;
  636. } else {
  637. $printAreas = explode(',', $this->printArea);
  638. if ($index < 0) {
  639. $index = count($printAreas) - abs($index) + 1;
  640. }
  641. if (($index <= 0) || ($index > count($printAreas))) {
  642. throw new PHPExcel_Exception('Invalid index for setting print range.');
  643. }
  644. $printAreas[$index-1] = $value;
  645. $this->printArea = implode(',', $printAreas);
  646. }
  647. } elseif ($method == self::SETPRINTRANGE_INSERT) {
  648. if ($index == 0) {
  649. $this->printArea .= ($this->printArea == '') ? $value : ','.$value;
  650. } else {
  651. $printAreas = explode(',', $this->printArea);
  652. if ($index < 0) {
  653. $index = abs($index) - 1;
  654. }
  655. if ($index > count($printAreas)) {
  656. throw new PHPExcel_Exception('Invalid index for setting print range.');
  657. }
  658. $printAreas = array_merge(array_slice($printAreas, 0, $index), array($value), array_slice($printAreas, $index));
  659. $this->printArea = implode(',', $printAreas);
  660. }
  661. } else {
  662. throw new PHPExcel_Exception('Invalid method for setting print range.');
  663. }
  664. return $this;
  665. }
  666. /**
  667. * Add a new print area (e.g. 'A1:D10' or 'A1:D10,G5:M20') to the list of print areas
  668. *
  669. * @param string $value
  670. * @param int $index Identifier for a specific print area range allowing several ranges to be set
  671. * A positive index will insert after that indexed entry in the print areas list, while a
  672. * negative index will insert before the indexed entry.
  673. * Specifying an index value of 0, will always append the new print range at the end of the
  674. * list.
  675. * Print areas are numbered from 1
  676. * @return PHPExcel_Worksheet_PageSetup
  677. * @throws PHPExcel_Exception
  678. */
  679. public function addPrintArea($value, $index = -1)
  680. {
  681. return $this->setPrintArea($value, $index, self::SETPRINTRANGE_INSERT);
  682. }
  683. /**
  684. * Set print area
  685. *
  686. * @param int $column1 Column 1
  687. * @param int $row1 Row 1
  688. * @param int $column2 Column 2
  689. * @param int $row2 Row 2
  690. * @param int $index Identifier for a specific print area range allowing several ranges to be set
  691. * When the method is "O"verwrite, then a positive integer index will overwrite that indexed
  692. * entry in the print areas list; a negative index value will identify which entry to
  693. * overwrite working bacward through the print area to the list, with the last entry as -1.
  694. * Specifying an index value of 0, will overwrite <b>all</b> existing print ranges.
  695. * When the method is "I"nsert, then a positive index will insert after that indexed entry in
  696. * the print areas list, while a negative index will insert before the indexed entry.
  697. * Specifying an index value of 0, will always append the new print range at the end of the
  698. * list.
  699. * Print areas are numbered from 1
  700. * @param string $method Determines the method used when setting multiple print areas
  701. * Default behaviour, or the "O" method, overwrites existing print area
  702. * The "I" method, inserts the new print area before any specified index, or at the end of the list
  703. * @return PHPExcel_Worksheet_PageSetup
  704. * @throws PHPExcel_Exception
  705. */
  706. public function setPrintAreaByColumnAndRow($column1, $row1, $column2, $row2, $index = 0, $method = self::SETPRINTRANGE_OVERWRITE)
  707. {
  708. return $this->setPrintArea(
  709. PHPExcel_Cell::stringFromColumnIndex($column1) . $row1 . ':' . PHPExcel_Cell::stringFromColumnIndex($column2) . $row2,
  710. $index,
  711. $method
  712. );
  713. }
  714. /**
  715. * Add a new print area to the list of print areas
  716. *
  717. * @param int $column1 Start Column for the print area
  718. * @param int $row1 Start Row for the print area
  719. * @param int $column2 End Column for the print area
  720. * @param int $row2 End Row for the print area
  721. * @param int $index Identifier for a specific print area range allowing several ranges to be set
  722. * A positive index will insert after that indexed entry in the print areas list, while a
  723. * negative index will insert before the indexed entry.
  724. * Specifying an index value of 0, will always append the new print range at the end of the
  725. * list.
  726. * Print areas are numbered from 1
  727. * @return PHPExcel_Worksheet_PageSetup
  728. * @throws PHPExcel_Exception
  729. */
  730. public function addPrintAreaByColumnAndRow($column1, $row1, $column2, $row2, $index = -1)
  731. {
  732. return $this->setPrintArea(
  733. PHPExcel_Cell::stringFromColumnIndex($column1) . $row1 . ':' . PHPExcel_Cell::stringFromColumnIndex($column2) . $row2,
  734. $index,
  735. self::SETPRINTRANGE_INSERT
  736. );
  737. }
  738. /**
  739. * Get first page number
  740. *
  741. * @return int
  742. */
  743. public function getFirstPageNumber()
  744. {
  745. return $this->firstPageNumber;
  746. }
  747. /**
  748. * Set first page number
  749. *
  750. * @param int $value
  751. * @return PHPExcel_Worksheet_HeaderFooter
  752. */
  753. public function setFirstPageNumber($value = null)
  754. {
  755. $this->firstPageNumber = $value;
  756. return $this;
  757. }
  758. /**
  759. * Reset first page number
  760. *
  761. * @return PHPExcel_Worksheet_HeaderFooter
  762. */
  763. public function resetFirstPageNumber()
  764. {
  765. return $this->setFirstPageNumber(null);
  766. }
  767. /**
  768. * Implement PHP __clone to create a deep clone, not just a shallow copy.
  769. */
  770. public function __clone()
  771. {
  772. $vars = get_object_vars($this);
  773. foreach ($vars as $key => $value) {
  774. if (is_object($value)) {
  775. $this->$key = clone $value;
  776. } else {
  777. $this->$key = $value;
  778. }
  779. }
  780. }
  781. }