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 - 2010 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 - 2010 PHPExcel (http://www.codeplex.com/PHPExcel)
  24.  * @license    http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt    LGPL
  25.  * @version    1.7.3c, 2010-06-01
  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 - 2010 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;
  153.  
  154.     /**
  155.      * Different header for first page, defaults to false
  156.      *
  157.      * @var boolean 
  158.      */
  159.     private $_differentFirst;
  160.  
  161.     /**
  162.      * Scale with document, defaults to true
  163.      *
  164.      * @var boolean 
  165.      */
  166.     private $_scaleWithDocument;
  167.  
  168.     /**
  169.      * Align with margins, defaults to true
  170.      *
  171.      * @var boolean 
  172.      */
  173.     private $_alignWithMargins;
  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.         // Initialise values
  188.         $this->_oddHeader            '';
  189.         $this->_oddFooter            '';
  190.         $this->_evenHeader            '';
  191.         $this->_evenFooter            '';
  192.         $this->_firstHeader            '';
  193.         $this->_firstFooter            '';
  194.         $this->_differentOddEven     false;
  195.         $this->_differentFirst         false;
  196.         $this->_scaleWithDocument     true;
  197.         $this->_alignWithMargins     true;
  198.         $this->_headerFooterImages    array();
  199.     }
  200.  
  201.     /**
  202.      * Get OddHeader
  203.      *
  204.      * @return string 
  205.      */
  206.     public function getOddHeader({
  207.         return $this->_oddHeader;
  208.     }
  209.  
  210.     /**
  211.      * Set OddHeader
  212.      *
  213.      * @param string $pValue 
  214.      * @return PHPExcel_Worksheet_HeaderFooter 
  215.      */
  216.     public function setOddHeader($pValue{
  217.         $this->_oddHeader $pValue;
  218.         return $this;
  219.     }
  220.  
  221.     /**
  222.      * Get OddFooter
  223.      *
  224.      * @return string 
  225.      */
  226.     public function getOddFooter({
  227.         return $this->_oddFooter;
  228.     }
  229.  
  230.     /**
  231.      * Set OddFooter
  232.      *
  233.      * @param string $pValue 
  234.      * @return PHPExcel_Worksheet_HeaderFooter 
  235.      */
  236.     public function setOddFooter($pValue{
  237.         $this->_oddFooter $pValue;
  238.         return $this;
  239.     }
  240.  
  241.     /**
  242.      * Get EvenHeader
  243.      *
  244.      * @return string 
  245.      */
  246.     public function getEvenHeader({
  247.         return $this->_evenHeader;
  248.     }
  249.  
  250.     /**
  251.      * Set EvenHeader
  252.      *
  253.      * @param string $pValue 
  254.      * @return PHPExcel_Worksheet_HeaderFooter 
  255.      */
  256.     public function setEvenHeader($pValue{
  257.         $this->_evenHeader $pValue;
  258.         return $this;
  259.     }
  260.  
  261.     /**
  262.      * Get EvenFooter
  263.      *
  264.      * @return string 
  265.      */
  266.     public function getEvenFooter({
  267.         return $this->_evenFooter;
  268.     }
  269.  
  270.     /**
  271.      * Set EvenFooter
  272.      *
  273.      * @param string $pValue 
  274.      * @return PHPExcel_Worksheet_HeaderFooter 
  275.      */
  276.     public function setEvenFooter($pValue{
  277.         $this->_evenFooter $pValue;
  278.         return $this;
  279.     }
  280.  
  281.     /**
  282.      * Get FirstHeader
  283.      *
  284.      * @return string 
  285.      */
  286.     public function getFirstHeader({
  287.         return $this->_firstHeader;
  288.     }
  289.  
  290.     /**
  291.      * Set FirstHeader
  292.      *
  293.      * @param string $pValue 
  294.      * @return PHPExcel_Worksheet_HeaderFooter 
  295.      */
  296.     public function setFirstHeader($pValue{
  297.         $this->_firstHeader $pValue;
  298.         return $this;
  299.     }
  300.  
  301.     /**
  302.      * Get FirstFooter
  303.      *
  304.      * @return string 
  305.      */
  306.     public function getFirstFooter({
  307.         return $this->_firstFooter;
  308.     }
  309.  
  310.     /**
  311.      * Set FirstFooter
  312.      *
  313.      * @param string $pValue 
  314.      * @return PHPExcel_Worksheet_HeaderFooter 
  315.      */
  316.     public function setFirstFooter($pValue{
  317.         $this->_firstFooter $pValue;
  318.         return $this;
  319.     }
  320.  
  321.     /**
  322.      * Get DifferentOddEven
  323.      *
  324.      * @return boolean 
  325.      */
  326.     public function getDifferentOddEven({
  327.         return $this->_differentOddEven;
  328.     }
  329.  
  330.     /**
  331.      * Set DifferentOddEven
  332.      *
  333.      * @param boolean $pValue 
  334.      * @return PHPExcel_Worksheet_HeaderFooter 
  335.      */
  336.     public function setDifferentOddEven($pValue false{
  337.         $this->_differentOddEven $pValue;
  338.         return $this;
  339.     }
  340.  
  341.     /**
  342.      * Get DifferentFirst
  343.      *
  344.      * @return boolean 
  345.      */
  346.     public function getDifferentFirst({
  347.         return $this->_differentFirst;
  348.     }
  349.  
  350.     /**
  351.      * Set DifferentFirst
  352.      *
  353.      * @param boolean $pValue 
  354.      * @return PHPExcel_Worksheet_HeaderFooter 
  355.      */
  356.     public function setDifferentFirst($pValue false{
  357.         $this->_differentFirst $pValue;
  358.         return $this;
  359.     }
  360.  
  361.     /**
  362.      * Get ScaleWithDocument
  363.      *
  364.      * @return boolean 
  365.      */
  366.     public function getScaleWithDocument({
  367.         return $this->_scaleWithDocument;
  368.     }
  369.  
  370.     /**
  371.      * Set ScaleWithDocument
  372.      *
  373.      * @param boolean $pValue 
  374.      * @return PHPExcel_Worksheet_HeaderFooter 
  375.      */
  376.     public function setScaleWithDocument($pValue true{
  377.         $this->_scaleWithDocument $pValue;
  378.         return $this;
  379.     }
  380.  
  381.     /**
  382.      * Get AlignWithMargins
  383.      *
  384.      * @return boolean 
  385.      */
  386.     public function getAlignWithMargins({
  387.         return $this->_alignWithMargins;
  388.     }
  389.  
  390.     /**
  391.      * Set AlignWithMargins
  392.      *
  393.      * @param boolean $pValue 
  394.      * @return PHPExcel_Worksheet_HeaderFooter 
  395.      */
  396.     public function setAlignWithMargins($pValue true{
  397.         $this->_alignWithMargins $pValue;
  398.         return $this;
  399.     }
  400.  
  401.     /**
  402.      * Add header/footer image
  403.      *
  404.      * @param PHPExcel_Worksheet_HeaderFooterDrawing $image 
  405.      * @param string $location 
  406.      * @throws Exception
  407.      * @return PHPExcel_Worksheet_HeaderFooter 
  408.      */
  409.     public function addImage(PHPExcel_Worksheet_HeaderFooterDrawing $image null$location self::IMAGE_HEADER_LEFT{
  410.         $this->_headerFooterImages[$location$image;
  411.         return $this;
  412.     }
  413.  
  414.     /**
  415.      * Remove header/footer image
  416.      *
  417.      * @param string $location 
  418.      * @throws Exception
  419.      * @return PHPExcel_Worksheet_HeaderFooter 
  420.      */
  421.     public function removeImage($location self::IMAGE_HEADER_LEFT{
  422.         if (isset($this->_headerFooterImages[$location])) {
  423.             unset($this->_headerFooterImages[$location]);
  424.         }
  425.         return $this;
  426.     }
  427.  
  428.     /**
  429.      * Set header/footer images
  430.      *
  431.      * @param PHPExcel_Worksheet_HeaderFooterDrawing[] $images 
  432.      * @throws Exception
  433.      * @return PHPExcel_Worksheet_HeaderFooter 
  434.      */
  435.     public function setImages($images{
  436.         if (!is_array($images)) {
  437.             throw new Exception('Invalid parameter!');
  438.         }
  439.  
  440.         $this->_headerFooterImages $images;
  441.         return $this;
  442.     }
  443.  
  444.     /**
  445.      * Get header/footer images
  446.      *
  447.      * @return PHPExcel_Worksheet_HeaderFooterDrawing[] 
  448.      */
  449.     public function getImages({
  450.         // Sort array
  451.         $images array();
  452.         if (isset($this->_headerFooterImages[self::IMAGE_HEADER_LEFT]))     $images[self::IMAGE_HEADER_LEFT=         $this->_headerFooterImages[self::IMAGE_HEADER_LEFT];
  453.         if (isset($this->_headerFooterImages[self::IMAGE_HEADER_CENTER]))     $images[self::IMAGE_HEADER_CENTER=     $this->_headerFooterImages[self::IMAGE_HEADER_CENTER];
  454.         if (isset($this->_headerFooterImages[self::IMAGE_HEADER_RIGHT]))     $images[self::IMAGE_HEADER_RIGHT=     $this->_headerFooterImages[self::IMAGE_HEADER_RIGHT];
  455.         if (isset($this->_headerFooterImages[self::IMAGE_FOOTER_LEFT]))     $images[self::IMAGE_FOOTER_LEFT=         $this->_headerFooterImages[self::IMAGE_FOOTER_LEFT];
  456.         if (isset($this->_headerFooterImages[self::IMAGE_FOOTER_CENTER]))     $images[self::IMAGE_FOOTER_CENTER=     $this->_headerFooterImages[self::IMAGE_FOOTER_CENTER];
  457.         if (isset($this->_headerFooterImages[self::IMAGE_FOOTER_RIGHT]))     $images[self::IMAGE_FOOTER_RIGHT=     $this->_headerFooterImages[self::IMAGE_FOOTER_RIGHT];
  458.         $this->_headerFooterImages $images;
  459.  
  460.         return $this->_headerFooterImages;
  461.     }
  462.  
  463.     /**
  464.      * Implement PHP __clone to create a deep clone, not just a shallow copy.
  465.      */
  466.     public function __clone({
  467.         $vars get_object_vars($this);
  468.         foreach ($vars as $key => $value{
  469.             if (is_object($value)) {
  470.                 $this->$key clone $value;
  471.             else {
  472.                 $this->$key $value;
  473.             }
  474.         }
  475.     }
  476. }

Documentation generated on Tue, 01 Jun 2010 17:04:53 +0200 by phpDocumentor 1.4.3