PageRenderTime 45ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/application/third_party/PHPExcel/Worksheet/PageSetup.php

https://github.com/daycry/gestion_colas
PHP | 798 lines | 303 code | 58 blank | 437 comment | 46 complexity | ee75b3d231b5cc301bf885af3011d825 MD5 | raw file
Possible License(s): Apache-2.0, GPL-2.0, GPL-3.0
  1. <?php
  2. /**
  3. * PHPExcel
  4. *
  5. * Copyright (c) 2006 - 2013 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 - 2013 PHPExcel (http://www.codeplex.com/PHPExcel)
  24. * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
  25. * @version 1.7.9, 2013-06-02
  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 - 2013 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. return $this->_paperSize;
  272. }
  273. /**
  274. * Set Paper Size
  275. *
  276. * @param int $pValue
  277. * @return PHPExcel_Worksheet_PageSetup
  278. */
  279. public function setPaperSize($pValue = PHPExcel_Worksheet_PageSetup::PAPERSIZE_LETTER) {
  280. $this->_paperSize = $pValue;
  281. return $this;
  282. }
  283. /**
  284. * Get Orientation
  285. *
  286. * @return string
  287. */
  288. public function getOrientation() {
  289. return $this->_orientation;
  290. }
  291. /**
  292. * Set Orientation
  293. *
  294. * @param string $pValue
  295. * @return PHPExcel_Worksheet_PageSetup
  296. */
  297. public function setOrientation($pValue = PHPExcel_Worksheet_PageSetup::ORIENTATION_DEFAULT) {
  298. $this->_orientation = $pValue;
  299. return $this;
  300. }
  301. /**
  302. * Get Scale
  303. *
  304. * @return int?
  305. */
  306. public function getScale() {
  307. return $this->_scale;
  308. }
  309. /**
  310. * Set Scale
  311. *
  312. * Print scaling. Valid values range from 10 to 400
  313. * This setting is overridden when fitToWidth and/or fitToHeight are in use
  314. *
  315. * @param int? $pValue
  316. * @param boolean $pUpdate Update fitToPage so scaling applies rather than fitToHeight / fitToWidth
  317. * @return PHPExcel_Worksheet_PageSetup
  318. * @throws PHPExcel_Exception
  319. */
  320. public function setScale($pValue = 100, $pUpdate = true) {
  321. // Microsoft Office Excel 2007 only allows setting a scale between 10 and 400 via the user interface,
  322. // but it is apparently still able to handle any scale >= 0, where 0 results in 100
  323. if (($pValue >= 0) || is_null($pValue)) {
  324. $this->_scale = $pValue;
  325. if ($pUpdate) {
  326. $this->_fitToPage = false;
  327. }
  328. } else {
  329. throw new PHPExcel_Exception("Scale must not be negative");
  330. }
  331. return $this;
  332. }
  333. /**
  334. * Get Fit To Page
  335. *
  336. * @return boolean
  337. */
  338. public function getFitToPage() {
  339. return $this->_fitToPage;
  340. }
  341. /**
  342. * Set Fit To Page
  343. *
  344. * @param boolean $pValue
  345. * @return PHPExcel_Worksheet_PageSetup
  346. */
  347. public function setFitToPage($pValue = TRUE) {
  348. $this->_fitToPage = $pValue;
  349. return $this;
  350. }
  351. /**
  352. * Get Fit To Height
  353. *
  354. * @return int?
  355. */
  356. public function getFitToHeight() {
  357. return $this->_fitToHeight;
  358. }
  359. /**
  360. * Set Fit To Height
  361. *
  362. * @param int? $pValue
  363. * @param boolean $pUpdate Update fitToPage so it applies rather than scaling
  364. * @return PHPExcel_Worksheet_PageSetup
  365. */
  366. public function setFitToHeight($pValue = 1, $pUpdate = TRUE) {
  367. $this->_fitToHeight = $pValue;
  368. if ($pUpdate) {
  369. $this->_fitToPage = TRUE;
  370. }
  371. return $this;
  372. }
  373. /**
  374. * Get Fit To Width
  375. *
  376. * @return int?
  377. */
  378. public function getFitToWidth() {
  379. return $this->_fitToWidth;
  380. }
  381. /**
  382. * Set Fit To Width
  383. *
  384. * @param int? $pValue
  385. * @param boolean $pUpdate Update fitToPage so it applies rather than scaling
  386. * @return PHPExcel_Worksheet_PageSetup
  387. */
  388. public function setFitToWidth($pValue = 1, $pUpdate = TRUE) {
  389. $this->_fitToWidth = $pValue;
  390. if ($pUpdate) {
  391. $this->_fitToPage = TRUE;
  392. }
  393. return $this;
  394. }
  395. /**
  396. * Is Columns to repeat at left set?
  397. *
  398. * @return boolean
  399. */
  400. public function isColumnsToRepeatAtLeftSet() {
  401. if (is_array($this->_columnsToRepeatAtLeft)) {
  402. if ($this->_columnsToRepeatAtLeft[0] != '' && $this->_columnsToRepeatAtLeft[1] != '') {
  403. return true;
  404. }
  405. }
  406. return false;
  407. }
  408. /**
  409. * Get Columns to repeat at left
  410. *
  411. * @return array Containing start column and end column, empty array if option unset
  412. */
  413. public function getColumnsToRepeatAtLeft() {
  414. return $this->_columnsToRepeatAtLeft;
  415. }
  416. /**
  417. * Set Columns to repeat at left
  418. *
  419. * @param array $pValue Containing start column and end column, empty array if option unset
  420. * @return PHPExcel_Worksheet_PageSetup
  421. */
  422. public function setColumnsToRepeatAtLeft($pValue = null) {
  423. if (is_array($pValue)) {
  424. $this->_columnsToRepeatAtLeft = $pValue;
  425. }
  426. return $this;
  427. }
  428. /**
  429. * Set Columns to repeat at left by start and end
  430. *
  431. * @param string $pStart
  432. * @param string $pEnd
  433. * @return PHPExcel_Worksheet_PageSetup
  434. */
  435. public function setColumnsToRepeatAtLeftByStartAndEnd($pStart = 'A', $pEnd = 'A') {
  436. $this->_columnsToRepeatAtLeft = array($pStart, $pEnd);
  437. return $this;
  438. }
  439. /**
  440. * Is Rows to repeat at top set?
  441. *
  442. * @return boolean
  443. */
  444. public function isRowsToRepeatAtTopSet() {
  445. if (is_array($this->_rowsToRepeatAtTop)) {
  446. if ($this->_rowsToRepeatAtTop[0] != 0 && $this->_rowsToRepeatAtTop[1] != 0) {
  447. return true;
  448. }
  449. }
  450. return false;
  451. }
  452. /**
  453. * Get Rows to repeat at top
  454. *
  455. * @return array Containing start column and end column, empty array if option unset
  456. */
  457. public function getRowsToRepeatAtTop() {
  458. return $this->_rowsToRepeatAtTop;
  459. }
  460. /**
  461. * Set Rows to repeat at top
  462. *
  463. * @param array $pValue Containing start column and end column, empty array if option unset
  464. * @return PHPExcel_Worksheet_PageSetup
  465. */
  466. public function setRowsToRepeatAtTop($pValue = null) {
  467. if (is_array($pValue)) {
  468. $this->_rowsToRepeatAtTop = $pValue;
  469. }
  470. return $this;
  471. }
  472. /**
  473. * Set Rows to repeat at top by start and end
  474. *
  475. * @param int $pStart
  476. * @param int $pEnd
  477. * @return PHPExcel_Worksheet_PageSetup
  478. */
  479. public function setRowsToRepeatAtTopByStartAndEnd($pStart = 1, $pEnd = 1) {
  480. $this->_rowsToRepeatAtTop = array($pStart, $pEnd);
  481. return $this;
  482. }
  483. /**
  484. * Get center page horizontally
  485. *
  486. * @return bool
  487. */
  488. public function getHorizontalCentered() {
  489. return $this->_horizontalCentered;
  490. }
  491. /**
  492. * Set center page horizontally
  493. *
  494. * @param bool $value
  495. * @return PHPExcel_Worksheet_PageSetup
  496. */
  497. public function setHorizontalCentered($value = false) {
  498. $this->_horizontalCentered = $value;
  499. return $this;
  500. }
  501. /**
  502. * Get center page vertically
  503. *
  504. * @return bool
  505. */
  506. public function getVerticalCentered() {
  507. return $this->_verticalCentered;
  508. }
  509. /**
  510. * Set center page vertically
  511. *
  512. * @param bool $value
  513. * @return PHPExcel_Worksheet_PageSetup
  514. */
  515. public function setVerticalCentered($value = false) {
  516. $this->_verticalCentered = $value;
  517. return $this;
  518. }
  519. /**
  520. * Get print area
  521. *
  522. * @param int $index Identifier for a specific print area range if several ranges have been set
  523. * Default behaviour, or a index value of 0, will return all ranges as a comma-separated string
  524. * Otherwise, the specific range identified by the value of $index will be returned
  525. * Print areas are numbered from 1
  526. * @throws PHPExcel_Exception
  527. * @return string
  528. */
  529. public function getPrintArea($index = 0) {
  530. if ($index == 0) {
  531. return $this->_printArea;
  532. }
  533. $printAreas = explode(',',$this->_printArea);
  534. if (isset($printAreas[$index-1])) {
  535. return $printAreas[$index-1];
  536. }
  537. throw new PHPExcel_Exception("Requested Print Area does not exist");
  538. }
  539. /**
  540. * Is print area set?
  541. *
  542. * @param int $index Identifier for a specific print area range if several ranges have been set
  543. * Default behaviour, or an index value of 0, will identify whether any print range is set
  544. * Otherwise, existence of the range identified by the value of $index will be returned
  545. * Print areas are numbered from 1
  546. * @return boolean
  547. */
  548. public function isPrintAreaSet($index = 0) {
  549. if ($index == 0) {
  550. return !is_null($this->_printArea);
  551. }
  552. $printAreas = explode(',',$this->_printArea);
  553. return isset($printAreas[$index-1]);
  554. }
  555. /**
  556. * Clear a print area
  557. *
  558. * @param int $index Identifier for a specific print area range if several ranges have been set
  559. * Default behaviour, or an index value of 0, will clear all print ranges that are set
  560. * Otherwise, the range identified by the value of $index will be removed from the series
  561. * Print areas are numbered from 1
  562. * @return PHPExcel_Worksheet_PageSetup
  563. */
  564. public function clearPrintArea($index = 0) {
  565. if ($index == 0) {
  566. $this->_printArea = NULL;
  567. } else {
  568. $printAreas = explode(',',$this->_printArea);
  569. if (isset($printAreas[$index-1])) {
  570. unset($printAreas[$index-1]);
  571. $this->_printArea = implode(',',$printAreas);
  572. }
  573. }
  574. return $this;
  575. }
  576. /**
  577. * Set print area. e.g. 'A1:D10' or 'A1:D10,G5:M20'
  578. *
  579. * @param string $value
  580. * @param int $index Identifier for a specific print area range allowing several ranges to be set
  581. * When the method is "O"verwrite, then a positive integer index will overwrite that indexed
  582. * entry in the print areas list; a negative index value will identify which entry to
  583. * overwrite working bacward through the print area to the list, with the last entry as -1.
  584. * Specifying an index value of 0, will overwrite <b>all</b> existing print ranges.
  585. * When the method is "I"nsert, then a positive index will insert after that indexed entry in
  586. * the print areas list, while a negative index will insert before the indexed entry.
  587. * Specifying an index value of 0, will always append the new print range at the end of the
  588. * list.
  589. * Print areas are numbered from 1
  590. * @param string $method Determines the method used when setting multiple print areas
  591. * Default behaviour, or the "O" method, overwrites existing print area
  592. * The "I" method, inserts the new print area before any specified index, or at the end of the list
  593. * @return PHPExcel_Worksheet_PageSetup
  594. * @throws PHPExcel_Exception
  595. */
  596. public function setPrintArea($value, $index = 0, $method = self::SETPRINTRANGE_OVERWRITE) {
  597. if (strpos($value,'!') !== false) {
  598. throw new PHPExcel_Exception('Cell coordinate must not specify a worksheet.');
  599. } elseif (strpos($value,':') === false) {
  600. throw new PHPExcel_Exception('Cell coordinate must be a range of cells.');
  601. } elseif (strpos($value,'$') !== false) {
  602. throw new PHPExcel_Exception('Cell coordinate must not be absolute.');
  603. }
  604. $value = strtoupper($value);
  605. if ($method == self::SETPRINTRANGE_OVERWRITE) {
  606. if ($index == 0) {
  607. $this->_printArea = $value;
  608. } else {
  609. $printAreas = explode(',',$this->_printArea);
  610. if($index < 0) {
  611. $index = count($printAreas) - abs($index) + 1;
  612. }
  613. if (($index <= 0) || ($index > count($printAreas))) {
  614. throw new PHPExcel_Exception('Invalid index for setting print range.');
  615. }
  616. $printAreas[$index-1] = $value;
  617. $this->_printArea = implode(',',$printAreas);
  618. }
  619. } elseif($method == self::SETPRINTRANGE_INSERT) {
  620. if ($index == 0) {
  621. $this->_printArea .= ($this->_printArea == '') ? $value : ','.$value;
  622. } else {
  623. $printAreas = explode(',',$this->_printArea);
  624. if($index < 0) {
  625. $index = abs($index) - 1;
  626. }
  627. if ($index > count($printAreas)) {
  628. throw new PHPExcel_Exception('Invalid index for setting print range.');
  629. }
  630. $printAreas = array_merge(array_slice($printAreas,0,$index),array($value),array_slice($printAreas,$index));
  631. $this->_printArea = implode(',',$printAreas);
  632. }
  633. } else {
  634. throw new PHPExcel_Exception('Invalid method for setting print range.');
  635. }
  636. return $this;
  637. }
  638. /**
  639. * Add a new print area (e.g. 'A1:D10' or 'A1:D10,G5:M20') to the list of print areas
  640. *
  641. * @param string $value
  642. * @param int $index Identifier for a specific print area range allowing several ranges to be set
  643. * A positive index will insert after that indexed entry in the print areas list, while a
  644. * negative index will insert before the indexed entry.
  645. * Specifying an index value of 0, will always append the new print range at the end of the
  646. * list.
  647. * Print areas are numbered from 1
  648. * @return PHPExcel_Worksheet_PageSetup
  649. * @throws PHPExcel_Exception
  650. */
  651. public function addPrintArea($value, $index = -1) {
  652. return $this->setPrintArea($value, $index, self::SETPRINTRANGE_INSERT);
  653. }
  654. /**
  655. * Set print area
  656. *
  657. * @param int $column1 Column 1
  658. * @param int $row1 Row 1
  659. * @param int $column2 Column 2
  660. * @param int $row2 Row 2
  661. * @param int $index Identifier for a specific print area range allowing several ranges to be set
  662. * When the method is "O"verwrite, then a positive integer index will overwrite that indexed
  663. * entry in the print areas list; a negative index value will identify which entry to
  664. * overwrite working bacward through the print area to the list, with the last entry as -1.
  665. * Specifying an index value of 0, will overwrite <b>all</b> existing print ranges.
  666. * When the method is "I"nsert, then a positive index will insert after that indexed entry in
  667. * the print areas list, while a negative index will insert before the indexed entry.
  668. * Specifying an index value of 0, will always append the new print range at the end of the
  669. * list.
  670. * Print areas are numbered from 1
  671. * @param string $method Determines the method used when setting multiple print areas
  672. * Default behaviour, or the "O" method, overwrites existing print area
  673. * The "I" method, inserts the new print area before any specified index, or at the end of the list
  674. * @return PHPExcel_Worksheet_PageSetup
  675. * @throws PHPExcel_Exception
  676. */
  677. public function setPrintAreaByColumnAndRow($column1, $row1, $column2, $row2, $index = 0, $method = self::SETPRINTRANGE_OVERWRITE)
  678. {
  679. return $this->setPrintArea(PHPExcel_Cell::stringFromColumnIndex($column1) . $row1 . ':' . PHPExcel_Cell::stringFromColumnIndex($column2) . $row2, $index, $method);
  680. }
  681. /**
  682. * Add a new print area to the list of print areas
  683. *
  684. * @param int $column1 Start Column for the print area
  685. * @param int $row1 Start Row for the print area
  686. * @param int $column2 End Column for the print area
  687. * @param int $row2 End Row for the print area
  688. * @param int $index Identifier for a specific print area range allowing several ranges to be set
  689. * A positive index will insert after that indexed entry in the print areas list, while a
  690. * negative index will insert before the indexed entry.
  691. * Specifying an index value of 0, will always append the new print range at the end of the
  692. * list.
  693. * Print areas are numbered from 1
  694. * @return PHPExcel_Worksheet_PageSetup
  695. * @throws PHPExcel_Exception
  696. */
  697. public function addPrintAreaByColumnAndRow($column1, $row1, $column2, $row2, $index = -1)
  698. {
  699. return $this->setPrintArea(PHPExcel_Cell::stringFromColumnIndex($column1) . $row1 . ':' . PHPExcel_Cell::stringFromColumnIndex($column2) . $row2, $index, self::SETPRINTRANGE_INSERT);
  700. }
  701. /**
  702. * Get first page number
  703. *
  704. * @return int
  705. */
  706. public function getFirstPageNumber() {
  707. return $this->_firstPageNumber;
  708. }
  709. /**
  710. * Set first page number
  711. *
  712. * @param int $value
  713. * @return PHPExcel_Worksheet_HeaderFooter
  714. */
  715. public function setFirstPageNumber($value = null) {
  716. $this->_firstPageNumber = $value;
  717. return $this;
  718. }
  719. /**
  720. * Reset first page number
  721. *
  722. * @return PHPExcel_Worksheet_HeaderFooter
  723. */
  724. public function resetFirstPageNumber() {
  725. return $this->setFirstPageNumber(null);
  726. }
  727. /**
  728. * Implement PHP __clone to create a deep clone, not just a shallow copy.
  729. */
  730. public function __clone() {
  731. $vars = get_object_vars($this);
  732. foreach ($vars as $key => $value) {
  733. if (is_object($value)) {
  734. $this->$key = clone $value;
  735. } else {
  736. $this->$key = $value;
  737. }
  738. }
  739. }
  740. }