PageSetup.Class.php 24 KB

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