[ Index ] |
PHP Cross Reference of Unnamed Project |
[Summary view] [Print] [Text view]
1 <?php 2 /** 3 * PHPExcel 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, 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 28 29 /** 30 * PHPExcel_Worksheet_PageSetup 31 * 32 * <code> 33 * Paper size taken from Office Open XML Part 4 - Markup Language Reference, page 1988: 34 * 35 * 1 = Letter paper (8.5 in. by 11 in.) 36 * 2 = Letter small paper (8.5 in. by 11 in.) 37 * 3 = Tabloid paper (11 in. by 17 in.) 38 * 4 = Ledger paper (17 in. by 11 in.) 39 * 5 = Legal paper (8.5 in. by 14 in.) 40 * 6 = Statement paper (5.5 in. by 8.5 in.) 41 * 7 = Executive paper (7.25 in. by 10.5 in.) 42 * 8 = A3 paper (297 mm by 420 mm) 43 * 9 = A4 paper (210 mm by 297 mm) 44 * 10 = A4 small paper (210 mm by 297 mm) 45 * 11 = A5 paper (148 mm by 210 mm) 46 * 12 = B4 paper (250 mm by 353 mm) 47 * 13 = B5 paper (176 mm by 250 mm) 48 * 14 = Folio paper (8.5 in. by 13 in.) 49 * 15 = Quarto paper (215 mm by 275 mm) 50 * 16 = Standard paper (10 in. by 14 in.) 51 * 17 = Standard paper (11 in. by 17 in.) 52 * 18 = Note paper (8.5 in. by 11 in.) 53 * 19 = #9 envelope (3.875 in. by 8.875 in.) 54 * 20 = #10 envelope (4.125 in. by 9.5 in.) 55 * 21 = #11 envelope (4.5 in. by 10.375 in.) 56 * 22 = #12 envelope (4.75 in. by 11 in.) 57 * 23 = #14 envelope (5 in. by 11.5 in.) 58 * 24 = C paper (17 in. by 22 in.) 59 * 25 = D paper (22 in. by 34 in.) 60 * 26 = E paper (34 in. by 44 in.) 61 * 27 = DL envelope (110 mm by 220 mm) 62 * 28 = C5 envelope (162 mm by 229 mm) 63 * 29 = C3 envelope (324 mm by 458 mm) 64 * 30 = C4 envelope (229 mm by 324 mm) 65 * 31 = C6 envelope (114 mm by 162 mm) 66 * 32 = C65 envelope (114 mm by 229 mm) 67 * 33 = B4 envelope (250 mm by 353 mm) 68 * 34 = B5 envelope (176 mm by 250 mm) 69 * 35 = B6 envelope (176 mm by 125 mm) 70 * 36 = Italy envelope (110 mm by 230 mm) 71 * 37 = Monarch envelope (3.875 in. by 7.5 in.). 72 * 38 = 6 3/4 envelope (3.625 in. by 6.5 in.) 73 * 39 = US standard fanfold (14.875 in. by 11 in.) 74 * 40 = German standard fanfold (8.5 in. by 12 in.) 75 * 41 = German legal fanfold (8.5 in. by 13 in.) 76 * 42 = ISO B4 (250 mm by 353 mm) 77 * 43 = Japanese double postcard (200 mm by 148 mm) 78 * 44 = Standard paper (9 in. by 11 in.) 79 * 45 = Standard paper (10 in. by 11 in.) 80 * 46 = Standard paper (15 in. by 11 in.) 81 * 47 = Invite envelope (220 mm by 220 mm) 82 * 50 = Letter extra paper (9.275 in. by 12 in.) 83 * 51 = Legal extra paper (9.275 in. by 15 in.) 84 * 52 = Tabloid extra paper (11.69 in. by 18 in.) 85 * 53 = A4 extra paper (236 mm by 322 mm) 86 * 54 = Letter transverse paper (8.275 in. by 11 in.) 87 * 55 = A4 transverse paper (210 mm by 297 mm) 88 * 56 = Letter extra transverse paper (9.275 in. by 12 in.) 89 * 57 = SuperA/SuperA/A4 paper (227 mm by 356 mm) 90 * 58 = SuperB/SuperB/A3 paper (305 mm by 487 mm) 91 * 59 = Letter plus paper (8.5 in. by 12.69 in.) 92 * 60 = A4 plus paper (210 mm by 330 mm) 93 * 61 = A5 transverse paper (148 mm by 210 mm) 94 * 62 = JIS B5 transverse paper (182 mm by 257 mm) 95 * 63 = A3 extra paper (322 mm by 445 mm) 96 * 64 = A5 extra paper (174 mm by 235 mm) 97 * 65 = ISO B5 extra paper (201 mm by 276 mm) 98 * 66 = A2 paper (420 mm by 594 mm) 99 * 67 = A3 transverse paper (297 mm by 420 mm) 100 * 68 = A3 extra transverse paper (322 mm by 445 mm) 101 * </code> 102 * 103 * @category PHPExcel 104 * @package PHPExcel_Worksheet 105 * @copyright Copyright (c) 2006 - 2015 PHPExcel (http://www.codeplex.com/PHPExcel) 106 */ 107 class PHPExcel_Worksheet_PageSetup 108 { 109 /* Paper size */ 110 const PAPERSIZE_LETTER = 1; 111 const PAPERSIZE_LETTER_SMALL = 2; 112 const PAPERSIZE_TABLOID = 3; 113 const PAPERSIZE_LEDGER = 4; 114 const PAPERSIZE_LEGAL = 5; 115 const PAPERSIZE_STATEMENT = 6; 116 const PAPERSIZE_EXECUTIVE = 7; 117 const PAPERSIZE_A3 = 8; 118 const PAPERSIZE_A4 = 9; 119 const PAPERSIZE_A4_SMALL = 10; 120 const PAPERSIZE_A5 = 11; 121 const PAPERSIZE_B4 = 12; 122 const PAPERSIZE_B5 = 13; 123 const PAPERSIZE_FOLIO = 14; 124 const PAPERSIZE_QUARTO = 15; 125 const PAPERSIZE_STANDARD_1 = 16; 126 const PAPERSIZE_STANDARD_2 = 17; 127 const PAPERSIZE_NOTE = 18; 128 const PAPERSIZE_NO9_ENVELOPE = 19; 129 const PAPERSIZE_NO10_ENVELOPE = 20; 130 const PAPERSIZE_NO11_ENVELOPE = 21; 131 const PAPERSIZE_NO12_ENVELOPE = 22; 132 const PAPERSIZE_NO14_ENVELOPE = 23; 133 const PAPERSIZE_C = 24; 134 const PAPERSIZE_D = 25; 135 const PAPERSIZE_E = 26; 136 const PAPERSIZE_DL_ENVELOPE = 27; 137 const PAPERSIZE_C5_ENVELOPE = 28; 138 const PAPERSIZE_C3_ENVELOPE = 29; 139 const PAPERSIZE_C4_ENVELOPE = 30; 140 const PAPERSIZE_C6_ENVELOPE = 31; 141 const PAPERSIZE_C65_ENVELOPE = 32; 142 const PAPERSIZE_B4_ENVELOPE = 33; 143 const PAPERSIZE_B5_ENVELOPE = 34; 144 const PAPERSIZE_B6_ENVELOPE = 35; 145 const PAPERSIZE_ITALY_ENVELOPE = 36; 146 const PAPERSIZE_MONARCH_ENVELOPE = 37; 147 const PAPERSIZE_6_3_4_ENVELOPE = 38; 148 const PAPERSIZE_US_STANDARD_FANFOLD = 39; 149 const PAPERSIZE_GERMAN_STANDARD_FANFOLD = 40; 150 const PAPERSIZE_GERMAN_LEGAL_FANFOLD = 41; 151 const PAPERSIZE_ISO_B4 = 42; 152 const PAPERSIZE_JAPANESE_DOUBLE_POSTCARD = 43; 153 const PAPERSIZE_STANDARD_PAPER_1 = 44; 154 const PAPERSIZE_STANDARD_PAPER_2 = 45; 155 const PAPERSIZE_STANDARD_PAPER_3 = 46; 156 const PAPERSIZE_INVITE_ENVELOPE = 47; 157 const PAPERSIZE_LETTER_EXTRA_PAPER = 48; 158 const PAPERSIZE_LEGAL_EXTRA_PAPER = 49; 159 const PAPERSIZE_TABLOID_EXTRA_PAPER = 50; 160 const PAPERSIZE_A4_EXTRA_PAPER = 51; 161 const PAPERSIZE_LETTER_TRANSVERSE_PAPER = 52; 162 const PAPERSIZE_A4_TRANSVERSE_PAPER = 53; 163 const PAPERSIZE_LETTER_EXTRA_TRANSVERSE_PAPER = 54; 164 const PAPERSIZE_SUPERA_SUPERA_A4_PAPER = 55; 165 const PAPERSIZE_SUPERB_SUPERB_A3_PAPER = 56; 166 const PAPERSIZE_LETTER_PLUS_PAPER = 57; 167 const PAPERSIZE_A4_PLUS_PAPER = 58; 168 const PAPERSIZE_A5_TRANSVERSE_PAPER = 59; 169 const PAPERSIZE_JIS_B5_TRANSVERSE_PAPER = 60; 170 const PAPERSIZE_A3_EXTRA_PAPER = 61; 171 const PAPERSIZE_A5_EXTRA_PAPER = 62; 172 const PAPERSIZE_ISO_B5_EXTRA_PAPER = 63; 173 const PAPERSIZE_A2_PAPER = 64; 174 const PAPERSIZE_A3_TRANSVERSE_PAPER = 65; 175 const PAPERSIZE_A3_EXTRA_TRANSVERSE_PAPER = 66; 176 177 /* Page orientation */ 178 const ORIENTATION_DEFAULT = 'default'; 179 const ORIENTATION_LANDSCAPE = 'landscape'; 180 const ORIENTATION_PORTRAIT = 'portrait'; 181 182 /* Print Range Set Method */ 183 const SETPRINTRANGE_OVERWRITE = 'O'; 184 const SETPRINTRANGE_INSERT = 'I'; 185 186 187 /** 188 * Paper size 189 * 190 * @var int 191 */ 192 private $paperSize = PHPExcel_Worksheet_PageSetup::PAPERSIZE_LETTER; 193 194 /** 195 * Orientation 196 * 197 * @var string 198 */ 199 private $orientation = PHPExcel_Worksheet_PageSetup::ORIENTATION_DEFAULT; 200 201 /** 202 * Scale (Print Scale) 203 * 204 * Print scaling. Valid values range from 10 to 400 205 * This setting is overridden when fitToWidth and/or fitToHeight are in use 206 * 207 * @var int? 208 */ 209 private $scale = 100; 210 211 /** 212 * Fit To Page 213 * Whether scale or fitToWith / fitToHeight applies 214 * 215 * @var boolean 216 */ 217 private $fitToPage = false; 218 219 /** 220 * Fit To Height 221 * Number of vertical pages to fit on 222 * 223 * @var int? 224 */ 225 private $fitToHeight = 1; 226 227 /** 228 * Fit To Width 229 * Number of horizontal pages to fit on 230 * 231 * @var int? 232 */ 233 private $fitToWidth = 1; 234 235 /** 236 * Columns to repeat at left 237 * 238 * @var array Containing start column and end column, empty array if option unset 239 */ 240 private $columnsToRepeatAtLeft = array('', ''); 241 242 /** 243 * Rows to repeat at top 244 * 245 * @var array Containing start row number and end row number, empty array if option unset 246 */ 247 private $rowsToRepeatAtTop = array(0, 0); 248 249 /** 250 * Center page horizontally 251 * 252 * @var boolean 253 */ 254 private $horizontalCentered = false; 255 256 /** 257 * Center page vertically 258 * 259 * @var boolean 260 */ 261 private $verticalCentered = false; 262 263 /** 264 * Print area 265 * 266 * @var string 267 */ 268 private $printArea = null; 269 270 /** 271 * First page number 272 * 273 * @var int 274 */ 275 private $firstPageNumber = null; 276 277 /** 278 * Create a new PHPExcel_Worksheet_PageSetup 279 */ 280 public function __construct() 281 { 282 } 283 284 /** 285 * Get Paper Size 286 * 287 * @return int 288 */ 289 public function getPaperSize() 290 { 291 return $this->paperSize; 292 } 293 294 /** 295 * Set Paper Size 296 * 297 * @param int $pValue 298 * @return PHPExcel_Worksheet_PageSetup 299 */ 300 public function setPaperSize($pValue = PHPExcel_Worksheet_PageSetup::PAPERSIZE_LETTER) 301 { 302 $this->paperSize = $pValue; 303 return $this; 304 } 305 306 /** 307 * Get Orientation 308 * 309 * @return string 310 */ 311 public function getOrientation() 312 { 313 return $this->orientation; 314 } 315 316 /** 317 * Set Orientation 318 * 319 * @param string $pValue 320 * @return PHPExcel_Worksheet_PageSetup 321 */ 322 public function setOrientation($pValue = PHPExcel_Worksheet_PageSetup::ORIENTATION_DEFAULT) 323 { 324 $this->orientation = $pValue; 325 return $this; 326 } 327 328 /** 329 * Get Scale 330 * 331 * @return int? 332 */ 333 public function getScale() 334 { 335 return $this->scale; 336 } 337 338 /** 339 * Set Scale 340 * 341 * Print scaling. Valid values range from 10 to 400 342 * This setting is overridden when fitToWidth and/or fitToHeight are in use 343 * 344 * @param int? $pValue 345 * @param boolean $pUpdate Update fitToPage so scaling applies rather than fitToHeight / fitToWidth 346 * @return PHPExcel_Worksheet_PageSetup 347 * @throws PHPExcel_Exception 348 */ 349 public function setScale($pValue = 100, $pUpdate = true) 350 { 351 // Microsoft Office Excel 2007 only allows setting a scale between 10 and 400 via the user interface, 352 // but it is apparently still able to handle any scale >= 0, where 0 results in 100 353 if (($pValue >= 0) || is_null($pValue)) { 354 $this->scale = $pValue; 355 if ($pUpdate) { 356 $this->fitToPage = false; 357 } 358 } else { 359 throw new PHPExcel_Exception("Scale must not be negative"); 360 } 361 return $this; 362 } 363 364 /** 365 * Get Fit To Page 366 * 367 * @return boolean 368 */ 369 public function getFitToPage() 370 { 371 return $this->fitToPage; 372 } 373 374 /** 375 * Set Fit To Page 376 * 377 * @param boolean $pValue 378 * @return PHPExcel_Worksheet_PageSetup 379 */ 380 public function setFitToPage($pValue = true) 381 { 382 $this->fitToPage = $pValue; 383 return $this; 384 } 385 386 /** 387 * Get Fit To Height 388 * 389 * @return int? 390 */ 391 public function getFitToHeight() 392 { 393 return $this->fitToHeight; 394 } 395 396 /** 397 * Set Fit To Height 398 * 399 * @param int? $pValue 400 * @param boolean $pUpdate Update fitToPage so it applies rather than scaling 401 * @return PHPExcel_Worksheet_PageSetup 402 */ 403 public function setFitToHeight($pValue = 1, $pUpdate = true) 404 { 405 $this->fitToHeight = $pValue; 406 if ($pUpdate) { 407 $this->fitToPage = true; 408 } 409 return $this; 410 } 411 412 /** 413 * Get Fit To Width 414 * 415 * @return int? 416 */ 417 public function getFitToWidth() 418 { 419 return $this->fitToWidth; 420 } 421 422 /** 423 * Set Fit To Width 424 * 425 * @param int? $pValue 426 * @param boolean $pUpdate Update fitToPage so it applies rather than scaling 427 * @return PHPExcel_Worksheet_PageSetup 428 */ 429 public function setFitToWidth($pValue = 1, $pUpdate = true) 430 { 431 $this->fitToWidth = $pValue; 432 if ($pUpdate) { 433 $this->fitToPage = true; 434 } 435 return $this; 436 } 437 438 /** 439 * Is Columns to repeat at left set? 440 * 441 * @return boolean 442 */ 443 public function isColumnsToRepeatAtLeftSet() 444 { 445 if (is_array($this->columnsToRepeatAtLeft)) { 446 if ($this->columnsToRepeatAtLeft[0] != '' && $this->columnsToRepeatAtLeft[1] != '') { 447 return true; 448 } 449 } 450 451 return false; 452 } 453 454 /** 455 * Get Columns to repeat at left 456 * 457 * @return array Containing start column and end column, empty array if option unset 458 */ 459 public function getColumnsToRepeatAtLeft() 460 { 461 return $this->columnsToRepeatAtLeft; 462 } 463 464 /** 465 * Set Columns to repeat at left 466 * 467 * @param array $pValue Containing start column and end column, empty array if option unset 468 * @return PHPExcel_Worksheet_PageSetup 469 */ 470 public function setColumnsToRepeatAtLeft($pValue = null) 471 { 472 if (is_array($pValue)) { 473 $this->columnsToRepeatAtLeft = $pValue; 474 } 475 return $this; 476 } 477 478 /** 479 * Set Columns to repeat at left by start and end 480 * 481 * @param string $pStart 482 * @param string $pEnd 483 * @return PHPExcel_Worksheet_PageSetup 484 */ 485 public function setColumnsToRepeatAtLeftByStartAndEnd($pStart = 'A', $pEnd = 'A') 486 { 487 $this->columnsToRepeatAtLeft = array($pStart, $pEnd); 488 return $this; 489 } 490 491 /** 492 * Is Rows to repeat at top set? 493 * 494 * @return boolean 495 */ 496 public function isRowsToRepeatAtTopSet() 497 { 498 if (is_array($this->rowsToRepeatAtTop)) { 499 if ($this->rowsToRepeatAtTop[0] != 0 && $this->rowsToRepeatAtTop[1] != 0) { 500 return true; 501 } 502 } 503 504 return false; 505 } 506 507 /** 508 * Get Rows to repeat at top 509 * 510 * @return array Containing start column and end column, empty array if option unset 511 */ 512 public function getRowsToRepeatAtTop() 513 { 514 return $this->rowsToRepeatAtTop; 515 } 516 517 /** 518 * Set Rows to repeat at top 519 * 520 * @param array $pValue Containing start column and end column, empty array if option unset 521 * @return PHPExcel_Worksheet_PageSetup 522 */ 523 public function setRowsToRepeatAtTop($pValue = null) 524 { 525 if (is_array($pValue)) { 526 $this->rowsToRepeatAtTop = $pValue; 527 } 528 return $this; 529 } 530 531 /** 532 * Set Rows to repeat at top by start and end 533 * 534 * @param int $pStart 535 * @param int $pEnd 536 * @return PHPExcel_Worksheet_PageSetup 537 */ 538 public function setRowsToRepeatAtTopByStartAndEnd($pStart = 1, $pEnd = 1) 539 { 540 $this->rowsToRepeatAtTop = array($pStart, $pEnd); 541 return $this; 542 } 543 544 /** 545 * Get center page horizontally 546 * 547 * @return bool 548 */ 549 public function getHorizontalCentered() 550 { 551 return $this->horizontalCentered; 552 } 553 554 /** 555 * Set center page horizontally 556 * 557 * @param bool $value 558 * @return PHPExcel_Worksheet_PageSetup 559 */ 560 public function setHorizontalCentered($value = false) 561 { 562 $this->horizontalCentered = $value; 563 return $this; 564 } 565 566 /** 567 * Get center page vertically 568 * 569 * @return bool 570 */ 571 public function getVerticalCentered() 572 { 573 return $this->verticalCentered; 574 } 575 576 /** 577 * Set center page vertically 578 * 579 * @param bool $value 580 * @return PHPExcel_Worksheet_PageSetup 581 */ 582 public function setVerticalCentered($value = false) 583 { 584 $this->verticalCentered = $value; 585 return $this; 586 } 587 588 /** 589 * Get print area 590 * 591 * @param int $index Identifier for a specific print area range if several ranges have been set 592 * Default behaviour, or a index value of 0, will return all ranges as a comma-separated string 593 * Otherwise, the specific range identified by the value of $index will be returned 594 * Print areas are numbered from 1 595 * @throws PHPExcel_Exception 596 * @return string 597 */ 598 public function getPrintArea($index = 0) 599 { 600 if ($index == 0) { 601 return $this->printArea; 602 } 603 $printAreas = explode(',', $this->printArea); 604 if (isset($printAreas[$index-1])) { 605 return $printAreas[$index-1]; 606 } 607 throw new PHPExcel_Exception("Requested Print Area does not exist"); 608 } 609 610 /** 611 * Is print area set? 612 * 613 * @param int $index Identifier for a specific print area range if several ranges have been set 614 * Default behaviour, or an index value of 0, will identify whether any print range is set 615 * Otherwise, existence of the range identified by the value of $index will be returned 616 * Print areas are numbered from 1 617 * @return boolean 618 */ 619 public function isPrintAreaSet($index = 0) 620 { 621 if ($index == 0) { 622 return !is_null($this->printArea); 623 } 624 $printAreas = explode(',', $this->printArea); 625 return isset($printAreas[$index-1]); 626 } 627 628 /** 629 * Clear a print area 630 * 631 * @param int $index Identifier for a specific print area range if several ranges have been set 632 * Default behaviour, or an index value of 0, will clear all print ranges that are set 633 * Otherwise, the range identified by the value of $index will be removed from the series 634 * Print areas are numbered from 1 635 * @return PHPExcel_Worksheet_PageSetup 636 */ 637 public function clearPrintArea($index = 0) 638 { 639 if ($index == 0) { 640 $this->printArea = null; 641 } else { 642 $printAreas = explode(',', $this->printArea); 643 if (isset($printAreas[$index-1])) { 644 unset($printAreas[$index-1]); 645 $this->printArea = implode(',', $printAreas); 646 } 647 } 648 649 return $this; 650 } 651 652 /** 653 * Set print area. e.g. 'A1:D10' or 'A1:D10,G5:M20' 654 * 655 * @param string $value 656 * @param int $index Identifier for a specific print area range allowing several ranges to be set 657 * When the method is "O"verwrite, then a positive integer index will overwrite that indexed 658 * entry in the print areas list; a negative index value will identify which entry to 659 * overwrite working bacward through the print area to the list, with the last entry as -1. 660 * Specifying an index value of 0, will overwrite <b>all</b> existing print ranges. 661 * When the method is "I"nsert, then a positive index will insert after that indexed entry in 662 * the print areas list, while a negative index will insert before the indexed entry. 663 * Specifying an index value of 0, will always append the new print range at the end of the 664 * list. 665 * Print areas are numbered from 1 666 * @param string $method Determines the method used when setting multiple print areas 667 * Default behaviour, or the "O" method, overwrites existing print area 668 * The "I" method, inserts the new print area before any specified index, or at the end of the list 669 * @return PHPExcel_Worksheet_PageSetup 670 * @throws PHPExcel_Exception 671 */ 672 public function setPrintArea($value, $index = 0, $method = self::SETPRINTRANGE_OVERWRITE) 673 { 674 if (strpos($value, '!') !== false) { 675 throw new PHPExcel_Exception('Cell coordinate must not specify a worksheet.'); 676 } elseif (strpos($value, ':') === false) { 677 throw new PHPExcel_Exception('Cell coordinate must be a range of cells.'); 678 } elseif (strpos($value, '$') !== false) { 679 throw new PHPExcel_Exception('Cell coordinate must not be absolute.'); 680 } 681 $value = strtoupper($value); 682 683 if ($method == self::SETPRINTRANGE_OVERWRITE) { 684 if ($index == 0) { 685 $this->printArea = $value; 686 } else { 687 $printAreas = explode(',', $this->printArea); 688 if ($index < 0) { 689 $index = count($printAreas) - abs($index) + 1; 690 } 691 if (($index <= 0) || ($index > count($printAreas))) { 692 throw new PHPExcel_Exception('Invalid index for setting print range.'); 693 } 694 $printAreas[$index-1] = $value; 695 $this->printArea = implode(',', $printAreas); 696 } 697 } elseif ($method == self::SETPRINTRANGE_INSERT) { 698 if ($index == 0) { 699 $this->printArea .= ($this->printArea == '') ? $value : ','.$value; 700 } else { 701 $printAreas = explode(',', $this->printArea); 702 if ($index < 0) { 703 $index = abs($index) - 1; 704 } 705 if ($index > count($printAreas)) { 706 throw new PHPExcel_Exception('Invalid index for setting print range.'); 707 } 708 $printAreas = array_merge(array_slice($printAreas, 0, $index), array($value), array_slice($printAreas, $index)); 709 $this->printArea = implode(',', $printAreas); 710 } 711 } else { 712 throw new PHPExcel_Exception('Invalid method for setting print range.'); 713 } 714 715 return $this; 716 } 717 718 /** 719 * Add a new print area (e.g. 'A1:D10' or 'A1:D10,G5:M20') to the list of print areas 720 * 721 * @param string $value 722 * @param int $index Identifier for a specific print area range allowing several ranges to be set 723 * A positive index will insert after that indexed entry in the print areas list, while a 724 * negative index will insert before the indexed entry. 725 * Specifying an index value of 0, will always append the new print range at the end of the 726 * list. 727 * Print areas are numbered from 1 728 * @return PHPExcel_Worksheet_PageSetup 729 * @throws PHPExcel_Exception 730 */ 731 public function addPrintArea($value, $index = -1) 732 { 733 return $this->setPrintArea($value, $index, self::SETPRINTRANGE_INSERT); 734 } 735 736 /** 737 * Set print area 738 * 739 * @param int $column1 Column 1 740 * @param int $row1 Row 1 741 * @param int $column2 Column 2 742 * @param int $row2 Row 2 743 * @param int $index Identifier for a specific print area range allowing several ranges to be set 744 * When the method is "O"verwrite, then a positive integer index will overwrite that indexed 745 * entry in the print areas list; a negative index value will identify which entry to 746 * overwrite working bacward through the print area to the list, with the last entry as -1. 747 * Specifying an index value of 0, will overwrite <b>all</b> existing print ranges. 748 * When the method is "I"nsert, then a positive index will insert after that indexed entry in 749 * the print areas list, while a negative index will insert before the indexed entry. 750 * Specifying an index value of 0, will always append the new print range at the end of the 751 * list. 752 * Print areas are numbered from 1 753 * @param string $method Determines the method used when setting multiple print areas 754 * Default behaviour, or the "O" method, overwrites existing print area 755 * The "I" method, inserts the new print area before any specified index, or at the end of the list 756 * @return PHPExcel_Worksheet_PageSetup 757 * @throws PHPExcel_Exception 758 */ 759 public function setPrintAreaByColumnAndRow($column1, $row1, $column2, $row2, $index = 0, $method = self::SETPRINTRANGE_OVERWRITE) 760 { 761 return $this->setPrintArea( 762 PHPExcel_Cell::stringFromColumnIndex($column1) . $row1 . ':' . PHPExcel_Cell::stringFromColumnIndex($column2) . $row2, 763 $index, 764 $method 765 ); 766 } 767 768 /** 769 * Add a new print area to the list of print areas 770 * 771 * @param int $column1 Start Column for the print area 772 * @param int $row1 Start Row for the print area 773 * @param int $column2 End Column for the print area 774 * @param int $row2 End Row for the print area 775 * @param int $index Identifier for a specific print area range allowing several ranges to be set 776 * A positive index will insert after that indexed entry in the print areas list, while a 777 * negative index will insert before the indexed entry. 778 * Specifying an index value of 0, will always append the new print range at the end of the 779 * list. 780 * Print areas are numbered from 1 781 * @return PHPExcel_Worksheet_PageSetup 782 * @throws PHPExcel_Exception 783 */ 784 public function addPrintAreaByColumnAndRow($column1, $row1, $column2, $row2, $index = -1) 785 { 786 return $this->setPrintArea( 787 PHPExcel_Cell::stringFromColumnIndex($column1) . $row1 . ':' . PHPExcel_Cell::stringFromColumnIndex($column2) . $row2, 788 $index, 789 self::SETPRINTRANGE_INSERT 790 ); 791 } 792 793 /** 794 * Get first page number 795 * 796 * @return int 797 */ 798 public function getFirstPageNumber() 799 { 800 return $this->firstPageNumber; 801 } 802 803 /** 804 * Set first page number 805 * 806 * @param int $value 807 * @return PHPExcel_Worksheet_HeaderFooter 808 */ 809 public function setFirstPageNumber($value = null) 810 { 811 $this->firstPageNumber = $value; 812 return $this; 813 } 814 815 /** 816 * Reset first page number 817 * 818 * @return PHPExcel_Worksheet_HeaderFooter 819 */ 820 public function resetFirstPageNumber() 821 { 822 return $this->setFirstPageNumber(null); 823 } 824 825 /** 826 * Implement PHP __clone to create a deep clone, not just a shallow copy. 827 */ 828 public function __clone() 829 { 830 $vars = get_object_vars($this); 831 foreach ($vars as $key => $value) { 832 if (is_object($value)) { 833 $this->$key = clone $value; 834 } else { 835 $this->$key = $value; 836 } 837 } 838 } 839 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Thu Aug 11 10:00:09 2016 | Cross-referenced by PHPXref 0.7.1 |