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

Documentation generated on Mon, 05 Jan 2009 20:37:50 +0100 by phpDocumentor 1.4.1