PHPExcel_Worksheet
[ class tree: PHPExcel_Worksheet ] [ index: PHPExcel_Worksheet ] [ all elements ]

Source for file PageSetup.php

Documentation is available at PageSetup.php

  1. <?php
  2. /**
  3.  * PHPExcel
  4.  *
  5.  * Copyright (c) 2006 - 2009 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 - 2009 PHPExcel (http://www.codeplex.com/PHPExcel)
  24.  * @license    http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt    LGPL
  25.  * @version    1.7.0, 2009-08-10
  26.  */
  27.  
  28.  
  29. /**
  30.  * PHPExcel_Worksheet_PageSetup
  31.  *
  32.  * <code>
  33.  * Paper size taken from Office Open XML Part 4 - Markup Language Reference, page 1988:
  34.  *
  35.  * 1 = Letter paper (8.5 in. by 11 in.)
  36.  * 2 = Letter small paper (8.5 in. by 11 in.)
  37.  * 3 = Tabloid paper (11 in. by 17 in.)
  38.  * 4 = Ledger paper (17 in. by 11 in.)
  39.  * 5 = Legal paper (8.5 in. by 14 in.)
  40.  * 6 = Statement paper (5.5 in. by 8.5 in.)
  41.  * 7 = Executive paper (7.25 in. by 10.5 in.)
  42.  * 8 = A3 paper (297 mm by 420 mm)
  43.  * 9 = A4 paper (210 mm by 297 mm)
  44.  * 10 = A4 small paper (210 mm by 297 mm)
  45.  * 11 = A5 paper (148 mm by 210 mm)
  46.  * 12 = B4 paper (250 mm by 353 mm)
  47.  * 13 = B5 paper (176 mm by 250 mm)
  48.  * 14 = Folio paper (8.5 in. by 13 in.)
  49.  * 15 = Quarto paper (215 mm by 275 mm)
  50.  * 16 = Standard paper (10 in. by 14 in.)
  51.  * 17 = Standard paper (11 in. by 17 in.)
  52.  * 18 = Note paper (8.5 in. by 11 in.)
  53.  * 19 = #9 envelope (3.875 in. by 8.875 in.)
  54.  * 20 = #10 envelope (4.125 in. by 9.5 in.)
  55.  * 21 = #11 envelope (4.5 in. by 10.375 in.)
  56.  * 22 = #12 envelope (4.75 in. by 11 in.)
  57.  * 23 = #14 envelope (5 in. by 11.5 in.)
  58.  * 24 = C paper (17 in. by 22 in.)
  59.  * 25 = D paper (22 in. by 34 in.)
  60.  * 26 = E paper (34 in. by 44 in.)
  61.  * 27 = DL envelope (110 mm by 220 mm)
  62.  * 28 = C5 envelope (162 mm by 229 mm)
  63.  * 29 = C3 envelope (324 mm by 458 mm)
  64.  * 30 = C4 envelope (229 mm by 324 mm)
  65.  * 31 = C6 envelope (114 mm by 162 mm)
  66.  * 32 = C65 envelope (114 mm by 229 mm)
  67.  * 33 = B4 envelope (250 mm by 353 mm)
  68.  * 34 = B5 envelope (176 mm by 250 mm)
  69.  * 35 = B6 envelope (176 mm by 125 mm)
  70.  * 36 = Italy envelope (110 mm by 230 mm)
  71.  * 37 = Monarch envelope (3.875 in. by 7.5 in.).
  72.  * 38 = 6 3/4 envelope (3.625 in. by 6.5 in.)
  73.  * 39 = US standard fanfold (14.875 in. by 11 in.)
  74.  * 40 = German standard fanfold (8.5 in. by 12 in.)
  75.  * 41 = German legal fanfold (8.5 in. by 13 in.)
  76.  * 42 = ISO B4 (250 mm by 353 mm)
  77.  * 43 = Japanese double postcard (200 mm by 148 mm)
  78.  * 44 = Standard paper (9 in. by 11 in.)
  79.  * 45 = Standard paper (10 in. by 11 in.)
  80.  * 46 = Standard paper (15 in. by 11 in.)
  81.  * 47 = Invite envelope (220 mm by 220 mm)
  82.  * 50 = Letter extra paper (9.275 in. by 12 in.)
  83.  * 51 = Legal extra paper (9.275 in. by 15 in.)
  84.  * 52 = Tabloid extra paper (11.69 in. by 18 in.)
  85.  * 53 = A4 extra paper (236 mm by 322 mm)
  86.  * 54 = Letter transverse paper (8.275 in. by 11 in.)
  87.  * 55 = A4 transverse paper (210 mm by 297 mm)
  88.  * 56 = Letter extra transverse paper (9.275 in. by 12 in.)
  89.  * 57 = SuperA/SuperA/A4 paper (227 mm by 356 mm)
  90.  * 58 = SuperB/SuperB/A3 paper (305 mm by 487 mm)
  91.  * 59 = Letter plus paper (8.5 in. by 12.69 in.)
  92.  * 60 = A4 plus paper (210 mm by 330 mm)
  93.  * 61 = A5 transverse paper (148 mm by 210 mm)
  94.  * 62 = JIS B5 transverse paper (182 mm by 257 mm)
  95.  * 63 = A3 extra paper (322 mm by 445 mm)
  96.  * 64 = A5 extra paper (174 mm by 235 mm)
  97.  * 65 = ISO B5 extra paper (201 mm by 276 mm)
  98.  * 66 = A2 paper (420 mm by 594 mm)
  99.  * 67 = A3 transverse paper (297 mm by 420 mm)
  100.  * 68 = A3 extra transverse paper (322 mm by 445 mm)
  101.  * </code>
  102.  *
  103.  * @category   PHPExcel
  104.  * @package    PHPExcel_Worksheet
  105.  * @copyright  Copyright (c) 2006 - 2009 PHPExcel (http://www.codeplex.com/PHPExcel)
  106.  */
  107. {
  108.     /* Paper size */
  109.     const PAPERSIZE_LETTER                            1;
  110.     const PAPERSIZE_LETTER_SMALL                    2;
  111.     const PAPERSIZE_TABLOID                            3;
  112.     const PAPERSIZE_LEDGER                            4;
  113.     const PAPERSIZE_LEGAL                            5;
  114.     const PAPERSIZE_STATEMENT                        6;
  115.     const PAPERSIZE_EXECUTIVE                        7;
  116.     const PAPERSIZE_A3                                8;
  117.     const PAPERSIZE_A4                                9;
  118.     const PAPERSIZE_A4_SMALL                        10;
  119.     const PAPERSIZE_A5                                11;
  120.     const PAPERSIZE_B4                                12;
  121.     const PAPERSIZE_B5                                13;
  122.     const PAPERSIZE_FOLIO                            14;
  123.     const PAPERSIZE_QUARTO                            15;
  124.     const PAPERSIZE_STANDARD_1                        16;
  125.     const PAPERSIZE_STANDARD_2                        17;
  126.     const PAPERSIZE_NOTE                            18;
  127.     const PAPERSIZE_NO9_ENVELOPE                    19;
  128.     const PAPERSIZE_NO10_ENVELOPE                    20;
  129.     const PAPERSIZE_NO11_ENVELOPE                    21;
  130.     const PAPERSIZE_NO12_ENVELOPE                    22;
  131.     const PAPERSIZE_NO14_ENVELOPE                    23;
  132.     const PAPERSIZE_C                                24;
  133.     const PAPERSIZE_D                                25;
  134.     const PAPERSIZE_E                                26;
  135.     const PAPERSIZE_DL_ENVELOPE                        27;
  136.     const PAPERSIZE_C5_ENVELOPE                        28;
  137.     const PAPERSIZE_C3_ENVELOPE                        29;
  138.     const PAPERSIZE_C4_ENVELOPE                        30;
  139.     const PAPERSIZE_C6_ENVELOPE                        31;
  140.     const PAPERSIZE_C65_ENVELOPE                    32;
  141.     const PAPERSIZE_B4_ENVELOPE                        33;
  142.     const PAPERSIZE_B5_ENVELOPE                        34;
  143.     const PAPERSIZE_B6_ENVELOPE                        35;
  144.     const PAPERSIZE_ITALY_ENVELOPE                    36;
  145.     const PAPERSIZE_MONARCH_ENVELOPE                37;
  146.     const PAPERSIZE_6_3_4_ENVELOPE                    38;
  147.     const PAPERSIZE_US_STANDARD_FANFOLD                39;
  148.     const PAPERSIZE_GERMAN_STANDARD_FANFOLD            40;
  149.     const PAPERSIZE_GERMAN_LEGAL_FANFOLD            41;
  150.     const PAPERSIZE_ISO_B4                            42;
  151.     const PAPERSIZE_JAPANESE_DOUBLE_POSTCARD        43;
  152.     const PAPERSIZE_STANDARD_PAPER_1                44;
  153.     const PAPERSIZE_STANDARD_PAPER_2                45;
  154.     const PAPERSIZE_STANDARD_PAPER_3                46;
  155.     const PAPERSIZE_INVITE_ENVELOPE                    47;
  156.     const PAPERSIZE_LETTER_EXTRA_PAPER                48;
  157.     const PAPERSIZE_LEGAL_EXTRA_PAPER                49;
  158.     const PAPERSIZE_TABLOID_EXTRA_PAPER                50;
  159.     const PAPERSIZE_A4_EXTRA_PAPER                    51;
  160.     const PAPERSIZE_LETTER_TRANSVERSE_PAPER            52;
  161.     const PAPERSIZE_A4_TRANSVERSE_PAPER                53;
  162.     const PAPERSIZE_LETTER_EXTRA_TRANSVERSE_PAPER    54;
  163.     const PAPERSIZE_SUPERA_SUPERA_A4_PAPER            55;
  164.     const PAPERSIZE_SUPERB_SUPERB_A3_PAPER            56;
  165.     const PAPERSIZE_LETTER_PLUS_PAPER                57;
  166.     const PAPERSIZE_A4_PLUS_PAPER                    58;
  167.     const PAPERSIZE_A5_TRANSVERSE_PAPER                59;
  168.     const PAPERSIZE_JIS_B5_TRANSVERSE_PAPER            60;
  169.     const PAPERSIZE_A3_EXTRA_PAPER                    61;
  170.     const PAPERSIZE_A5_EXTRA_PAPER                    62;
  171.     const PAPERSIZE_ISO_B5_EXTRA_PAPER                63;
  172.     const PAPERSIZE_A2_PAPER                        64;
  173.     const PAPERSIZE_A3_TRANSVERSE_PAPER                65;
  174.     const PAPERSIZE_A3_EXTRA_TRANSVERSE_PAPER        66;
  175.  
  176.     /* Page orientation */
  177.     const ORIENTATION_DEFAULT    'default';
  178.     const ORIENTATION_LANDSCAPE    'landscape';
  179.     const ORIENTATION_PORTRAIT    'portrait';
  180.  
  181.     /**
  182.      * Paper size
  183.      *
  184.      * @var int 
  185.      */
  186.     private $_paperSize;
  187.  
  188.     /**
  189.      * Orientation
  190.      *
  191.      * @var string 
  192.      */
  193.     private $_orientation;
  194.  
  195.     /**
  196.      * Scale (Print Scale)
  197.      *
  198.      * Print scaling. Valid values range from 10 to 400
  199.      * This setting is overridden when fitToWidth and/or fitToHeight are in use
  200.      *
  201.      * @var int? 
  202.      */
  203.     private $_scale;
  204.  
  205.     /**
  206.       * Fit To Height
  207.       * Number of vertical pages to fit on
  208.       *
  209.       * @var int? 
  210.       */
  211.     private $_fitToHeight;
  212.  
  213.     /**
  214.       * Fit To Width
  215.       * Number of horizontal pages to fit on
  216.       *
  217.       * @var int? 
  218.       */
  219.     private $_fitToWidth;
  220.  
  221.     /**
  222.      * Columns to repeat at left
  223.      *
  224.      * @var array Containing start column and end column, empty array if option unset
  225.      */
  226.     private $_columnsToRepeatAtLeft = array('''');
  227.  
  228.     /**
  229.      * Rows to repeat at top
  230.      *
  231.      * @var array Containing start row number and end row number, empty array if option unset
  232.      */
  233.     private $_rowsToRepeatAtTop = array(00);
  234.  
  235.     /**
  236.      * Center page horizontally
  237.      *
  238.      * @var boolean 
  239.      */
  240.     private $_horizontalCentered = false;
  241.  
  242.     /**
  243.      * Center page vertically
  244.      *
  245.      * @var boolean 
  246.      */
  247.     private $_verticalCentered = false;
  248.  
  249.     /**
  250.      * Print area
  251.      *
  252.      * @var string 
  253.      */
  254.     private $_printArea = null;
  255.  
  256.     /**
  257.      * Create a new PHPExcel_Worksheet_PageSetup
  258.      */
  259.     public function __construct()
  260.     {
  261.         // Initialise values
  262.         $this->_paperSize                 = PHPExcel_Worksheet_PageSetup::PAPERSIZE_LETTER;
  263.         $this->_orientation                = PHPExcel_Worksheet_PageSetup::ORIENTATION_DEFAULT;
  264.         $this->_scale                    = null;
  265.         $this->_fitToHeight                = null;
  266.         $this->_fitToWidth                = null;
  267.         $this->_columnsToRepeatAtLeft     = array('''');
  268.         $this->_rowsToRepeatAtTop        = array(00);
  269.         $this->_horizontalCentered        = false;
  270.         $this->_verticalCentered        = false;
  271.         $this->_printArea                = null;
  272.     }
  273.  
  274.     /**
  275.      * Get Paper Size
  276.      *
  277.      * @return int 
  278.      */
  279.     public function getPaperSize({
  280.         return $this->_paperSize;
  281.     }
  282.  
  283.     /**
  284.      * Set Paper Size
  285.      *
  286.      * @param int $pValue 
  287.      * @return PHPExcel_Worksheet_PageSetup 
  288.      */
  289.     public function setPaperSize($pValue PHPExcel_Worksheet_PageSetup::PAPERSIZE_LETTER{
  290.         $this->_paperSize = $pValue;
  291.         return $this;
  292.     }
  293.  
  294.     /**
  295.      * Get Orientation
  296.      *
  297.      * @return string 
  298.      */
  299.     public function getOrientation({
  300.         return $this->_orientation;
  301.     }
  302.  
  303.     /**
  304.      * Set Orientation
  305.      *
  306.      * @param string $pValue 
  307.      * @return PHPExcel_Worksheet_PageSetup 
  308.      */
  309.     public function setOrientation($pValue PHPExcel_Worksheet_PageSetup::ORIENTATION_DEFAULT{
  310.         $this->_orientation = $pValue;
  311.         return $this;
  312.     }
  313.  
  314.     /**
  315.      * Get Scale
  316.      *
  317.      * @return int? 
  318.      */
  319.     public function getScale({
  320.         return $this->_scale;
  321.     }
  322.  
  323.     /**
  324.      * Set Scale
  325.      *
  326.      * Print scaling. Valid values range from 10 to 400
  327.      * This setting is overridden when fitToWidth and/or fitToHeight are in use
  328.      *
  329.      * @param     int?     $pValue 
  330.      * @throws     Exception
  331.      * @return PHPExcel_Worksheet_PageSetup 
  332.      */
  333.     public function setScale($pValue 100{
  334.         // Microsoft Office Excel 2007 only allows setting a scale between 10 and 400 via the user interface,
  335.         // but it is apparently still able to handle any scale >= 0, where 0 results in 100
  336.         if (($pValue >= 0|| is_null($pValue)) {
  337.             $this->_scale = $pValue;
  338.         else {
  339.             throw new Exception("Scale must not be negative");
  340.         }
  341.         return $this;
  342.     }
  343.  
  344.     /**
  345.      * Get Fit To Height
  346.      *
  347.      * @return int? 
  348.      */
  349.     public function getFitToHeight({
  350.         return $this->_fitToHeight;
  351.     }
  352.  
  353.     /**
  354.      * Set Fit To Height
  355.      *
  356.      * @param int? $pValue 
  357.      * @return PHPExcel_Worksheet_PageSetup 
  358.      */
  359.     public function setFitToHeight($pValue 1{
  360.         if ($pValue != ''{
  361.             $this->_fitToHeight = $pValue;
  362.         }
  363.         return $this;
  364.     }
  365.  
  366.     /**
  367.      * Get Fit To Width
  368.      *
  369.      * @return int? 
  370.      */
  371.     public function getFitToWidth({
  372.         return $this->_fitToWidth;
  373.     }
  374.  
  375.     /**
  376.      * Set Fit To Width
  377.      *
  378.      * @param int? $pValue 
  379.      * @return PHPExcel_Worksheet_PageSetup 
  380.      */
  381.     public function setFitToWidth($pValue 1{
  382.         if ($pValue != ''{
  383.             $this->_fitToWidth = $pValue;
  384.         }
  385.         return $this;
  386.     }
  387.  
  388.     /**
  389.      * Is Columns to repeat at left set?
  390.      *
  391.      * @return boolean 
  392.      */
  393.     public function isColumnsToRepeatAtLeftSet({
  394.         if (is_array($this->_columnsToRepeatAtLeft)) {
  395.             if ($this->_columnsToRepeatAtLeft[0!= '' && $this->_columnsToRepeatAtLeft[1!= ''{
  396.                 return true;
  397.             }
  398.         }
  399.  
  400.         return false;
  401.     }
  402.  
  403.     /**
  404.      * Get Columns to repeat at left
  405.      *
  406.      * @return array Containing start column and end column, empty array if option unset
  407.      */
  408.     public function getColumnsToRepeatAtLeft({
  409.         return $this->_columnsToRepeatAtLeft;
  410.     }
  411.  
  412.     /**
  413.      * Set Columns to repeat at left
  414.      *
  415.      * @param array $pValue Containing start column and end column, empty array if option unset
  416.      * @return PHPExcel_Worksheet_PageSetup 
  417.      */
  418.     public function setColumnsToRepeatAtLeft($pValue null{
  419.         if (is_array($pValue)) {
  420.             $this->_columnsToRepeatAtLeft = $pValue;
  421.         }
  422.         return $this;
  423.     }
  424.  
  425.     /**
  426.      * Set Columns to repeat at left by start and end
  427.      *
  428.      * @param string $pStart 
  429.      * @param string $pEnd 
  430.      * @return PHPExcel_Worksheet_PageSetup 
  431.      */
  432.     public function setColumnsToRepeatAtLeftByStartAndEnd($pStart 'A'$pEnd 'A'{
  433.         $this->_columnsToRepeatAtLeft = array($pStart$pEnd);
  434.         return $this;
  435.     }
  436.  
  437.     /**
  438.      * Is Rows to repeat at top set?
  439.      *
  440.      * @return boolean 
  441.      */
  442.     public function isRowsToRepeatAtTopSet({
  443.         if (is_array($this->_rowsToRepeatAtTop)) {
  444.             if ($this->_rowsToRepeatAtTop[0!= && $this->_rowsToRepeatAtTop[1!= 0{
  445.                 return true;
  446.             }
  447.         }
  448.  
  449.         return false;
  450.     }
  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.     /**
  462.      * Set Rows to repeat at top
  463.      *
  464.      * @param array $pValue Containing start column and end column, empty array if option unset
  465.      * @return PHPExcel_Worksheet_PageSetup 
  466.      */
  467.     public function setRowsToRepeatAtTop($pValue null{
  468.         if (is_array($pValue)) {
  469.             $this->_rowsToRepeatAtTop = $pValue;
  470.         }
  471.         return $this;
  472.     }
  473.  
  474.     /**
  475.      * Set Rows to repeat at top by start and end
  476.      *
  477.      * @param int $pStart 
  478.      * @param int $pEnd 
  479.      * @return PHPExcel_Worksheet_PageSetup 
  480.      */
  481.     public function setRowsToRepeatAtTopByStartAndEnd($pStart 1$pEnd 1{
  482.         $this->_rowsToRepeatAtTop = array($pStart$pEnd);
  483.         return $this;
  484.     }
  485.  
  486.     /**
  487.      * Get center page horizontally
  488.      *
  489.      * @return bool 
  490.      */
  491.     public function getHorizontalCentered({
  492.         return $this->_horizontalCentered;
  493.     }
  494.  
  495.     /**
  496.      * Set center page horizontally
  497.      *
  498.      * @param bool $value 
  499.      * @return PHPExcel_Worksheet_PageSetup 
  500.      */
  501.     public function setHorizontalCentered($value false{
  502.         $this->_horizontalCentered = $value;
  503.         return $this;
  504.     }
  505.  
  506.     /**
  507.      * Get center page vertically
  508.      *
  509.      * @return bool 
  510.      */
  511.     public function getVerticalCentered({
  512.         return $this->_verticalCentered;
  513.     }
  514.  
  515.     /**
  516.      * Set center page vertically
  517.      *
  518.      * @param bool $value 
  519.      * @return PHPExcel_Worksheet_PageSetup 
  520.      */
  521.     public function setVerticalCentered($value false{
  522.         $this->_verticalCentered = $value;
  523.         return $this;
  524.     }
  525.  
  526.     /**
  527.      * Get print area
  528.      *
  529.      * @return string 
  530.      */
  531.     public function getPrintArea({
  532.         return $this->_printArea;
  533.     }
  534.  
  535.     /**
  536.      * Is print area set?
  537.      *
  538.      * @return boolean 
  539.      */
  540.     public function isPrintAreaSet({
  541.         return !is_null($this->_printArea);
  542.     }
  543.  
  544.     /**
  545.      * Set print area
  546.      *
  547.      * @param string $value 
  548.      * @throws Exception
  549.      * @return PHPExcel_Worksheet_PageSetup 
  550.      */
  551.     public function setPrintArea($value{
  552.         if (strpos($value,':'=== false{
  553.             throw new Exception('Cell coordinate must be a range of cells.');
  554.         elseif (strpos($value,'$'!== false{
  555.             throw new Exception('Cell coordinate must not be absolute.');
  556.         else {
  557.             $this->_printArea = strtoupper($value);
  558.         }
  559.         return $this;
  560.     }
  561.  
  562.     /**
  563.      * Set print area
  564.      *
  565.      * @param int $column1        Column 1
  566.      * @param int $row1            Row 1
  567.      * @param int $column2        Column 2
  568.      * @param int $row2            Row 2
  569.      * @return PHPExcel_Worksheet_PageSetup 
  570.      */
  571.     public function setPrintAreaByColumnAndRow($column1$row1$column2$row2)
  572.     {
  573.         return $this->setPrintArea(PHPExcel_Cell::stringFromColumnIndex($column1$row1 ':' PHPExcel_Cell::stringFromColumnIndex($column2$row2);
  574.     }
  575.  
  576.     /**
  577.      * Implement PHP __clone to create a deep clone, not just a shallow copy.
  578.      */
  579.     public function __clone({
  580.         $vars get_object_vars($this);
  581.         foreach ($vars as $key => $value{
  582.             if (is_object($value)) {
  583.                 $this->$key clone $value;
  584.             else {
  585.                 $this->$key $value;
  586.             }
  587.         }
  588.     }
  589. }

Documentation generated on Mon, 10 Aug 2009 08:07:03 +0200 by phpDocumentor 1.4.1