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

Source for file HeaderFooter.php

Documentation is available at HeaderFooter.php

  1. <?php
  2. /**
  3.  * PHPExcel
  4.  *
  5.  * Copyright (c) 2006 - 2011 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 - 2011 PHPExcel (http://www.codeplex.com/PHPExcel)
  24.  * @license    http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt    LGPL
  25.  * @version    1.7.6, 2011-02-27
  26.  */
  27.  
  28.  
  29. /**
  30.  * PHPExcel_Worksheet_HeaderFooter
  31.  *
  32.  * <code>
  33.  * Header/Footer Formatting Syntax taken from Office Open XML Part 4 - Markup Language Reference, page 1970:
  34.  *
  35.  * There are a number of formatting codes that can be written inline with the actual header / footer text, which
  36.  * affect the formatting in the header or footer.
  37.  *
  38.  * Example: This example shows the text "Center Bold Header" on the first line (center section), and the date on
  39.  * the second line (center section).
  40.  *         &CCenter &"-,Bold"Bold&"-,Regular"Header_x000A_&D
  41.  *
  42.  * General Rules:
  43.  * There is no required order in which these codes must appear.
  44.  *
  45.  * The first occurrence of the following codes turns the formatting ON, the second occurrence turns it OFF again:
  46.  * - strikethrough
  47.  * - superscript
  48.  * - subscript
  49.  * Superscript and subscript cannot both be ON at same time. Whichever comes first wins and the other is ignored,
  50.  * while the first is ON.
  51.  * &L - code for "left section" (there are three header / footer locations, "left", "center", and "right"). When
  52.  * two or more occurrences of this section marker exist, the contents from all markers are concatenated, in the
  53.  * order of appearance, and placed into the left section.
  54.  * &P - code for "current page #"
  55.  * &N - code for "total pages"
  56.  * &font size - code for "text font size", where font size is a font size in points.
  57.  * &K - code for "text font color"
  58.  * RGB Color is specified as RRGGBB
  59.  * Theme Color is specifed as TTSNN where TT is the theme color Id, S is either "+" or "-" of the tint/shade
  60.  * value, NN is the tint/shade value.
  61.  * &S - code for "text strikethrough" on / off
  62.  * &X - code for "text super script" on / off
  63.  * &Y - code for "text subscript" on / off
  64.  * &C - code for "center section". When two or more occurrences of this section marker exist, the contents
  65.  * from all markers are concatenated, in the order of appearance, and placed into the center section.
  66.  *
  67.  * &D - code for "date"
  68.  * &T - code for "time"
  69.  * &G - code for "picture as background"
  70.  * &U - code for "text single underline"
  71.  * &E - code for "double underline"
  72.  * &R - code for "right section". When two or more occurrences of this section marker exist, the contents
  73.  * from all markers are concatenated, in the order of appearance, and placed into the right section.
  74.  * &Z - code for "this workbook's file path"
  75.  * &F - code for "this workbook's file name"
  76.  * &A - code for "sheet tab name"
  77.  * &+ - code for add to page #.
  78.  * &- - code for subtract from page #.
  79.  * &"font name,font type" - code for "text font name" and "text font type", where font name and font type
  80.  * are strings specifying the name and type of the font, separated by a comma. When a hyphen appears in font
  81.  * name, it means "none specified". Both of font name and font type can be localized values.
  82.  * &"-,Bold" - code for "bold font style"
  83.  * &B - also means "bold font style".
  84.  * &"-,Regular" - code for "regular font style"
  85.  * &"-,Italic" - code for "italic font style"
  86.  * &I - also means "italic font style"
  87.  * &"-,Bold Italic" code for "bold italic font style"
  88.  * &O - code for "outline style"
  89.  * &H - code for "shadow style"
  90.  * </code>
  91.  *
  92.  * @category   PHPExcel
  93.  * @package    PHPExcel_Worksheet
  94.  * @copyright  Copyright (c) 2006 - 2011 PHPExcel (http://www.codeplex.com/PHPExcel)
  95.  */
  96. {
  97.     /* Header/footer image location */
  98.     const IMAGE_HEADER_LEFT                            'LH';
  99.     const IMAGE_HEADER_CENTER                        'CH';
  100.     const IMAGE_HEADER_RIGHT                        'RH';
  101.     const IMAGE_FOOTER_LEFT                            'LF';
  102.     const IMAGE_FOOTER_CENTER                        'CF';
  103.     const IMAGE_FOOTER_RIGHT                        'RF';
  104.  
  105.     /**
  106.      * OddHeader
  107.      *
  108.      * @var string 
  109.      */
  110.     private $_oddHeader            '';
  111.  
  112.     /**
  113.      * OddFooter
  114.      *
  115.      * @var string 
  116.      */
  117.     private $_oddFooter            '';
  118.  
  119.     /**
  120.      * EvenHeader
  121.      *
  122.      * @var string 
  123.      */
  124.     private $_evenHeader        '';
  125.  
  126.     /**
  127.      * EvenFooter
  128.      *
  129.      * @var string 
  130.      */
  131.     private $_evenFooter        '';
  132.  
  133.     /**
  134.      * FirstHeader
  135.      *
  136.      * @var string 
  137.      */
  138.     private $_firstHeader        '';
  139.  
  140.     /**
  141.      * FirstFooter
  142.      *
  143.      * @var string 
  144.      */
  145.     private $_firstFooter        '';
  146.  
  147.     /**
  148.      * Different header for Odd/Even, defaults to false
  149.      *
  150.      * @var boolean 
  151.      */
  152.     private $_differentOddEven    false;
  153.  
  154.     /**
  155.      * Different header for first page, defaults to false
  156.      *
  157.      * @var boolean 
  158.      */
  159.     private $_differentFirst    false;
  160.  
  161.     /**
  162.      * Scale with document, defaults to true
  163.      *
  164.      * @var boolean 
  165.      */
  166.     private $_scaleWithDocument    true;
  167.  
  168.     /**
  169.      * Align with margins, defaults to true
  170.      *
  171.      * @var boolean 
  172.      */
  173.     private $_alignWithMargins    true;
  174.  
  175.     /**
  176.      * Header/footer images
  177.      *
  178.      * @var PHPExcel_Worksheet_HeaderFooterDrawing[] 
  179.      */
  180.     private $_headerFooterImages array();
  181.  
  182.     /**
  183.      * Create a new PHPExcel_Worksheet_HeaderFooter
  184.      */
  185.     public function __construct()
  186.     {
  187.     }
  188.  
  189.     /**
  190.      * Get OddHeader
  191.      *
  192.      * @return string 
  193.      */
  194.     public function getOddHeader({
  195.         return $this->_oddHeader;
  196.     }
  197.  
  198.     /**
  199.      * Set OddHeader
  200.      *
  201.      * @param string $pValue 
  202.      * @return PHPExcel_Worksheet_HeaderFooter 
  203.      */
  204.     public function setOddHeader($pValue{
  205.         $this->_oddHeader $pValue;
  206.         return $this;
  207.     }
  208.  
  209.     /**
  210.      * Get OddFooter
  211.      *
  212.      * @return string 
  213.      */
  214.     public function getOddFooter({
  215.         return $this->_oddFooter;
  216.     }
  217.  
  218.     /**
  219.      * Set OddFooter
  220.      *
  221.      * @param string $pValue 
  222.      * @return PHPExcel_Worksheet_HeaderFooter 
  223.      */
  224.     public function setOddFooter($pValue{
  225.         $this->_oddFooter $pValue;
  226.         return $this;
  227.     }
  228.  
  229.     /**
  230.      * Get EvenHeader
  231.      *
  232.      * @return string 
  233.      */
  234.     public function getEvenHeader({
  235.         return $this->_evenHeader;
  236.     }
  237.  
  238.     /**
  239.      * Set EvenHeader
  240.      *
  241.      * @param string $pValue 
  242.      * @return PHPExcel_Worksheet_HeaderFooter 
  243.      */
  244.     public function setEvenHeader($pValue{
  245.         $this->_evenHeader $pValue;
  246.         return $this;
  247.     }
  248.  
  249.     /**
  250.      * Get EvenFooter
  251.      *
  252.      * @return string 
  253.      */
  254.     public function getEvenFooter({
  255.         return $this->_evenFooter;
  256.     }
  257.  
  258.     /**
  259.      * Set EvenFooter
  260.      *
  261.      * @param string $pValue 
  262.      * @return PHPExcel_Worksheet_HeaderFooter 
  263.      */
  264.     public function setEvenFooter($pValue{
  265.         $this->_evenFooter $pValue;
  266.         return $this;
  267.     }
  268.  
  269.     /**
  270.      * Get FirstHeader
  271.      *
  272.      * @return string 
  273.      */
  274.     public function getFirstHeader({
  275.         return $this->_firstHeader;
  276.     }
  277.  
  278.     /**
  279.      * Set FirstHeader
  280.      *
  281.      * @param string $pValue 
  282.      * @return PHPExcel_Worksheet_HeaderFooter 
  283.      */
  284.     public function setFirstHeader($pValue{
  285.         $this->_firstHeader $pValue;
  286.         return $this;
  287.     }
  288.  
  289.     /**
  290.      * Get FirstFooter
  291.      *
  292.      * @return string 
  293.      */
  294.     public function getFirstFooter({
  295.         return $this->_firstFooter;
  296.     }
  297.  
  298.     /**
  299.      * Set FirstFooter
  300.      *
  301.      * @param string $pValue 
  302.      * @return PHPExcel_Worksheet_HeaderFooter 
  303.      */
  304.     public function setFirstFooter($pValue{
  305.         $this->_firstFooter $pValue;
  306.         return $this;
  307.     }
  308.  
  309.     /**
  310.      * Get DifferentOddEven
  311.      *
  312.      * @return boolean 
  313.      */
  314.     public function getDifferentOddEven({
  315.         return $this->_differentOddEven;
  316.     }
  317.  
  318.     /**
  319.      * Set DifferentOddEven
  320.      *
  321.      * @param boolean $pValue 
  322.      * @return PHPExcel_Worksheet_HeaderFooter 
  323.      */
  324.     public function setDifferentOddEven($pValue false{
  325.         $this->_differentOddEven $pValue;
  326.         return $this;
  327.     }
  328.  
  329.     /**
  330.      * Get DifferentFirst
  331.      *
  332.      * @return boolean 
  333.      */
  334.     public function getDifferentFirst({
  335.         return $this->_differentFirst;
  336.     }
  337.  
  338.     /**
  339.      * Set DifferentFirst
  340.      *
  341.      * @param boolean $pValue 
  342.      * @return PHPExcel_Worksheet_HeaderFooter 
  343.      */
  344.     public function setDifferentFirst($pValue false{
  345.         $this->_differentFirst $pValue;
  346.         return $this;
  347.     }
  348.  
  349.     /**
  350.      * Get ScaleWithDocument
  351.      *
  352.      * @return boolean 
  353.      */
  354.     public function getScaleWithDocument({
  355.         return $this->_scaleWithDocument;
  356.     }
  357.  
  358.     /**
  359.      * Set ScaleWithDocument
  360.      *
  361.      * @param boolean $pValue 
  362.      * @return PHPExcel_Worksheet_HeaderFooter 
  363.      */
  364.     public function setScaleWithDocument($pValue true{
  365.         $this->_scaleWithDocument $pValue;
  366.         return $this;
  367.     }
  368.  
  369.     /**
  370.      * Get AlignWithMargins
  371.      *
  372.      * @return boolean 
  373.      */
  374.     public function getAlignWithMargins({
  375.         return $this->_alignWithMargins;
  376.     }
  377.  
  378.     /**
  379.      * Set AlignWithMargins
  380.      *
  381.      * @param boolean $pValue 
  382.      * @return PHPExcel_Worksheet_HeaderFooter 
  383.      */
  384.     public function setAlignWithMargins($pValue true{
  385.         $this->_alignWithMargins $pValue;
  386.         return $this;
  387.     }
  388.  
  389.     /**
  390.      * Add header/footer image
  391.      *
  392.      * @param PHPExcel_Worksheet_HeaderFooterDrawing $image 
  393.      * @param string $location 
  394.      * @throws Exception
  395.      * @return PHPExcel_Worksheet_HeaderFooter 
  396.      */
  397.     public function addImage(PHPExcel_Worksheet_HeaderFooterDrawing $image null$location self::IMAGE_HEADER_LEFT{
  398.         $this->_headerFooterImages[$location$image;
  399.         return $this;
  400.     }
  401.  
  402.     /**
  403.      * Remove header/footer image
  404.      *
  405.      * @param string $location 
  406.      * @throws Exception
  407.      * @return PHPExcel_Worksheet_HeaderFooter 
  408.      */
  409.     public function removeImage($location self::IMAGE_HEADER_LEFT{
  410.         if (isset($this->_headerFooterImages[$location])) {
  411.             unset($this->_headerFooterImages[$location]);
  412.         }
  413.         return $this;
  414.     }
  415.  
  416.     /**
  417.      * Set header/footer images
  418.      *
  419.      * @param PHPExcel_Worksheet_HeaderFooterDrawing[] $images 
  420.      * @throws Exception
  421.      * @return PHPExcel_Worksheet_HeaderFooter 
  422.      */
  423.     public function setImages($images{
  424.         if (!is_array($images)) {
  425.             throw new Exception('Invalid parameter!');
  426.         }
  427.  
  428.         $this->_headerFooterImages $images;
  429.         return $this;
  430.     }
  431.  
  432.     /**
  433.      * Get header/footer images
  434.      *
  435.      * @return PHPExcel_Worksheet_HeaderFooterDrawing[] 
  436.      */
  437.     public function getImages({
  438.         // Sort array
  439.         $images array();
  440.         if (isset($this->_headerFooterImages[self::IMAGE_HEADER_LEFT]))     $images[self::IMAGE_HEADER_LEFT=         $this->_headerFooterImages[self::IMAGE_HEADER_LEFT];
  441.         if (isset($this->_headerFooterImages[self::IMAGE_HEADER_CENTER]))     $images[self::IMAGE_HEADER_CENTER=     $this->_headerFooterImages[self::IMAGE_HEADER_CENTER];
  442.         if (isset($this->_headerFooterImages[self::IMAGE_HEADER_RIGHT]))     $images[self::IMAGE_HEADER_RIGHT=     $this->_headerFooterImages[self::IMAGE_HEADER_RIGHT];
  443.         if (isset($this->_headerFooterImages[self::IMAGE_FOOTER_LEFT]))     $images[self::IMAGE_FOOTER_LEFT=         $this->_headerFooterImages[self::IMAGE_FOOTER_LEFT];
  444.         if (isset($this->_headerFooterImages[self::IMAGE_FOOTER_CENTER]))     $images[self::IMAGE_FOOTER_CENTER=     $this->_headerFooterImages[self::IMAGE_FOOTER_CENTER];
  445.         if (isset($this->_headerFooterImages[self::IMAGE_FOOTER_RIGHT]))     $images[self::IMAGE_FOOTER_RIGHT=     $this->_headerFooterImages[self::IMAGE_FOOTER_RIGHT];
  446.         $this->_headerFooterImages $images;
  447.  
  448.         return $this->_headerFooterImages;
  449.     }
  450.  
  451.     /**
  452.      * Implement PHP __clone to create a deep clone, not just a shallow copy.
  453.      */
  454.     public function __clone({
  455.         $vars get_object_vars($this);
  456.         foreach ($vars as $key => $value{
  457.             if (is_object($value)) {
  458.                 $this->$key clone $value;
  459.             else {
  460.                 $this->$key $value;
  461.             }
  462.         }
  463.     }
  464. }

Documentation generated on Sun, 27 Feb 2011 16:32:15 -0800 by phpDocumentor 1.4.3