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

Documentation generated on Mon, 11 Jan 2010 08:11:14 +0100 by phpDocumentor 1.4.1