PluginProbe
TablePress – Tables in WordPress made easy / 3.4
TablePress – Tables in WordPress made easy v3.4
3.4 3.3.4 3.3.3 3.3.2 3.3.1 trunk 1.12 1.14 1.9.2 2.0.4 2.1.7 2.1.8 2.2 2.2.1 2.2.2 2.2.3 2.2.4 2.2.5 2.3 2.3.1 2.3.2 2.4 2.4.1 2.4.2 2.4.3 All 45 releases
tablepress / libraries / vendor / PhpSpreadsheet / Worksheet / PageSetup.php

PageSetup.php in TablePress – Tables in WordPress made easy 3.4, at libraries/vendor/PhpSpreadsheet/Worksheet/PageSetup.php

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