[ Index ]

PHP Cross Reference of Unnamed Project

title

Body

[close]

/lib/phpexcel/PHPExcel/Worksheet/ -> HeaderFooter.php (source)

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


Generated: Thu Aug 11 10:00:09 2016 Cross-referenced by PHPXref 0.7.1