HeaderFooter.php 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413
  1. <?php
  2. /**
  3. * 重庆赤晓店信息科技有限公司
  4. * https://www.chixiaodian.com
  5. * Copyright (c) 2023 赤店商城 All rights reserved.
  6. */
  7. class PHPExcel_Worksheet_HeaderFooter
  8. {
  9. /* Header/footer image location */
  10. const IMAGE_HEADER_LEFT = 'LH';
  11. const IMAGE_HEADER_CENTER = 'CH';
  12. const IMAGE_HEADER_RIGHT = 'RH';
  13. const IMAGE_FOOTER_LEFT = 'LF';
  14. const IMAGE_FOOTER_CENTER = 'CF';
  15. const IMAGE_FOOTER_RIGHT = 'RF';
  16. /**
  17. * OddHeader
  18. *
  19. * @var string
  20. */
  21. private $oddHeader = '';
  22. /**
  23. * OddFooter
  24. *
  25. * @var string
  26. */
  27. private $oddFooter = '';
  28. /**
  29. * EvenHeader
  30. *
  31. * @var string
  32. */
  33. private $evenHeader = '';
  34. /**
  35. * EvenFooter
  36. *
  37. * @var string
  38. */
  39. private $evenFooter = '';
  40. /**
  41. * FirstHeader
  42. *
  43. * @var string
  44. */
  45. private $firstHeader = '';
  46. /**
  47. * FirstFooter
  48. *
  49. * @var string
  50. */
  51. private $firstFooter = '';
  52. /**
  53. * Different header for Odd/Even, defaults to false
  54. *
  55. * @var boolean
  56. */
  57. private $differentOddEven = false;
  58. /**
  59. * Different header for first page, defaults to false
  60. *
  61. * @var boolean
  62. */
  63. private $differentFirst = false;
  64. /**
  65. * Scale with document, defaults to true
  66. *
  67. * @var boolean
  68. */
  69. private $scaleWithDocument = true;
  70. /**
  71. * Align with margins, defaults to true
  72. *
  73. * @var boolean
  74. */
  75. private $alignWithMargins = true;
  76. /**
  77. * Header/footer images
  78. *
  79. * @var PHPExcel_Worksheet_HeaderFooterDrawing[]
  80. */
  81. private $headerFooterImages = array();
  82. /**
  83. * Create a new PHPExcel_Worksheet_HeaderFooter
  84. */
  85. public function __construct()
  86. {
  87. }
  88. /**
  89. * Get OddHeader
  90. *
  91. * @return string
  92. */
  93. public function getOddHeader()
  94. {
  95. return $this->oddHeader;
  96. }
  97. /**
  98. * Set OddHeader
  99. *
  100. * @param string $pValue
  101. * @return PHPExcel_Worksheet_HeaderFooter
  102. */
  103. public function setOddHeader($pValue)
  104. {
  105. $this->oddHeader = $pValue;
  106. return $this;
  107. }
  108. /**
  109. * Get OddFooter
  110. *
  111. * @return string
  112. */
  113. public function getOddFooter()
  114. {
  115. return $this->oddFooter;
  116. }
  117. /**
  118. * Set OddFooter
  119. *
  120. * @param string $pValue
  121. * @return PHPExcel_Worksheet_HeaderFooter
  122. */
  123. public function setOddFooter($pValue)
  124. {
  125. $this->oddFooter = $pValue;
  126. return $this;
  127. }
  128. /**
  129. * Get EvenHeader
  130. *
  131. * @return string
  132. */
  133. public function getEvenHeader()
  134. {
  135. return $this->evenHeader;
  136. }
  137. /**
  138. * Set EvenHeader
  139. *
  140. * @param string $pValue
  141. * @return PHPExcel_Worksheet_HeaderFooter
  142. */
  143. public function setEvenHeader($pValue)
  144. {
  145. $this->evenHeader = $pValue;
  146. return $this;
  147. }
  148. /**
  149. * Get EvenFooter
  150. *
  151. * @return string
  152. */
  153. public function getEvenFooter()
  154. {
  155. return $this->evenFooter;
  156. }
  157. /**
  158. * Set EvenFooter
  159. *
  160. * @param string $pValue
  161. * @return PHPExcel_Worksheet_HeaderFooter
  162. */
  163. public function setEvenFooter($pValue)
  164. {
  165. $this->evenFooter = $pValue;
  166. return $this;
  167. }
  168. /**
  169. * Get FirstHeader
  170. *
  171. * @return string
  172. */
  173. public function getFirstHeader()
  174. {
  175. return $this->firstHeader;
  176. }
  177. /**
  178. * Set FirstHeader
  179. *
  180. * @param string $pValue
  181. * @return PHPExcel_Worksheet_HeaderFooter
  182. */
  183. public function setFirstHeader($pValue)
  184. {
  185. $this->firstHeader = $pValue;
  186. return $this;
  187. }
  188. /**
  189. * Get FirstFooter
  190. *
  191. * @return string
  192. */
  193. public function getFirstFooter()
  194. {
  195. return $this->firstFooter;
  196. }
  197. /**
  198. * Set FirstFooter
  199. *
  200. * @param string $pValue
  201. * @return PHPExcel_Worksheet_HeaderFooter
  202. */
  203. public function setFirstFooter($pValue)
  204. {
  205. $this->firstFooter = $pValue;
  206. return $this;
  207. }
  208. /**
  209. * Get DifferentOddEven
  210. *
  211. * @return boolean
  212. */
  213. public function getDifferentOddEven()
  214. {
  215. return $this->differentOddEven;
  216. }
  217. /**
  218. * Set DifferentOddEven
  219. *
  220. * @param boolean $pValue
  221. * @return PHPExcel_Worksheet_HeaderFooter
  222. */
  223. public function setDifferentOddEven($pValue = false)
  224. {
  225. $this->differentOddEven = $pValue;
  226. return $this;
  227. }
  228. /**
  229. * Get DifferentFirst
  230. *
  231. * @return boolean
  232. */
  233. public function getDifferentFirst()
  234. {
  235. return $this->differentFirst;
  236. }
  237. /**
  238. * Set DifferentFirst
  239. *
  240. * @param boolean $pValue
  241. * @return PHPExcel_Worksheet_HeaderFooter
  242. */
  243. public function setDifferentFirst($pValue = false)
  244. {
  245. $this->differentFirst = $pValue;
  246. return $this;
  247. }
  248. /**
  249. * Get ScaleWithDocument
  250. *
  251. * @return boolean
  252. */
  253. public function getScaleWithDocument()
  254. {
  255. return $this->scaleWithDocument;
  256. }
  257. /**
  258. * Set ScaleWithDocument
  259. *
  260. * @param boolean $pValue
  261. * @return PHPExcel_Worksheet_HeaderFooter
  262. */
  263. public function setScaleWithDocument($pValue = true)
  264. {
  265. $this->scaleWithDocument = $pValue;
  266. return $this;
  267. }
  268. /**
  269. * Get AlignWithMargins
  270. *
  271. * @return boolean
  272. */
  273. public function getAlignWithMargins()
  274. {
  275. return $this->alignWithMargins;
  276. }
  277. /**
  278. * Set AlignWithMargins
  279. *
  280. * @param boolean $pValue
  281. * @return PHPExcel_Worksheet_HeaderFooter
  282. */
  283. public function setAlignWithMargins($pValue = true)
  284. {
  285. $this->alignWithMargins = $pValue;
  286. return $this;
  287. }
  288. /**
  289. * Add header/footer image
  290. *
  291. * @param PHPExcel_Worksheet_HeaderFooterDrawing $image
  292. * @param string $location
  293. * @throws PHPExcel_Exception
  294. * @return PHPExcel_Worksheet_HeaderFooter
  295. */
  296. public function addImage(PHPExcel_Worksheet_HeaderFooterDrawing $image = null, $location = self::IMAGE_HEADER_LEFT)
  297. {
  298. $this->headerFooterImages[$location] = $image;
  299. return $this;
  300. }
  301. /**
  302. * Remove header/footer image
  303. *
  304. * @param string $location
  305. * @throws PHPExcel_Exception
  306. * @return PHPExcel_Worksheet_HeaderFooter
  307. */
  308. public function removeImage($location = self::IMAGE_HEADER_LEFT)
  309. {
  310. if (isset($this->headerFooterImages[$location])) {
  311. unset($this->headerFooterImages[$location]);
  312. }
  313. return $this;
  314. }
  315. /**
  316. * Set header/footer images
  317. *
  318. * @param PHPExcel_Worksheet_HeaderFooterDrawing[] $images
  319. * @throws PHPExcel_Exception
  320. * @return PHPExcel_Worksheet_HeaderFooter
  321. */
  322. public function setImages($images)
  323. {
  324. if (!is_array($images)) {
  325. throw new PHPExcel_Exception('Invalid parameter!');
  326. }
  327. $this->headerFooterImages = $images;
  328. return $this;
  329. }
  330. /**
  331. * Get header/footer images
  332. *
  333. * @return PHPExcel_Worksheet_HeaderFooterDrawing[]
  334. */
  335. public function getImages()
  336. {
  337. // Sort array
  338. $images = array();
  339. if (isset($this->headerFooterImages[self::IMAGE_HEADER_LEFT])) {
  340. $images[self::IMAGE_HEADER_LEFT] = $this->headerFooterImages[self::IMAGE_HEADER_LEFT];
  341. }
  342. if (isset($this->headerFooterImages[self::IMAGE_HEADER_CENTER])) {
  343. $images[self::IMAGE_HEADER_CENTER] = $this->headerFooterImages[self::IMAGE_HEADER_CENTER];
  344. }
  345. if (isset($this->headerFooterImages[self::IMAGE_HEADER_RIGHT])) {
  346. $images[self::IMAGE_HEADER_RIGHT] = $this->headerFooterImages[self::IMAGE_HEADER_RIGHT];
  347. }
  348. if (isset($this->headerFooterImages[self::IMAGE_FOOTER_LEFT])) {
  349. $images[self::IMAGE_FOOTER_LEFT] = $this->headerFooterImages[self::IMAGE_FOOTER_LEFT];
  350. }
  351. if (isset($this->headerFooterImages[self::IMAGE_FOOTER_CENTER])) {
  352. $images[self::IMAGE_FOOTER_CENTER] = $this->headerFooterImages[self::IMAGE_FOOTER_CENTER];
  353. }
  354. if (isset($this->headerFooterImages[self::IMAGE_FOOTER_RIGHT])) {
  355. $images[self::IMAGE_FOOTER_RIGHT] = $this->headerFooterImages[self::IMAGE_FOOTER_RIGHT];
  356. }
  357. $this->headerFooterImages = $images;
  358. return $this->headerFooterImages;
  359. }
  360. /**
  361. * Implement PHP __clone to create a deep clone, not just a shallow copy.
  362. */
  363. public function __clone()
  364. {
  365. $vars = get_object_vars($this);
  366. foreach ($vars as $key => $value) {
  367. if (is_object($value)) {
  368. $this->$key = clone $value;
  369. } else {
  370. $this->$key = $value;
  371. }
  372. }
  373. }
  374. }