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.6.5, 2009-01-05
  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.      */
  288.     public function setPaperSize($pValue PHPExcel_Worksheet_PageSetup::PAPERSIZE_LETTER{
  289.         $this->_paperSize = $pValue;
  290.     }
  291.  
  292.     /**
  293.      * Get Orientation
  294.      *
  295.      * @return string 
  296.      */
  297.     public function getOrientation({
  298.         return $this->_orientation;
  299.     }
  300.  
  301.     /**
  302.      * Set Orientation
  303.      *
  304.      * @param string $pValue 
  305.      */
  306.     public function setOrientation($pValue PHPExcel_Worksheet_PageSetup::ORIENTATION_DEFAULT{
  307.         $this->_orientation = $pValue;
  308.     }
  309.  
  310.     /**
  311.      * Get Scale
  312.      *
  313.      * @return int? 
  314.      */
  315.     public function getScale({
  316.         return $this->_scale;
  317.     }
  318.  
  319.     /**
  320.      * Set Scale
  321.      *
  322.      * Print scaling. Valid values range from 10 to 400
  323.      * This setting is overridden when fitToWidth and/or fitToHeight are in use
  324.      *
  325.      * @param     int?     $pValue 
  326.      * @throws     Exception
  327.      */
  328.     public function setScale($pValue 100{
  329.         if (($pValue >= 10 && $pValue <= 400|| is_null($pValue)) {
  330.             $this->_scale = $pValue;
  331.         else {
  332.             throw new Exception("Valid scale is between 10 and 400.");
  333.         }
  334.     }
  335.  
  336.     /**
  337.      * Get Fit To Height
  338.      *
  339.      * @return int? 
  340.      */
  341.     public function getFitToHeight({
  342.         return $this->_fitToHeight;
  343.     }
  344.  
  345.     /**
  346.      * Set Fit To Height
  347.      *
  348.      * @param int? $pValue 
  349.      */
  350.     public function setFitToHeight($pValue 1{
  351.         if ($pValue != ''{
  352.             $this->_fitToHeight = $pValue;
  353.         }
  354.     }
  355.  
  356.     /**
  357.      * Get Fit To Width
  358.      *
  359.      * @return int? 
  360.      */
  361.     public function getFitToWidth({
  362.         return $this->_fitToWidth;
  363.     }
  364.  
  365.     /**
  366.      * Set Fit To Width
  367.      *
  368.      * @param int? $pValue 
  369.      */
  370.     public function setFitToWidth($pValue 1{
  371.         if ($pValue != ''{
  372.             $this->_fitToWidth = $pValue;
  373.         }
  374.     }
  375.  
  376.     /**
  377.      * Is Columns to repeat at left set?
  378.      *
  379.      * @return boolean 
  380.      */
  381.     public function isColumnsToRepeatAtLeftSet({
  382.         if (is_array($this->_columnsToRepeatAtLeft)) {
  383.             if ($this->_columnsToRepeatAtLeft[0!= '' && $this->_columnsToRepeatAtLeft[1!= ''{
  384.                 return true;
  385.             }
  386.         }
  387.  
  388.         return false;
  389.     }
  390.  
  391.     /**
  392.      * Get Columns to repeat at left
  393.      *
  394.      * @return array Containing start column and end column, empty array if option unset
  395.      */
  396.     public function getColumnsToRepeatAtLeft({
  397.         return $this->_columnsToRepeatAtLeft;
  398.     }
  399.  
  400.     /**
  401.      * Set Columns to repeat at left
  402.      *
  403.      * @param array $pValue Containing start column and end column, empty array if option unset
  404.      */
  405.     public function setColumnsToRepeatAtLeft($pValue null{
  406.         if (is_array($pValue)) {
  407.             $this->_columnsToRepeatAtLeft = $pValue;
  408.         }
  409.     }
  410.  
  411.     /**
  412.      * Set Columns to repeat at left by start and end
  413.      *
  414.      * @param string $pStart 
  415.      * @param string $pEnd 
  416.      */
  417.     public function setColumnsToRepeatAtLeftByStartAndEnd($pStart 'A'$pEnd 'A'{
  418.         $this->_columnsToRepeatAtLeft = array($pStart$pEnd);
  419.     }
  420.  
  421.     /**
  422.      * Is Rows to repeat at top set?
  423.      *
  424.      * @return boolean 
  425.      */
  426.     public function isRowsToRepeatAtTopSet({
  427.         if (is_array($this->_rowsToRepeatAtTop)) {
  428.             if ($this->_rowsToRepeatAtTop[0!= && $this->_rowsToRepeatAtTop[1!= 0{
  429.                 return true;
  430.             }
  431.         }
  432.  
  433.         return false;
  434.     }
  435.  
  436.     /**
  437.      * Get Rows to repeat at top
  438.      *
  439.      * @return array Containing start column and end column, empty array if option unset
  440.      */
  441.     public function getRowsToRepeatAtTop({
  442.         return $this->_rowsToRepeatAtTop;
  443.     }
  444.  
  445.     /**
  446.      * Set Rows to repeat at top
  447.      *
  448.      * @param array $pValue Containing start column and end column, empty array if option unset
  449.      */
  450.     public function setRowsToRepeatAtTop($pValue null{
  451.         if (is_array($pValue)) {
  452.             $this->_rowsToRepeatAtTop = $pValue;
  453.         }
  454.     }
  455.  
  456.     /**
  457.      * Set Rows to repeat at top by start and end
  458.      *
  459.      * @param int $pStart 
  460.      * @param int $pEnd 
  461.      */
  462.     public function setRowsToRepeatAtTopByStartAndEnd($pStart 1$pEnd 1{
  463.         $this->_rowsToRepeatAtTop = array($pStart$pEnd);
  464.     }
  465.  
  466.     /**
  467.      * Get center page horizontally
  468.      *
  469.      * @return bool 
  470.      */
  471.     public function getHorizontalCentered({
  472.         return $this->_horizontalCentered;
  473.     }
  474.  
  475.     /**
  476.      * Set center page horizontally
  477.      *
  478.      * @param bool $value 
  479.      */
  480.     public function setHorizontalCentered($value false{
  481.         $this->_horizontalCentered = $value;
  482.     }
  483.  
  484.     /**
  485.      * Get center page vertically
  486.      *
  487.      * @return bool 
  488.      */
  489.     public function getVerticalCentered({
  490.         return $this->_verticalCentered;
  491.     }
  492.  
  493.     /**
  494.      * Set center page vertically
  495.      *
  496.      * @param bool $value 
  497.      */
  498.     public function setVerticalCentered($value false{
  499.         $this->_verticalCentered = $value;
  500.     }
  501.  
  502.     /**
  503.      * Get print area
  504.      *
  505.      * @return string 
  506.      */
  507.     public function getPrintArea({
  508.         return $this->_printArea;
  509.     }
  510.  
  511.     /**
  512.      * Is print area set?
  513.      *
  514.      * @return boolean 
  515.      */
  516.     public function isPrintAreaSet({
  517.         return !is_null($this->_printArea);
  518.     }
  519.  
  520.     /**
  521.      * Set print area
  522.      *
  523.      * @param string $value 
  524.      * @throws Exception
  525.      */
  526.     public function setPrintArea($value{
  527.         if (strpos($value,':'=== false{
  528.             throw new Exception('Cell coordinate must be a range of cells.');
  529.         elseif (strpos($value,'$'!== false{
  530.             throw new Exception('Cell coordinate must not be absolute.');
  531.         else {
  532.             $this->_printArea = strtoupper($value);
  533.         }
  534.     }
  535.  
  536.     /**
  537.      * Set print area
  538.      *
  539.      * @param int $column1        Column 1
  540.      * @param int $row1            Row 1
  541.      * @param int $column2        Column 2
  542.      * @param int $row2            Row 2
  543.      */
  544.     public function setPrintAreaByColumnAndRow($column1$row1$column2$row2)
  545.     {
  546.         $this->setPrintArea(PHPExcel_Cell::stringFromColumnIndex($column1$row1 ':' PHPExcel_Cell::stringFromColumnIndex($column2$row2);
  547.     }
  548.  
  549.     /**
  550.      * Implement PHP __clone to create a deep clone, not just a shallow copy.
  551.      */
  552.     public function __clone({
  553.         $vars get_object_vars($this);
  554.         foreach ($vars as $key => $value{
  555.             if (is_object($value)) {
  556.                 $this->$key clone $value;
  557.             else {
  558.                 $this->$key $value;
  559.             }
  560.         }
  561.     }
  562. }

Documentation generated on Mon, 05 Jan 2009 20:38:15 +0100 by phpDocumentor 1.4.1