PageSetup.php 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819
  1. <?php
  2. /**
  3. * 重庆赤晓店信息科技有限公司
  4. * https://www.chixiaodian.com
  5. * Copyright (c) 2023 赤店商城 All rights reserved.
  6. */
  7. /**
  8. * PHPExcel_Worksheet_PageSetup
  9. *
  10. * <code>
  11. * Paper size taken from Office Open XML Part 4 - Markup Language Reference, page 1988:
  12. *
  13. * 1 = Letter paper (8.5 in. by 11 in.)
  14. * 2 = Letter small paper (8.5 in. by 11 in.)
  15. * 3 = Tabloid paper (11 in. by 17 in.)
  16. * 4 = Ledger paper (17 in. by 11 in.)
  17. * 5 = Legal paper (8.5 in. by 14 in.)
  18. * 6 = Statement paper (5.5 in. by 8.5 in.)
  19. * 7 = Executive paper (7.25 in. by 10.5 in.)
  20. * 8 = A3 paper (297 mm by 420 mm)
  21. * 9 = A4 paper (210 mm by 297 mm)
  22. * 10 = A4 small paper (210 mm by 297 mm)
  23. * 11 = A5 paper (148 mm by 210 mm)
  24. * 12 = B4 paper (250 mm by 353 mm)
  25. * 13 = B5 paper (176 mm by 250 mm)
  26. * 14 = Folio paper (8.5 in. by 13 in.)
  27. * 15 = Quarto paper (215 mm by 275 mm)
  28. * 16 = Standard paper (10 in. by 14 in.)
  29. * 17 = Standard paper (11 in. by 17 in.)
  30. * 18 = Note paper (8.5 in. by 11 in.)
  31. * 19 = #9 envelope (3.875 in. by 8.875 in.)
  32. * 20 = #10 envelope (4.125 in. by 9.5 in.)
  33. * 21 = #11 envelope (4.5 in. by 10.375 in.)
  34. * 22 = #12 envelope (4.75 in. by 11 in.)
  35. * 23 = #14 envelope (5 in. by 11.5 in.)
  36. * 24 = C paper (17 in. by 22 in.)
  37. * 25 = D paper (22 in. by 34 in.)
  38. * 26 = E paper (34 in. by 44 in.)
  39. * 27 = DL envelope (110 mm by 220 mm)
  40. * 28 = C5 envelope (162 mm by 229 mm)
  41. * 29 = C3 envelope (324 mm by 458 mm)
  42. * 30 = C4 envelope (229 mm by 324 mm)
  43. * 31 = C6 envelope (114 mm by 162 mm)
  44. * 32 = C65 envelope (114 mm by 229 mm)
  45. * 33 = B4 envelope (250 mm by 353 mm)
  46. * 34 = B5 envelope (176 mm by 250 mm)
  47. * 35 = B6 envelope (176 mm by 125 mm)
  48. * 36 = Italy envelope (110 mm by 230 mm)
  49. * 37 = Monarch envelope (3.875 in. by 7.5 in.).
  50. * 38 = 6 3/4 envelope (3.625 in. by 6.5 in.)
  51. * 39 = US standard fanfold (14.875 in. by 11 in.)
  52. * 40 = German standard fanfold (8.5 in. by 12 in.)
  53. * 41 = German legal fanfold (8.5 in. by 13 in.)
  54. * 42 = ISO B4 (250 mm by 353 mm)
  55. * 43 = Japanese double postcard (200 mm by 148 mm)
  56. * 44 = Standard paper (9 in. by 11 in.)
  57. * 45 = Standard paper (10 in. by 11 in.)
  58. * 46 = Standard paper (15 in. by 11 in.)
  59. * 47 = Invite envelope (220 mm by 220 mm)
  60. * 50 = Letter extra paper (9.275 in. by 12 in.)
  61. * 51 = Legal extra paper (9.275 in. by 15 in.)
  62. * 52 = Tabloid extra paper (11.69 in. by 18 in.)
  63. * 53 = A4 extra paper (236 mm by 322 mm)
  64. * 54 = Letter transverse paper (8.275 in. by 11 in.)
  65. * 55 = A4 transverse paper (210 mm by 297 mm)
  66. * 56 = Letter extra transverse paper (9.275 in. by 12 in.)
  67. * 57 = SuperA/SuperA/A4 paper (227 mm by 356 mm)
  68. * 58 = SuperB/SuperB/A3 paper (305 mm by 487 mm)
  69. * 59 = Letter plus paper (8.5 in. by 12.69 in.)
  70. * 60 = A4 plus paper (210 mm by 330 mm)
  71. * 61 = A5 transverse paper (148 mm by 210 mm)
  72. * 62 = JIS B5 transverse paper (182 mm by 257 mm)
  73. * 63 = A3 extra paper (322 mm by 445 mm)
  74. * 64 = A5 extra paper (174 mm by 235 mm)
  75. * 65 = ISO B5 extra paper (201 mm by 276 mm)
  76. * 66 = A2 paper (420 mm by 594 mm)
  77. * 67 = A3 transverse paper (297 mm by 420 mm)
  78. * 68 = A3 extra transverse paper (322 mm by 445 mm)
  79. * </code>
  80. *
  81. * @category PHPExcel
  82. * @package PHPExcel_Worksheet
  83. * @copyright Copyright (c) 2006 - 2015 PHPExcel (http://www.codeplex.com/PHPExcel)
  84. */
  85. class PHPExcel_Worksheet_PageSetup
  86. {
  87. /* Paper size */
  88. const PAPERSIZE_LETTER = 1;
  89. const PAPERSIZE_LETTER_SMALL = 2;
  90. const PAPERSIZE_TABLOID = 3;
  91. const PAPERSIZE_LEDGER = 4;
  92. const PAPERSIZE_LEGAL = 5;
  93. const PAPERSIZE_STATEMENT = 6;
  94. const PAPERSIZE_EXECUTIVE = 7;
  95. const PAPERSIZE_A3 = 8;
  96. const PAPERSIZE_A4 = 9;
  97. const PAPERSIZE_A4_SMALL = 10;
  98. const PAPERSIZE_A5 = 11;
  99. const PAPERSIZE_B4 = 12;
  100. const PAPERSIZE_B5 = 13;
  101. const PAPERSIZE_FOLIO = 14;
  102. const PAPERSIZE_QUARTO = 15;
  103. const PAPERSIZE_STANDARD_1 = 16;
  104. const PAPERSIZE_STANDARD_2 = 17;
  105. const PAPERSIZE_NOTE = 18;
  106. const PAPERSIZE_NO9_ENVELOPE = 19;
  107. const PAPERSIZE_NO10_ENVELOPE = 20;
  108. const PAPERSIZE_NO11_ENVELOPE = 21;
  109. const PAPERSIZE_NO12_ENVELOPE = 22;
  110. const PAPERSIZE_NO14_ENVELOPE = 23;
  111. const PAPERSIZE_C = 24;
  112. const PAPERSIZE_D = 25;
  113. const PAPERSIZE_E = 26;
  114. const PAPERSIZE_DL_ENVELOPE = 27;
  115. const PAPERSIZE_C5_ENVELOPE = 28;
  116. const PAPERSIZE_C3_ENVELOPE = 29;
  117. const PAPERSIZE_C4_ENVELOPE = 30;
  118. const PAPERSIZE_C6_ENVELOPE = 31;
  119. const PAPERSIZE_C65_ENVELOPE = 32;
  120. const PAPERSIZE_B4_ENVELOPE = 33;
  121. const PAPERSIZE_B5_ENVELOPE = 34;
  122. const PAPERSIZE_B6_ENVELOPE = 35;
  123. const PAPERSIZE_ITALY_ENVELOPE = 36;
  124. const PAPERSIZE_MONARCH_ENVELOPE = 37;
  125. const PAPERSIZE_6_3_4_ENVELOPE = 38;
  126. const PAPERSIZE_US_STANDARD_FANFOLD = 39;
  127. const PAPERSIZE_GERMAN_STANDARD_FANFOLD = 40;
  128. const PAPERSIZE_GERMAN_LEGAL_FANFOLD = 41;
  129. const PAPERSIZE_ISO_B4 = 42;
  130. const PAPERSIZE_JAPANESE_DOUBLE_POSTCARD = 43;
  131. const PAPERSIZE_STANDARD_PAPER_1 = 44;
  132. const PAPERSIZE_STANDARD_PAPER_2 = 45;
  133. const PAPERSIZE_STANDARD_PAPER_3 = 46;
  134. const PAPERSIZE_INVITE_ENVELOPE = 47;
  135. const PAPERSIZE_LETTER_EXTRA_PAPER = 48;
  136. const PAPERSIZE_LEGAL_EXTRA_PAPER = 49;
  137. const PAPERSIZE_TABLOID_EXTRA_PAPER = 50;
  138. const PAPERSIZE_A4_EXTRA_PAPER = 51;
  139. const PAPERSIZE_LETTER_TRANSVERSE_PAPER = 52;
  140. const PAPERSIZE_A4_TRANSVERSE_PAPER = 53;
  141. const PAPERSIZE_LETTER_EXTRA_TRANSVERSE_PAPER = 54;
  142. const PAPERSIZE_SUPERA_SUPERA_A4_PAPER = 55;
  143. const PAPERSIZE_SUPERB_SUPERB_A3_PAPER = 56;
  144. const PAPERSIZE_LETTER_PLUS_PAPER = 57;
  145. const PAPERSIZE_A4_PLUS_PAPER = 58;
  146. const PAPERSIZE_A5_TRANSVERSE_PAPER = 59;
  147. const PAPERSIZE_JIS_B5_TRANSVERSE_PAPER = 60;
  148. const PAPERSIZE_A3_EXTRA_PAPER = 61;
  149. const PAPERSIZE_A5_EXTRA_PAPER = 62;
  150. const PAPERSIZE_ISO_B5_EXTRA_PAPER = 63;
  151. const PAPERSIZE_A2_PAPER = 64;
  152. const PAPERSIZE_A3_TRANSVERSE_PAPER = 65;
  153. const PAPERSIZE_A3_EXTRA_TRANSVERSE_PAPER = 66;
  154. /* Page orientation */
  155. const ORIENTATION_DEFAULT = 'default';
  156. const ORIENTATION_LANDSCAPE = 'landscape';
  157. const ORIENTATION_PORTRAIT = 'portrait';
  158. /* Print Range Set Method */
  159. const SETPRINTRANGE_OVERWRITE = 'O';
  160. const SETPRINTRANGE_INSERT = 'I';
  161. /**
  162. * Paper size
  163. *
  164. * @var int
  165. */
  166. private $paperSize = PHPExcel_Worksheet_PageSetup::PAPERSIZE_LETTER;
  167. /**
  168. * Orientation
  169. *
  170. * @var string
  171. */
  172. private $orientation = PHPExcel_Worksheet_PageSetup::ORIENTATION_DEFAULT;
  173. /**
  174. * Scale (Print Scale)
  175. *
  176. * Print scaling. Valid values range from 10 to 400
  177. * This setting is overridden when fitToWidth and/or fitToHeight are in use
  178. *
  179. * @var int?
  180. */
  181. private $scale = 100;
  182. /**
  183. * Fit To Page
  184. * Whether scale or fitToWith / fitToHeight applies
  185. *
  186. * @var boolean
  187. */
  188. private $fitToPage = false;
  189. /**
  190. * Fit To Height
  191. * Number of vertical pages to fit on
  192. *
  193. * @var int?
  194. */
  195. private $fitToHeight = 1;
  196. /**
  197. * Fit To Width
  198. * Number of horizontal pages to fit on
  199. *
  200. * @var int?
  201. */
  202. private $fitToWidth = 1;
  203. /**
  204. * Columns to repeat at left
  205. *
  206. * @var array Containing start column and end column, empty array if option unset
  207. */
  208. private $columnsToRepeatAtLeft = array('', '');
  209. /**
  210. * Rows to repeat at top
  211. *
  212. * @var array Containing start row number and end row number, empty array if option unset
  213. */
  214. private $rowsToRepeatAtTop = array(0, 0);
  215. /**
  216. * Center page horizontally
  217. *
  218. * @var boolean
  219. */
  220. private $horizontalCentered = false;
  221. /**
  222. * Center page vertically
  223. *
  224. * @var boolean
  225. */
  226. private $verticalCentered = false;
  227. /**
  228. * Print area
  229. *
  230. * @var string
  231. */
  232. private $printArea = null;
  233. /**
  234. * First page number
  235. *
  236. * @var int
  237. */
  238. private $firstPageNumber = null;
  239. /**
  240. * Create a new PHPExcel_Worksheet_PageSetup
  241. */
  242. public function __construct()
  243. {
  244. }
  245. /**
  246. * Get Paper Size
  247. *
  248. * @return int
  249. */
  250. public function getPaperSize()
  251. {
  252. return $this->paperSize;
  253. }
  254. /**
  255. * Set Paper Size
  256. *
  257. * @param int $pValue
  258. * @return PHPExcel_Worksheet_PageSetup
  259. */
  260. public function setPaperSize($pValue = PHPExcel_Worksheet_PageSetup::PAPERSIZE_LETTER)
  261. {
  262. $this->paperSize = $pValue;
  263. return $this;
  264. }
  265. /**
  266. * Get Orientation
  267. *
  268. * @return string
  269. */
  270. public function getOrientation()
  271. {
  272. return $this->orientation;
  273. }
  274. /**
  275. * Set Orientation
  276. *
  277. * @param string $pValue
  278. * @return PHPExcel_Worksheet_PageSetup
  279. */
  280. public function setOrientation($pValue = PHPExcel_Worksheet_PageSetup::ORIENTATION_DEFAULT)
  281. {
  282. $this->orientation = $pValue;
  283. return $this;
  284. }
  285. /**
  286. * Get Scale
  287. *
  288. * @return int?
  289. */
  290. public function getScale()
  291. {
  292. return $this->scale;
  293. }
  294. /**
  295. * Set Scale
  296. *
  297. * Print scaling. Valid values range from 10 to 400
  298. * This setting is overridden when fitToWidth and/or fitToHeight are in use
  299. *
  300. * @param int? $pValue
  301. * @param boolean $pUpdate Update fitToPage so scaling applies rather than fitToHeight / fitToWidth
  302. * @return PHPExcel_Worksheet_PageSetup
  303. * @throws PHPExcel_Exception
  304. */
  305. public function setScale($pValue = 100, $pUpdate = true)
  306. {
  307. // Microsoft Office Excel 2007 only allows setting a scale between 10 and 400 via the user interface,
  308. // but it is apparently still able to handle any scale >= 0, where 0 results in 100
  309. if (($pValue >= 0) || is_null($pValue)) {
  310. $this->scale = $pValue;
  311. if ($pUpdate) {
  312. $this->fitToPage = false;
  313. }
  314. } else {
  315. throw new PHPExcel_Exception("Scale must not be negative");
  316. }
  317. return $this;
  318. }
  319. /**
  320. * Get Fit To Page
  321. *
  322. * @return boolean
  323. */
  324. public function getFitToPage()
  325. {
  326. return $this->fitToPage;
  327. }
  328. /**
  329. * Set Fit To Page
  330. *
  331. * @param boolean $pValue
  332. * @return PHPExcel_Worksheet_PageSetup
  333. */
  334. public function setFitToPage($pValue = true)
  335. {
  336. $this->fitToPage = $pValue;
  337. return $this;
  338. }
  339. /**
  340. * Get Fit To Height
  341. *
  342. * @return int?
  343. */
  344. public function getFitToHeight()
  345. {
  346. return $this->fitToHeight;
  347. }
  348. /**
  349. * Set Fit To Height
  350. *
  351. * @param int? $pValue
  352. * @param boolean $pUpdate Update fitToPage so it applies rather than scaling
  353. * @return PHPExcel_Worksheet_PageSetup
  354. */
  355. public function setFitToHeight($pValue = 1, $pUpdate = true)
  356. {
  357. $this->fitToHeight = $pValue;
  358. if ($pUpdate) {
  359. $this->fitToPage = true;
  360. }
  361. return $this;
  362. }
  363. /**
  364. * Get Fit To Width
  365. *
  366. * @return int?
  367. */
  368. public function getFitToWidth()
  369. {
  370. return $this->fitToWidth;
  371. }
  372. /**
  373. * Set Fit To Width
  374. *
  375. * @param int? $pValue
  376. * @param boolean $pUpdate Update fitToPage so it applies rather than scaling
  377. * @return PHPExcel_Worksheet_PageSetup
  378. */
  379. public function setFitToWidth($pValue = 1, $pUpdate = true)
  380. {
  381. $this->fitToWidth = $pValue;
  382. if ($pUpdate) {
  383. $this->fitToPage = true;
  384. }
  385. return $this;
  386. }
  387. /**
  388. * Is Columns to repeat at left set?
  389. *
  390. * @return boolean
  391. */
  392. public function isColumnsToRepeatAtLeftSet()
  393. {
  394. if (is_array($this->columnsToRepeatAtLeft)) {
  395. if ($this->columnsToRepeatAtLeft[0] != '' && $this->columnsToRepeatAtLeft[1] != '') {
  396. return true;
  397. }
  398. }
  399. return false;
  400. }
  401. /**
  402. * Get Columns to repeat at left
  403. *
  404. * @return array Containing start column and end column, empty array if option unset
  405. */
  406. public function getColumnsToRepeatAtLeft()
  407. {
  408. return $this->columnsToRepeatAtLeft;
  409. }
  410. /**
  411. * Set Columns to repeat at left
  412. *
  413. * @param array $pValue Containing start column and end column, empty array if option unset
  414. * @return PHPExcel_Worksheet_PageSetup
  415. */
  416. public function setColumnsToRepeatAtLeft($pValue = null)
  417. {
  418. if (is_array($pValue)) {
  419. $this->columnsToRepeatAtLeft = $pValue;
  420. }
  421. return $this;
  422. }
  423. /**
  424. * Set Columns to repeat at left by start and end
  425. *
  426. * @param string $pStart
  427. * @param string $pEnd
  428. * @return PHPExcel_Worksheet_PageSetup
  429. */
  430. public function setColumnsToRepeatAtLeftByStartAndEnd($pStart = 'A', $pEnd = 'A')
  431. {
  432. $this->columnsToRepeatAtLeft = array($pStart, $pEnd);
  433. return $this;
  434. }
  435. /**
  436. * Is Rows to repeat at top set?
  437. *
  438. * @return boolean
  439. */
  440. public function isRowsToRepeatAtTopSet()
  441. {
  442. if (is_array($this->rowsToRepeatAtTop)) {
  443. if ($this->rowsToRepeatAtTop[0] != 0 && $this->rowsToRepeatAtTop[1] != 0) {
  444. return true;
  445. }
  446. }
  447. return false;
  448. }
  449. /**
  450. * Get Rows to repeat at top
  451. *
  452. * @return array Containing start column and end column, empty array if option unset
  453. */
  454. public function getRowsToRepeatAtTop()
  455. {
  456. return $this->rowsToRepeatAtTop;
  457. }
  458. /**
  459. * Set Rows to repeat at top
  460. *
  461. * @param array $pValue Containing start column and end column, empty array if option unset
  462. * @return PHPExcel_Worksheet_PageSetup
  463. */
  464. public function setRowsToRepeatAtTop($pValue = null)
  465. {
  466. if (is_array($pValue)) {
  467. $this->rowsToRepeatAtTop = $pValue;
  468. }
  469. return $this;
  470. }
  471. /**
  472. * Set Rows to repeat at top by start and end
  473. *
  474. * @param int $pStart
  475. * @param int $pEnd
  476. * @return PHPExcel_Worksheet_PageSetup
  477. */
  478. public function setRowsToRepeatAtTopByStartAndEnd($pStart = 1, $pEnd = 1)
  479. {
  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. {
  490. return $this->horizontalCentered;
  491. }
  492. /**
  493. * Set center page horizontally
  494. *
  495. * @param bool $value
  496. * @return PHPExcel_Worksheet_PageSetup
  497. */
  498. public function setHorizontalCentered($value = false)
  499. {
  500. $this->horizontalCentered = $value;
  501. return $this;
  502. }
  503. /**
  504. * Get center page vertically
  505. *
  506. * @return bool
  507. */
  508. public function getVerticalCentered()
  509. {
  510. return $this->verticalCentered;
  511. }
  512. /**
  513. * Set center page vertically
  514. *
  515. * @param bool $value
  516. * @return PHPExcel_Worksheet_PageSetup
  517. */
  518. public function setVerticalCentered($value = false)
  519. {
  520. $this->verticalCentered = $value;
  521. return $this;
  522. }
  523. /**
  524. * Get print area
  525. *
  526. * @param int $index Identifier for a specific print area range if several ranges have been set
  527. * Default behaviour, or a index value of 0, will return all ranges as a comma-separated string
  528. * Otherwise, the specific range identified by the value of $index will be returned
  529. * Print areas are numbered from 1
  530. * @throws PHPExcel_Exception
  531. * @return string
  532. */
  533. public function getPrintArea($index = 0)
  534. {
  535. if ($index == 0) {
  536. return $this->printArea;
  537. }
  538. $printAreas = explode(',', $this->printArea);
  539. if (isset($printAreas[$index-1])) {
  540. return $printAreas[$index-1];
  541. }
  542. throw new PHPExcel_Exception("Requested Print Area does not exist");
  543. }
  544. /**
  545. * Is print area set?
  546. *
  547. * @param int $index Identifier for a specific print area range if several ranges have been set
  548. * Default behaviour, or an index value of 0, will identify whether any print range is set
  549. * Otherwise, existence of the range identified by the value of $index will be returned
  550. * Print areas are numbered from 1
  551. * @return boolean
  552. */
  553. public function isPrintAreaSet($index = 0)
  554. {
  555. if ($index == 0) {
  556. return !is_null($this->printArea);
  557. }
  558. $printAreas = explode(',', $this->printArea);
  559. return isset($printAreas[$index-1]);
  560. }
  561. /**
  562. * Clear a print area
  563. *
  564. * @param int $index Identifier for a specific print area range if several ranges have been set
  565. * Default behaviour, or an index value of 0, will clear all print ranges that are set
  566. * Otherwise, the range identified by the value of $index will be removed from the series
  567. * Print areas are numbered from 1
  568. * @return PHPExcel_Worksheet_PageSetup
  569. */
  570. public function clearPrintArea($index = 0)
  571. {
  572. if ($index == 0) {
  573. $this->printArea = null;
  574. } else {
  575. $printAreas = explode(',', $this->printArea);
  576. if (isset($printAreas[$index-1])) {
  577. unset($printAreas[$index-1]);
  578. $this->printArea = implode(',', $printAreas);
  579. }
  580. }
  581. return $this;
  582. }
  583. /**
  584. * Set print area. e.g. 'A1:D10' or 'A1:D10,G5:M20'
  585. *
  586. * @param string $value
  587. * @param int $index Identifier for a specific print area range allowing several ranges to be set
  588. * When the method is "O"verwrite, then a positive integer index will overwrite that indexed
  589. * entry in the print areas list; a negative index value will identify which entry to
  590. * overwrite working bacward through the print area to the list, with the last entry as -1.
  591. * Specifying an index value of 0, will overwrite <b>all</b> existing print ranges.
  592. * When the method is "I"nsert, then a positive index will insert after that indexed entry in
  593. * the print areas list, while a negative index will insert before the indexed entry.
  594. * Specifying an index value of 0, will always append the new print range at the end of the
  595. * list.
  596. * Print areas are numbered from 1
  597. * @param string $method Determines the method used when setting multiple print areas
  598. * Default behaviour, or the "O" method, overwrites existing print area
  599. * The "I" method, inserts the new print area before any specified index, or at the end of the list
  600. * @return PHPExcel_Worksheet_PageSetup
  601. * @throws PHPExcel_Exception
  602. */
  603. public function setPrintArea($value, $index = 0, $method = self::SETPRINTRANGE_OVERWRITE)
  604. {
  605. if (strpos($value, '!') !== false) {
  606. throw new PHPExcel_Exception('Cell coordinate must not specify a worksheet.');
  607. } elseif (strpos($value, ':') === false) {
  608. throw new PHPExcel_Exception('Cell coordinate must be a range of cells.');
  609. } elseif (strpos($value, '$') !== false) {
  610. throw new PHPExcel_Exception('Cell coordinate must not be absolute.');
  611. }
  612. $value = strtoupper($value);
  613. if ($method == self::SETPRINTRANGE_OVERWRITE) {
  614. if ($index == 0) {
  615. $this->printArea = $value;
  616. } else {
  617. $printAreas = explode(',', $this->printArea);
  618. if ($index < 0) {
  619. $index = count($printAreas) - abs($index) + 1;
  620. }
  621. if (($index <= 0) || ($index > count($printAreas))) {
  622. throw new PHPExcel_Exception('Invalid index for setting print range.');
  623. }
  624. $printAreas[$index-1] = $value;
  625. $this->printArea = implode(',', $printAreas);
  626. }
  627. } elseif ($method == self::SETPRINTRANGE_INSERT) {
  628. if ($index == 0) {
  629. $this->printArea .= ($this->printArea == '') ? $value : ','.$value;
  630. } else {
  631. $printAreas = explode(',', $this->printArea);
  632. if ($index < 0) {
  633. $index = abs($index) - 1;
  634. }
  635. if ($index > count($printAreas)) {
  636. throw new PHPExcel_Exception('Invalid index for setting print range.');
  637. }
  638. $printAreas = array_merge(array_slice($printAreas, 0, $index), array($value), array_slice($printAreas, $index));
  639. $this->printArea = implode(',', $printAreas);
  640. }
  641. } else {
  642. throw new PHPExcel_Exception('Invalid method for setting print range.');
  643. }
  644. return $this;
  645. }
  646. /**
  647. * Add a new print area (e.g. 'A1:D10' or 'A1:D10,G5:M20') to the list of print areas
  648. *
  649. * @param string $value
  650. * @param int $index Identifier for a specific print area range allowing several ranges to be set
  651. * A positive index will insert after that indexed entry in the print areas list, while a
  652. * negative index will insert before the indexed entry.
  653. * Specifying an index value of 0, will always append the new print range at the end of the
  654. * list.
  655. * Print areas are numbered from 1
  656. * @return PHPExcel_Worksheet_PageSetup
  657. * @throws PHPExcel_Exception
  658. */
  659. public function addPrintArea($value, $index = -1)
  660. {
  661. return $this->setPrintArea($value, $index, self::SETPRINTRANGE_INSERT);
  662. }
  663. /**
  664. * Set print area
  665. *
  666. * @param int $column1 Column 1
  667. * @param int $row1 Row 1
  668. * @param int $column2 Column 2
  669. * @param int $row2 Row 2
  670. * @param int $index Identifier for a specific print area range allowing several ranges to be set
  671. * When the method is "O"verwrite, then a positive integer index will overwrite that indexed
  672. * entry in the print areas list; a negative index value will identify which entry to
  673. * overwrite working bacward through the print area to the list, with the last entry as -1.
  674. * Specifying an index value of 0, will overwrite <b>all</b> existing print ranges.
  675. * When the method is "I"nsert, then a positive index will insert after that indexed entry in
  676. * the print areas list, while a negative index will insert before the indexed entry.
  677. * Specifying an index value of 0, will always append the new print range at the end of the
  678. * list.
  679. * Print areas are numbered from 1
  680. * @param string $method Determines the method used when setting multiple print areas
  681. * Default behaviour, or the "O" method, overwrites existing print area
  682. * The "I" method, inserts the new print area before any specified index, or at the end of the list
  683. * @return PHPExcel_Worksheet_PageSetup
  684. * @throws PHPExcel_Exception
  685. */
  686. public function setPrintAreaByColumnAndRow($column1, $row1, $column2, $row2, $index = 0, $method = self::SETPRINTRANGE_OVERWRITE)
  687. {
  688. return $this->setPrintArea(
  689. PHPExcel_Cell::stringFromColumnIndex($column1) . $row1 . ':' . PHPExcel_Cell::stringFromColumnIndex($column2) . $row2,
  690. $index,
  691. $method
  692. );
  693. }
  694. /**
  695. * Add a new print area to the list of print areas
  696. *
  697. * @param int $column1 Start Column for the print area
  698. * @param int $row1 Start Row for the print area
  699. * @param int $column2 End Column for the print area
  700. * @param int $row2 End Row for the print area
  701. * @param int $index Identifier for a specific print area range allowing several ranges to be set
  702. * A positive index will insert after that indexed entry in the print areas list, while a
  703. * negative index will insert before the indexed entry.
  704. * Specifying an index value of 0, will always append the new print range at the end of the
  705. * list.
  706. * Print areas are numbered from 1
  707. * @return PHPExcel_Worksheet_PageSetup
  708. * @throws PHPExcel_Exception
  709. */
  710. public function addPrintAreaByColumnAndRow($column1, $row1, $column2, $row2, $index = -1)
  711. {
  712. return $this->setPrintArea(
  713. PHPExcel_Cell::stringFromColumnIndex($column1) . $row1 . ':' . PHPExcel_Cell::stringFromColumnIndex($column2) . $row2,
  714. $index,
  715. self::SETPRINTRANGE_INSERT
  716. );
  717. }
  718. /**
  719. * Get first page number
  720. *
  721. * @return int
  722. */
  723. public function getFirstPageNumber()
  724. {
  725. return $this->firstPageNumber;
  726. }
  727. /**
  728. * Set first page number
  729. *
  730. * @param int $value
  731. * @return PHPExcel_Worksheet_HeaderFooter
  732. */
  733. public function setFirstPageNumber($value = null)
  734. {
  735. $this->firstPageNumber = $value;
  736. return $this;
  737. }
  738. /**
  739. * Reset first page number
  740. *
  741. * @return PHPExcel_Worksheet_HeaderFooter
  742. */
  743. public function resetFirstPageNumber()
  744. {
  745. return $this->setFirstPageNumber(null);
  746. }
  747. /**
  748. * Implement PHP __clone to create a deep clone, not just a shallow copy.
  749. */
  750. public function __clone()
  751. {
  752. $vars = get_object_vars($this);
  753. foreach ($vars as $key => $value) {
  754. if (is_object($value)) {
  755. $this->$key = clone $value;
  756. } else {
  757. $this->$key = $value;
  758. }
  759. }
  760. }
  761. }