PageRenderTime 46ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/branches/v1.6.1/Classes/PHPExcel/Worksheet/HeaderFooter.php

#
PHP | 455 lines | 131 code | 43 blank | 281 comment | 10 complexity | 0342d4e70a6f1f11949c9103aa9f0245 MD5 | raw file
Possible License(s): AGPL-1.0, LGPL-2.0, LGPL-2.1, GPL-3.0, LGPL-3.0
  1. <?php
  2. /**
  3. * PHPExcel
  4. *
  5. * Copyright (c) 2006 - 2008 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 - 2008 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. /** PHPExcel_Worksheet_HeaderFooterDrawing */
  28. require_once 'PHPExcel/Worksheet/HeaderFooterDrawing.php';
  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 - 2008 PHPExcel (http://www.codeplex.com/PHPExcel)
  95. */
  96. class PHPExcel_Worksheet_HeaderFooter
  97. {
  98. /* Header/footer image location */
  99. const IMAGE_HEADER_LEFT = 'LH';
  100. const IMAGE_HEADER_CENTER = 'CH';
  101. const IMAGE_HEADER_RIGHT = 'RH';
  102. const IMAGE_FOOTER_LEFT = 'LF';
  103. const IMAGE_FOOTER_CENTER = 'CF';
  104. const IMAGE_FOOTER_RIGHT = 'RF';
  105. /**
  106. * OddHeader
  107. *
  108. * @var string
  109. */
  110. private $_oddHeader;
  111. /**
  112. * OddFooter
  113. *
  114. * @var string
  115. */
  116. private $_oddFooter;
  117. /**
  118. * EvenHeader
  119. *
  120. * @var string
  121. */
  122. private $_evenHeader;
  123. /**
  124. * EvenFooter
  125. *
  126. * @var string
  127. */
  128. private $_evenFooter;
  129. /**
  130. * FirstHeader
  131. *
  132. * @var string
  133. */
  134. private $_firstHeader;
  135. /**
  136. * FirstFooter
  137. *
  138. * @var string
  139. */
  140. private $_firstFooter;
  141. /**
  142. * Different header for Odd/Even, defaults to false
  143. *
  144. * @var boolean
  145. */
  146. private $_differentOddEven;
  147. /**
  148. * Different header for first page, defaults to false
  149. *
  150. * @var boolean
  151. */
  152. private $_differentFirst;
  153. /**
  154. * Scale with document, defaults to true
  155. *
  156. * @var boolean
  157. */
  158. private $_scaleWithDocument;
  159. /**
  160. * Align with margins, defaults to true
  161. *
  162. * @var boolean
  163. */
  164. private $_alignWithMargins;
  165. /**
  166. * Header/footer images
  167. *
  168. * @var PHPExcel_Worksheet_HeaderFooterDrawing[]
  169. */
  170. private $_headerFooterImages = array();
  171. /**
  172. * Create a new PHPExcel_Worksheet_HeaderFooter
  173. */
  174. public function __construct()
  175. {
  176. // Initialise values
  177. $this->_oddHeader = '';
  178. $this->_oddFooter = '';
  179. $this->_evenHeader = '';
  180. $this->_evenFooter = '';
  181. $this->_firstHeader = '';
  182. $this->_firstFooter = '';
  183. $this->_differentOddEven = false;
  184. $this->_differentFirst = false;
  185. $this->_scaleWithDocument = true;
  186. $this->_alignWithMargins = true;
  187. $this->_headerFooterImages = array();
  188. }
  189. /**
  190. * Get OddHeader
  191. *
  192. * @return string
  193. */
  194. public function getOddHeader() {
  195. return $this->_oddHeader;
  196. }
  197. /**
  198. * Set OddHeader
  199. *
  200. * @param string $pValue
  201. */
  202. public function setOddHeader($pValue) {
  203. $this->_oddHeader = $pValue;
  204. }
  205. /**
  206. * Get OddFooter
  207. *
  208. * @return string
  209. */
  210. public function getOddFooter() {
  211. return $this->_oddFooter;
  212. }
  213. /**
  214. * Set OddFooter
  215. *
  216. * @param string $pValue
  217. */
  218. public function setOddFooter($pValue) {
  219. $this->_oddFooter = $pValue;
  220. }
  221. /**
  222. * Get EvenHeader
  223. *
  224. * @return string
  225. */
  226. public function getEvenHeader() {
  227. return $this->_evenHeader;
  228. }
  229. /**
  230. * Set EvenHeader
  231. *
  232. * @param string $pValue
  233. */
  234. public function setEvenHeader($pValue) {
  235. $this->_evenHeader = $pValue;
  236. }
  237. /**
  238. * Get EvenFooter
  239. *
  240. * @return string
  241. */
  242. public function getEvenFooter() {
  243. return $this->_evenFooter;
  244. }
  245. /**
  246. * Set EvenFooter
  247. *
  248. * @param string $pValue
  249. */
  250. public function setEvenFooter($pValue) {
  251. $this->_evenFooter = $pValue;
  252. }
  253. /**
  254. * Get FirstHeader
  255. *
  256. * @return string
  257. */
  258. public function getFirstHeader() {
  259. return $this->_firstHeader;
  260. }
  261. /**
  262. * Set FirstHeader
  263. *
  264. * @param string $pValue
  265. */
  266. public function setFirstHeader($pValue) {
  267. $this->_firstHeader = $pValue;
  268. }
  269. /**
  270. * Get FirstFooter
  271. *
  272. * @return string
  273. */
  274. public function getFirstFooter() {
  275. return $this->_firstFooter;
  276. }
  277. /**
  278. * Set FirstFooter
  279. *
  280. * @param string $pValue
  281. */
  282. public function setFirstFooter($pValue) {
  283. $this->_firstFooter = $pValue;
  284. }
  285. /**
  286. * Get DifferentOddEven
  287. *
  288. * @return boolean
  289. */
  290. public function getDifferentOddEven() {
  291. return $this->_differentOddEven;
  292. }
  293. /**
  294. * Set DifferentOddEven
  295. *
  296. * @param boolean $pValue
  297. */
  298. public function setDifferentOddEven($pValue = false) {
  299. $this->_differentOddEven = $pValue;
  300. }
  301. /**
  302. * Get DifferentFirst
  303. *
  304. * @return boolean
  305. */
  306. public function getDifferentFirst() {
  307. return $this->_differentFirst;
  308. }
  309. /**
  310. * Set DifferentFirst
  311. *
  312. * @param boolean $pValue
  313. */
  314. public function setDifferentFirst($pValue = false) {
  315. $this->_differentFirst = $pValue;
  316. }
  317. /**
  318. * Get ScaleWithDocument
  319. *
  320. * @return boolean
  321. */
  322. public function getScaleWithDocument() {
  323. return $this->_scaleWithDocument;
  324. }
  325. /**
  326. * Set ScaleWithDocument
  327. *
  328. * @param boolean $pValue
  329. */
  330. public function setScaleWithDocument($pValue = true) {
  331. $this->_scaleWithDocument = $pValue;
  332. }
  333. /**
  334. * Get AlignWithMargins
  335. *
  336. * @return boolean
  337. */
  338. public function getAlignWithMargins() {
  339. return $this->_alignWithMargins;
  340. }
  341. /**
  342. * Set AlignWithMargins
  343. *
  344. * @param boolean $pValue
  345. */
  346. public function setAlignWithMargins($pValue = true) {
  347. $this->_alignWithMargins = $pValue;
  348. }
  349. /**
  350. * Add header/footer image
  351. *
  352. * @param PHPExcel_Worksheet_HeaderFooterDrawing $image
  353. * @param string $location
  354. * @throws Exception
  355. */
  356. public function addImage(PHPExcel_Worksheet_HeaderFooterDrawing $image = null, $location = self::IMAGE_HEADER_LEFT) {
  357. $this->_headerFooterImages[$location] = $image;
  358. }
  359. /**
  360. * Remove header/footer image
  361. *
  362. * @param string $location
  363. * @throws Exception
  364. */
  365. public function removeImage($location = self::IMAGE_HEADER_LEFT) {
  366. if (isset($this->_headerFooterImages[$location])) {
  367. unset($this->_headerFooterImages[$location]);
  368. }
  369. }
  370. /**
  371. * Set header/footer images
  372. *
  373. * @param PHPExcel_Worksheet_HeaderFooterDrawing[] $images
  374. * @throws Exception
  375. */
  376. public function setImages($images) {
  377. if (!is_array($images)) {
  378. throw new Exception('Invalid parameter!');
  379. }
  380. $this->_headerFooterImages = $images;
  381. }
  382. /**
  383. * Get header/footer images
  384. *
  385. * @return HPExcel_Worksheet_HeaderFooterDrawing[]
  386. */
  387. public function getImages() {
  388. // Sort array
  389. $images = array();
  390. if (isset($this->_headerFooterImages[self::IMAGE_HEADER_LEFT])) $images[self::IMAGE_HEADER_LEFT] = $this->_headerFooterImages[self::IMAGE_HEADER_LEFT];
  391. if (isset($this->_headerFooterImages[self::IMAGE_HEADER_CENTER])) $images[self::IMAGE_HEADER_CENTER] = $this->_headerFooterImages[self::IMAGE_HEADER_CENTER];
  392. if (isset($this->_headerFooterImages[self::IMAGE_HEADER_RIGHT])) $images[self::IMAGE_HEADER_RIGHT] = $this->_headerFooterImages[self::IMAGE_HEADER_RIGHT];
  393. if (isset($this->_headerFooterImages[self::IMAGE_FOOTER_LEFT])) $images[self::IMAGE_FOOTER_LEFT] = $this->_headerFooterImages[self::IMAGE_FOOTER_LEFT];
  394. if (isset($this->_headerFooterImages[self::IMAGE_FOOTER_CENTER])) $images[self::IMAGE_FOOTER_CENTER] = $this->_headerFooterImages[self::IMAGE_FOOTER_CENTER];
  395. if (isset($this->_headerFooterImages[self::IMAGE_FOOTER_RIGHT])) $images[self::IMAGE_FOOTER_RIGHT] = $this->_headerFooterImages[self::IMAGE_FOOTER_RIGHT];
  396. $this->_headerFooterImages = $images;
  397. return $this->_headerFooterImages;
  398. }
  399. /**
  400. * Implement PHP __clone to create a deep clone, not just a shallow copy.
  401. */
  402. public function __clone() {
  403. $vars = get_object_vars($this);
  404. foreach ($vars as $key => $value) {
  405. if (is_object($value)) {
  406. $this->$key = clone $value;
  407. } else {
  408. $this->$key = $value;
  409. }
  410. }
  411. }
  412. }