ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
PageSetup.php
Go to the documentation of this file.
1 <?php
2 
4 
7 
80 class PageSetup
81 {
82  // Paper size
83  const PAPERSIZE_LETTER = 1;
85  const PAPERSIZE_TABLOID = 3;
86  const PAPERSIZE_LEDGER = 4;
87  const PAPERSIZE_LEGAL = 5;
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;
100  const PAPERSIZE_NOTE = 18;
106  const PAPERSIZE_C = 24;
107  const PAPERSIZE_D = 25;
108  const PAPERSIZE_E = 26;
124  const PAPERSIZE_ISO_B4 = 42;
146  const PAPERSIZE_A2_PAPER = 64;
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
157  const SETPRINTRANGE_INSERT = 'I';
158 
159  const PAGEORDER_OVER_THEN_DOWN = 'overThenDown';
160  const PAGEORDER_DOWN_THEN_OVER = 'downThenOver';
161 
167  private $paperSize = self::PAPERSIZE_LETTER;
168 
174  private $orientation = self::ORIENTATION_DEFAULT;
175 
184  private $scale = 100;
185 
192  private $fitToPage = false;
193 
200  private $fitToHeight = 1;
201 
208  private $fitToWidth = 1;
209 
215  private $columnsToRepeatAtLeft = ['', ''];
216 
222  private $rowsToRepeatAtTop = [0, 0];
223 
229  private $horizontalCentered = false;
230 
236  private $verticalCentered = false;
237 
243  private $printArea;
244 
251 
252  private $pageOrder = self::PAGEORDER_DOWN_THEN_OVER;
253 
257  public function __construct()
258  {
259  }
260 
266  public function getPaperSize()
267  {
268  return $this->paperSize;
269  }
270 
278  public function setPaperSize($pValue)
279  {
280  $this->paperSize = $pValue;
281 
282  return $this;
283  }
284 
290  public function getOrientation()
291  {
292  return $this->orientation;
293  }
294 
302  public function setOrientation($pValue)
303  {
304  $this->orientation = $pValue;
305 
306  return $this;
307  }
308 
314  public function getScale()
315  {
316  return $this->scale;
317  }
318 
329  public function setScale($pValue, $pUpdate = true)
330  {
331  // Microsoft Office Excel 2007 only allows setting a scale between 10 and 400 via the user interface,
332  // but it is apparently still able to handle any scale >= 0, where 0 results in 100
333  if (($pValue >= 0) || $pValue === null) {
334  $this->scale = $pValue;
335  if ($pUpdate) {
336  $this->fitToPage = false;
337  }
338  } else {
339  throw new PhpSpreadsheetException('Scale must not be negative');
340  }
341 
342  return $this;
343  }
344 
350  public function getFitToPage()
351  {
352  return $this->fitToPage;
353  }
354 
362  public function setFitToPage($pValue)
363  {
364  $this->fitToPage = $pValue;
365 
366  return $this;
367  }
368 
374  public function getFitToHeight()
375  {
376  return $this->fitToHeight;
377  }
378 
387  public function setFitToHeight($pValue, $pUpdate = true)
388  {
389  $this->fitToHeight = $pValue;
390  if ($pUpdate) {
391  $this->fitToPage = true;
392  }
393 
394  return $this;
395  }
396 
402  public function getFitToWidth()
403  {
404  return $this->fitToWidth;
405  }
406 
415  public function setFitToWidth($pValue, $pUpdate = true)
416  {
417  $this->fitToWidth = $pValue;
418  if ($pUpdate) {
419  $this->fitToPage = true;
420  }
421 
422  return $this;
423  }
424 
430  public function isColumnsToRepeatAtLeftSet()
431  {
432  if (is_array($this->columnsToRepeatAtLeft)) {
433  if ($this->columnsToRepeatAtLeft[0] != '' && $this->columnsToRepeatAtLeft[1] != '') {
434  return true;
435  }
436  }
437 
438  return false;
439  }
440 
446  public function getColumnsToRepeatAtLeft()
447  {
449  }
450 
458  public function setColumnsToRepeatAtLeft(array $pValue)
459  {
460  $this->columnsToRepeatAtLeft = $pValue;
461 
462  return $this;
463  }
464 
473  public function setColumnsToRepeatAtLeftByStartAndEnd($pStart, $pEnd)
474  {
475  $this->columnsToRepeatAtLeft = [$pStart, $pEnd];
476 
477  return $this;
478  }
479 
485  public function isRowsToRepeatAtTopSet()
486  {
487  if (is_array($this->rowsToRepeatAtTop)) {
488  if ($this->rowsToRepeatAtTop[0] != 0 && $this->rowsToRepeatAtTop[1] != 0) {
489  return true;
490  }
491  }
492 
493  return false;
494  }
495 
501  public function getRowsToRepeatAtTop()
502  {
504  }
505 
513  public function setRowsToRepeatAtTop(array $pValue)
514  {
515  $this->rowsToRepeatAtTop = $pValue;
516 
517  return $this;
518  }
519 
528  public function setRowsToRepeatAtTopByStartAndEnd($pStart, $pEnd)
529  {
530  $this->rowsToRepeatAtTop = [$pStart, $pEnd];
531 
532  return $this;
533  }
534 
540  public function getHorizontalCentered()
541  {
543  }
544 
552  public function setHorizontalCentered($value)
553  {
554  $this->horizontalCentered = $value;
555 
556  return $this;
557  }
558 
564  public function getVerticalCentered()
565  {
567  }
568 
576  public function setVerticalCentered($value)
577  {
578  $this->verticalCentered = $value;
579 
580  return $this;
581  }
582 
593  public function getPrintArea($index = 0)
594  {
595  if ($index == 0) {
596  return $this->printArea;
597  }
598  $printAreas = explode(',', $this->printArea);
599  if (isset($printAreas[$index - 1])) {
600  return $printAreas[$index - 1];
601  }
602 
603  throw new PhpSpreadsheetException('Requested Print Area does not exist');
604  }
605 
616  public function isPrintAreaSet($index = 0)
617  {
618  if ($index == 0) {
619  return $this->printArea !== null;
620  }
621  $printAreas = explode(',', $this->printArea);
622 
623  return isset($printAreas[$index - 1]);
624  }
625 
636  public function clearPrintArea($index = 0)
637  {
638  if ($index == 0) {
639  $this->printArea = null;
640  } else {
641  $printAreas = explode(',', $this->printArea);
642  if (isset($printAreas[$index - 1])) {
643  unset($printAreas[$index - 1]);
644  $this->printArea = implode(',', $printAreas);
645  }
646  }
647 
648  return $this;
649  }
650 
671  public function setPrintArea($value, $index = 0, $method = self::SETPRINTRANGE_OVERWRITE)
672  {
673  if (strpos($value, '!') !== false) {
674  throw new PhpSpreadsheetException('Cell coordinate must not specify a worksheet.');
675  } elseif (strpos($value, ':') === false) {
676  throw new PhpSpreadsheetException('Cell coordinate must be a range of cells.');
677  } elseif (strpos($value, '$') !== false) {
678  throw new PhpSpreadsheetException('Cell coordinate must not be absolute.');
679  }
680  $value = strtoupper($value);
681  if (!$this->printArea) {
682  $index = 0;
683  }
684 
685  if ($method == self::SETPRINTRANGE_OVERWRITE) {
686  if ($index == 0) {
687  $this->printArea = $value;
688  } else {
689  $printAreas = explode(',', $this->printArea);
690  if ($index < 0) {
691  $index = count($printAreas) - abs($index) + 1;
692  }
693  if (($index <= 0) || ($index > count($printAreas))) {
694  throw new PhpSpreadsheetException('Invalid index for setting print range.');
695  }
696  $printAreas[$index - 1] = $value;
697  $this->printArea = implode(',', $printAreas);
698  }
699  } elseif ($method == self::SETPRINTRANGE_INSERT) {
700  if ($index == 0) {
701  $this->printArea = $this->printArea ? ($this->printArea . ',' . $value) : $value;
702  } else {
703  $printAreas = explode(',', $this->printArea);
704  if ($index < 0) {
705  $index = abs($index) - 1;
706  }
707  if ($index > count($printAreas)) {
708  throw new PhpSpreadsheetException('Invalid index for setting print range.');
709  }
710  $printAreas = array_merge(array_slice($printAreas, 0, $index), [$value], array_slice($printAreas, $index));
711  $this->printArea = implode(',', $printAreas);
712  }
713  } else {
714  throw new PhpSpreadsheetException('Invalid method for setting print range.');
715  }
716 
717  return $this;
718  }
719 
733  public function addPrintArea($value, $index = -1)
734  {
735  return $this->setPrintArea($value, $index, self::SETPRINTRANGE_INSERT);
736  }
737 
761  public function setPrintAreaByColumnAndRow($column1, $row1, $column2, $row2, $index = 0, $method = self::SETPRINTRANGE_OVERWRITE)
762  {
763  return $this->setPrintArea(
764  Coordinate::stringFromColumnIndex($column1) . $row1 . ':' . Coordinate::stringFromColumnIndex($column2) . $row2,
765  $index,
766  $method
767  );
768  }
769 
786  public function addPrintAreaByColumnAndRow($column1, $row1, $column2, $row2, $index = -1)
787  {
788  return $this->setPrintArea(
789  Coordinate::stringFromColumnIndex($column1) . $row1 . ':' . Coordinate::stringFromColumnIndex($column2) . $row2,
790  $index,
791  self::SETPRINTRANGE_INSERT
792  );
793  }
794 
800  public function getFirstPageNumber()
801  {
802  return $this->firstPageNumber;
803  }
804 
812  public function setFirstPageNumber($value)
813  {
814  $this->firstPageNumber = $value;
815 
816  return $this;
817  }
818 
824  public function resetFirstPageNumber()
825  {
826  return $this->setFirstPageNumber(null);
827  }
828 
829  public function getPageOrder(): string
830  {
831  return $this->pageOrder;
832  }
833 
834  public function setPageOrder(?string $pageOrder): self
835  {
836  if ($pageOrder === null || $pageOrder === self::PAGEORDER_DOWN_THEN_OVER || $pageOrder === self::PAGEORDER_OVER_THEN_DOWN) {
837  $this->pageOrder = $pageOrder ?? self::PAGEORDER_DOWN_THEN_OVER;
838  }
839 
840  return $this;
841  }
842 
846  public function __clone()
847  {
848  $vars = get_object_vars($this);
849  foreach ($vars as $key => $value) {
850  if (is_object($value)) {
851  $this->$key = clone $value;
852  } else {
853  $this->$key = $value;
854  }
855  }
856  }
857 }
setFirstPageNumber($value)
Set first page number.
Definition: PageSetup.php:812
isPrintAreaSet($index=0)
Is print area set?
Definition: PageSetup.php:616
setColumnsToRepeatAtLeftByStartAndEnd($pStart, $pEnd)
Set Columns to repeat at left by start and end.
Definition: PageSetup.php:473
$index
Definition: metadata.php:60
getRowsToRepeatAtTop()
Get Rows to repeat at top.
Definition: PageSetup.php:501
addPrintAreaByColumnAndRow($column1, $row1, $column2, $row2, $index=-1)
Add a new print area to the list of print areas.
Definition: PageSetup.php:786
clearPrintArea($index=0)
Clear a print area.
Definition: PageSetup.php:636
setFitToHeight($pValue, $pUpdate=true)
Set Fit To Height.
Definition: PageSetup.php:387
resetFirstPageNumber()
Reset first page number.
Definition: PageSetup.php:824
addPrintArea($value, $index=-1)
Add a new print area (e.g.
Definition: PageSetup.php:733
__construct()
Create a new PageSetup.
Definition: PageSetup.php:257
setRowsToRepeatAtTop(array $pValue)
Set Rows to repeat at top.
Definition: PageSetup.php:513
isRowsToRepeatAtTopSet()
Is Rows to repeat at top set?
Definition: PageSetup.php:485
getColumnsToRepeatAtLeft()
Get Columns to repeat at left.
Definition: PageSetup.php:446
getHorizontalCentered()
Get center page horizontally.
Definition: PageSetup.php:540
Paper size taken from Office Open XML Part 4 - Markup Language Reference, page 1988:.
Definition: PageSetup.php:80
setRowsToRepeatAtTopByStartAndEnd($pStart, $pEnd)
Set Rows to repeat at top by start and end.
Definition: PageSetup.php:528
setPrintArea($value, $index=0, $method=self::SETPRINTRANGE_OVERWRITE)
Set print area.
Definition: PageSetup.php:671
getPrintArea($index=0)
Get print area.
Definition: PageSetup.php:593
isColumnsToRepeatAtLeftSet()
Is Columns to repeat at left set?
Definition: PageSetup.php:430
__clone()
Implement PHP __clone to create a deep clone, not just a shallow copy.
Definition: PageSetup.php:846
getVerticalCentered()
Get center page vertically.
Definition: PageSetup.php:564
getFirstPageNumber()
Get first page number.
Definition: PageSetup.php:800
setScale($pValue, $pUpdate=true)
Set Scale.
Definition: PageSetup.php:329
setColumnsToRepeatAtLeft(array $pValue)
Set Columns to repeat at left.
Definition: PageSetup.php:458
setFitToWidth($pValue, $pUpdate=true)
Set Fit To Width.
Definition: PageSetup.php:415
setHorizontalCentered($value)
Set center page horizontally.
Definition: PageSetup.php:552
$key
Definition: croninfo.php:18
setPrintAreaByColumnAndRow($column1, $row1, $column2, $row2, $index=0, $method=self::SETPRINTRANGE_OVERWRITE)
Set print area.
Definition: PageSetup.php:761
static stringFromColumnIndex($columnIndex)
String from column index.
Definition: Coordinate.php:313
setVerticalCentered($value)
Set center page vertically.
Definition: PageSetup.php:576
setOrientation($pValue)
Set Orientation.
Definition: PageSetup.php:302
setFitToPage($pValue)
Set Fit To Page.
Definition: PageSetup.php:362