File Source for Style.php

PHPExcel_Writer_Excel2007

# Source for file Style.php

Documentation is available at Style.php

1. <?php
2. /**
3. * PHPExcel
4. *
5. * Copyright (c) 2006 - 2011 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_Writer_Excel2007
23. * @copyright Copyright (c) 2006 - 2011 PHPExcel (http://www.codeplex.com/PHPExcel)
24. * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
25. * @version 1.7.6, 2011-02-27
26. */
29. /**
30. * PHPExcel_Writer_Excel2007_Style
31. *
32. * @category PHPExcel
33. * @package PHPExcel_Writer_Excel2007
34. * @copyright Copyright (c) 2006 - 2011 PHPExcel (http://www.codeplex.com/PHPExcel)
35. */
36. class PHPExcel_Writer_Excel2007_Style extends PHPExcel_Writer_Excel2007_WriterPart
37. {
38. /**
39. * Write styles to XML format
40. *
41. * @param PHPExcel $pPHPExcel
42. * @return string XML Output
43. * @throws Exception
44. */
45. public function writeStyles(PHPExcel $pPHPExcel = null)
46. {
47. // Create XML writer
48. $objWriter = null;
49. if ($this-> getParentWriter()->getUseDiskCaching()) {
50. $objWriter = new PHPExcel_Shared_XMLWriter( PHPExcel_Shared_XMLWriter:: STORAGE_DISK, $this-> getParentWriter()->getDiskCachingDirectory());
51. } else {
52. $objWriter = new PHPExcel_Shared_XMLWriter( PHPExcel_Shared_XMLWriter:: STORAGE_MEMORY);
53. }
55. // XML header
56. $objWriter->startDocument('1.0','UTF-8','yes');
58. // styleSheet
59. $objWriter->startElement('styleSheet');
60. $objWriter->writeAttribute('xml:space', 'preserve');
61. $objWriter->writeAttribute('xmlns', 'http://schemas.openxmlformats.org/spreadsheetml/2006/main');
63. // numFmts
64. $objWriter->startElement('numFmts');
65. $objWriter->writeAttribute('count', $this-> getParentWriter()->getNumFmtHashTable()->count());
67. // numFmt
68. for ($i = 0; $i < $this-> getParentWriter()->getNumFmtHashTable()->count(); ++$i) {
69. $this->_writeNumFmt($objWriter, $this-> getParentWriter()->getNumFmtHashTable()->getByIndex($i), $i);
70. }
72. $objWriter->endElement();
74. // fonts
75. $objWriter->startElement('fonts');
76. $objWriter->writeAttribute('count', $this-> getParentWriter()->getFontHashTable()->count());
78. // font
79. for ($i = 0; $i < $this-> getParentWriter()->getFontHashTable()->count(); ++$i) {
80. $this->_writeFont($objWriter, $this-> getParentWriter()->getFontHashTable()->getByIndex($i));
81. }
83. $objWriter->endElement();
85. // fills
86. $objWriter->startElement('fills');
87. $objWriter->writeAttribute('count', $this-> getParentWriter()->getFillHashTable()->count());
89. // fill
90. for ($i = 0; $i < $this-> getParentWriter()->getFillHashTable()->count(); ++$i) {
91. $this->_writeFill($objWriter, $this-> getParentWriter()->getFillHashTable()->getByIndex($i));
92. }
94. $objWriter->endElement();
96. // borders
97. $objWriter->startElement('borders');
98. $objWriter->writeAttribute('count', $this-> getParentWriter()->getBordersHashTable()->count());
100. // border
101. for ($i = 0; $i < $this-> getParentWriter()->getBordersHashTable()->count(); ++$i) {
102. $this->_writeBorder($objWriter, $this-> getParentWriter()->getBordersHashTable()->getByIndex($i));
103. }
105. $objWriter->endElement();
107. // cellStyleXfs
108. $objWriter->startElement('cellStyleXfs');
109. $objWriter->writeAttribute('count', 1);
111. // xf
112. $objWriter->startElement('xf');
113. $objWriter->writeAttribute('numFmtId', 0);
114. $objWriter->writeAttribute('fontId', 0);
115. $objWriter->writeAttribute('fillId', 0);
116. $objWriter->writeAttribute('borderId', 0);
117. $objWriter->endElement();
119. $objWriter->endElement();
121. // cellXfs
122. $objWriter->startElement('cellXfs');
123. $objWriter->writeAttribute('count', count($pPHPExcel->getCellXfCollection()));
125. // xf
126. foreach ($pPHPExcel->getCellXfCollection() as $cellXf) {
127. $this->_writeCellStyleXf($objWriter, $cellXf, $pPHPExcel);
128. }
130. $objWriter->endElement();
132. // cellStyles
133. $objWriter->startElement('cellStyles');
134. $objWriter->writeAttribute('count', 1);
136. // cellStyle
137. $objWriter->startElement('cellStyle');
138. $objWriter->writeAttribute('name', 'Normal');
139. $objWriter->writeAttribute('xfId', 0);
140. $objWriter->writeAttribute('builtinId', 0);
141. $objWriter->endElement();
143. $objWriter->endElement();
145. // dxfs
146. $objWriter->startElement('dxfs');
147. $objWriter->writeAttribute('count', $this-> getParentWriter()->getStylesConditionalHashTable()->count());
149. // dxf
150. for ($i = 0; $i < $this-> getParentWriter()->getStylesConditionalHashTable()->count(); ++$i) {
151. $this->_writeCellStyleDxf($objWriter, $this-> getParentWriter()->getStylesConditionalHashTable()->getByIndex($i)->getStyle());
152. }
154. $objWriter->endElement();
156. // tableStyles
157. $objWriter->startElement('tableStyles');
158. $objWriter->writeAttribute('defaultTableStyle', 'TableStyleMedium9');
159. $objWriter->writeAttribute('defaultPivotStyle', 'PivotTableStyle1');
160. $objWriter->endElement();
162. $objWriter->endElement();
164. // Return
165. return $objWriter->getData();
166. }
168. /**
169. * Write Fill
170. *
171. * @param PHPExcel_Shared_XMLWriter $objWriter XML Writer
172. * @param PHPExcel_Style_Fill $pFill Fill style
173. * @throws Exception
174. */
175. private function _writeFill(PHPExcel_Shared_XMLWriter $objWriter = null, PHPExcel_Style_Fill $pFill = null)
176. {
177. // Check if this is a pattern type or gradient type
178. if ($pFill->getFillType() == PHPExcel_Style_Fill:: FILL_GRADIENT_LINEAR
179. || $pFill->getFillType() == PHPExcel_Style_Fill:: FILL_GRADIENT_PATH) {
180. // Gradient fill
181. $this->_writeGradientFill($objWriter, $pFill);
182. } else {
183. // Pattern fill
184. $this->_writePatternFill($objWriter, $pFill);
185. }
186. }
188. /**
189. * Write Gradient Fill
190. *
191. * @param PHPExcel_Shared_XMLWriter $objWriter XML Writer
192. * @param PHPExcel_Style_Fill $pFill Fill style
193. * @throws Exception
194. */
195. private function _writeGradientFill(PHPExcel_Shared_XMLWriter $objWriter = null, PHPExcel_Style_Fill $pFill = null)
196. {
197. // fill
198. $objWriter->startElement('fill');
200. // gradientFill
201. $objWriter->startElement('gradientFill');
202. $objWriter->writeAttribute('type', $pFill->getFillType());
203. $objWriter->writeAttribute('degree', $pFill->getRotation());
205. // stop
206. $objWriter->startElement('stop');
207. $objWriter->writeAttribute('position', '0');
209. // color
210. $objWriter->startElement('color');
211. $objWriter->writeAttribute('rgb', $pFill->getStartColor()->getARGB());
212. $objWriter->endElement();
214. $objWriter->endElement();
216. // stop
217. $objWriter->startElement('stop');
218. $objWriter->writeAttribute('position', '1');
220. // color
221. $objWriter->startElement('color');
222. $objWriter->writeAttribute('rgb', $pFill->getEndColor()->getARGB());
223. $objWriter->endElement();
225. $objWriter->endElement();
227. $objWriter->endElement();
229. $objWriter->endElement();
230. }
232. /**
233. * Write Pattern Fill
234. *
235. * @param PHPExcel_Shared_XMLWriter $objWriter XML Writer
236. * @param PHPExcel_Style_Fill $pFill Fill style
237. * @throws Exception
238. */
239. private function _writePatternFill(PHPExcel_Shared_XMLWriter $objWriter = null, PHPExcel_Style_Fill $pFill = null)
240. {
241. // fill
242. $objWriter->startElement('fill');
244. // patternFill
245. $objWriter->startElement('patternFill');
246. $objWriter->writeAttribute('patternType', $pFill->getFillType());
248. // fgColor
249. $objWriter->startElement('fgColor');
250. $objWriter->writeAttribute('rgb', $pFill->getStartColor()->getARGB());
251. $objWriter->endElement();
253. // bgColor
254. $objWriter->startElement('bgColor');
255. $objWriter->writeAttribute('rgb', $pFill->getEndColor()->getARGB());
256. $objWriter->endElement();
258. $objWriter->endElement();
260. $objWriter->endElement();
261. }
263. /**
264. * Write Font
265. *
266. * @param PHPExcel_Shared_XMLWriter $objWriter XML Writer
267. * @param PHPExcel_Style_Font $pFont Font style
268. * @throws Exception
269. */
270. private function _writeFont(PHPExcel_Shared_XMLWriter $objWriter = null, PHPExcel_Style_Font $pFont = null)
271. {
272. // font
273. $objWriter->startElement('font');
275. // Name
276. $objWriter->startElement('name');
277. $objWriter->writeAttribute('val', $pFont->getName());
278. $objWriter->endElement();
280. // Size
281. $objWriter->startElement('sz');
282. $objWriter->writeAttribute('val', $pFont->getSize());
283. $objWriter->endElement();
285. // Bold. We explicitly write this element also when false (like MS Office Excel 2007 does
286. // for conditional formatting). Otherwise it will apparently not be picked up in conditional
287. // formatting style dialog
288. $objWriter->startElement('b');
289. $objWriter->writeAttribute('val', $pFont->getBold() ? '1' : '0');
290. $objWriter->endElement();
292. // Italic
293. $objWriter->startElement('i');
294. $objWriter->writeAttribute('val', $pFont->getItalic() ? '1' : '0');
295. $objWriter->endElement();
297. // Superscript / subscript
298. if ($pFont->getSuperScript() || $pFont->getSubScript()) {
299. $objWriter->startElement('vertAlign');
300. if ($pFont->getSuperScript()) {
301. $objWriter->writeAttribute('val', 'superscript');
302. } else if ($pFont->getSubScript()) {
303. $objWriter->writeAttribute('val', 'subscript');
304. }
305. $objWriter->endElement();
306. }
308. // Underline
309. $objWriter->startElement('u');
310. $objWriter->writeAttribute('val', $pFont->getUnderline());
311. $objWriter->endElement();
313. // Strikethrough
314. $objWriter->startElement('strike');
315. $objWriter->writeAttribute('val', $pFont->getStrikethrough() ? '1' : '0');
316. $objWriter->endElement();
318. // Foreground color
319. $objWriter->startElement('color');
320. $objWriter->writeAttribute('rgb', $pFont->getColor()->getARGB());
321. $objWriter->endElement();
323. $objWriter->endElement();
324. }
326. /**
327. * Write Border
328. *
329. * @param PHPExcel_Shared_XMLWriter $objWriter XML Writer
330. * @param PHPExcel_Style_Borders $pBorders Borders style
331. * @throws Exception
332. */
333. private function _writeBorder(PHPExcel_Shared_XMLWriter $objWriter = null, PHPExcel_Style_Borders $pBorders = null)
334. {
335. // Write border
336. $objWriter->startElement('border');
337. // Diagonal?
338. switch ($pBorders->getDiagonalDirection()) {
339. case PHPExcel_Style_Borders:: DIAGONAL_UP:
340. $objWriter->writeAttribute('diagonalUp', 'true');
341. $objWriter->writeAttribute('diagonalDown', 'false');
342. break;
343. case PHPExcel_Style_Borders:: DIAGONAL_DOWN:
344. $objWriter->writeAttribute('diagonalUp', 'false');
345. $objWriter->writeAttribute('diagonalDown', 'true');
346. break;
347. case PHPExcel_Style_Borders:: DIAGONAL_BOTH:
348. $objWriter->writeAttribute('diagonalUp', 'true');
349. $objWriter->writeAttribute('diagonalDown', 'true');
350. break;
351. }
353. // BorderPr
354. $this->_writeBorderPr($objWriter, 'left', $pBorders->getLeft());
355. $this->_writeBorderPr($objWriter, 'right', $pBorders->getRight());
356. $this->_writeBorderPr($objWriter, 'top', $pBorders->getTop());
357. $this->_writeBorderPr($objWriter, 'bottom', $pBorders->getBottom());
358. $this->_writeBorderPr($objWriter, 'diagonal', $pBorders->getDiagonal());
359. $objWriter->endElement();
360. }
362. /**
363. * Write Cell Style Xf
364. *
365. * @param PHPExcel_Shared_XMLWriter $objWriter XML Writer
366. * @param PHPExcel_Style $pStyle Style
367. * @param PHPExcel $pPHPExcel Workbook
368. * @throws Exception
369. */
370. private function _writeCellStyleXf(PHPExcel_Shared_XMLWriter $objWriter = null, PHPExcel_Style $pStyle = null, PHPExcel $pPHPExcel = null)
371. {
372. // xf
373. $objWriter->startElement('xf');
374. $objWriter->writeAttribute('xfId', 0);
375. $objWriter->writeAttribute('fontId', (int)$this-> getParentWriter()->getFontHashTable()->getIndexForHashCode($pStyle->getFont()->getHashCode()));
377. if ($pStyle->getNumberFormat()->getBuiltInFormatCode() === false) {
378. $objWriter->writeAttribute('numFmtId', (int)($this-> getParentWriter()->getNumFmtHashTable()->getIndexForHashCode($pStyle->getNumberFormat()->getHashCode()) + 164) );
379. } else {
380. $objWriter->writeAttribute('numFmtId', (int)$pStyle->getNumberFormat()->getBuiltInFormatCode());
381. }
383. $objWriter->writeAttribute('fillId', (int)$this-> getParentWriter()->getFillHashTable()->getIndexForHashCode($pStyle->getFill()->getHashCode()));
384. $objWriter->writeAttribute('borderId', (int)$this-> getParentWriter()->getBordersHashTable()->getIndexForHashCode($pStyle->getBorders()->getHashCode()));
386. // Apply styles?
387. $objWriter->writeAttribute('applyFont', ($pPHPExcel->getDefaultStyle()->getFont()->getHashCode() != $pStyle->getFont()->getHashCode()) ? '1' : '0');
388. $objWriter->writeAttribute('applyNumberFormat', ($pPHPExcel->getDefaultStyle()->getNumberFormat()->getHashCode() != $pStyle->getNumberFormat()->getHashCode()) ? '1' : '0');
389. $objWriter->writeAttribute('applyFill', ($pPHPExcel->getDefaultStyle()->getFill()->getHashCode() != $pStyle->getFill()->getHashCode()) ? '1' : '0');
390. $objWriter->writeAttribute('applyBorder', ($pPHPExcel->getDefaultStyle()->getBorders()->getHashCode() != $pStyle->getBorders()->getHashCode()) ? '1' : '0');
391. $objWriter->writeAttribute('applyAlignment', ($pPHPExcel->getDefaultStyle()->getAlignment()->getHashCode() != $pStyle->getAlignment()->getHashCode()) ? '1' : '0');
392. if ($pStyle->getProtection()->getLocked() != PHPExcel_Style_Protection:: PROTECTION_INHERIT || $pStyle->getProtection()->getHidden() != PHPExcel_Style_Protection:: PROTECTION_INHERIT) {
393. $objWriter->writeAttribute('applyProtection', 'true');
394. }
396. // alignment
397. $objWriter->startElement('alignment');
398. $objWriter->writeAttribute('horizontal', $pStyle->getAlignment()->getHorizontal());
399. $objWriter->writeAttribute('vertical', $pStyle->getAlignment()->getVertical());
401. $textRotation = 0;
402. if ($pStyle->getAlignment()->getTextRotation() >= 0) {
403. $textRotation = $pStyle->getAlignment()->getTextRotation();
404. } else if ($pStyle->getAlignment()->getTextRotation() < 0) {
405. $textRotation = 90 - $pStyle->getAlignment()->getTextRotation();
406. }
408. $objWriter->writeAttribute('textRotation', $textRotation);
409. $objWriter->writeAttribute('wrapText', ($pStyle->getAlignment()->getWrapText() ? 'true' : 'false'));
410. $objWriter->writeAttribute('shrinkToFit', ($pStyle->getAlignment()->getShrinkToFit() ? 'true' : 'false'));
412. if ($pStyle->getAlignment()->getIndent() > 0) {
413. $objWriter->writeAttribute('indent', $pStyle->getAlignment()->getIndent());
414. }
415. $objWriter->endElement();
417. // protection
418. if ($pStyle->getProtection()->getLocked() != PHPExcel_Style_Protection:: PROTECTION_INHERIT || $pStyle->getProtection()->getHidden() != PHPExcel_Style_Protection:: PROTECTION_INHERIT) {
419. $objWriter->startElement('protection');
420. if ($pStyle->getProtection()->getLocked() != PHPExcel_Style_Protection:: PROTECTION_INHERIT) {
421. $objWriter->writeAttribute('locked', ($pStyle->getProtection()->getLocked() == PHPExcel_Style_Protection:: PROTECTION_PROTECTED ? 'true' : 'false'));
422. }
423. if ($pStyle->getProtection()->getHidden() != PHPExcel_Style_Protection:: PROTECTION_INHERIT) {
424. $objWriter->writeAttribute('hidden', ($pStyle->getProtection()->getHidden() == PHPExcel_Style_Protection:: PROTECTION_PROTECTED ? 'true' : 'false'));
425. }
426. $objWriter->endElement();
427. }
429. $objWriter->endElement();
430. }
432. /**
433. * Write Cell Style Dxf
434. *
435. * @param PHPExcel_Shared_XMLWriter $objWriter XML Writer
436. * @param PHPExcel_Style $pStyle Style
437. * @throws Exception
438. */
439. private function _writeCellStyleDxf(PHPExcel_Shared_XMLWriter $objWriter = null, PHPExcel_Style $pStyle = null)
440. {
441. // dxf
442. $objWriter->startElement('dxf');
444. // font
445. $this->_writeFont($objWriter, $pStyle->getFont());
447. // numFmt
448. $this->_writeNumFmt($objWriter, $pStyle->getNumberFormat());
450. // fill
451. $this->_writeFill($objWriter, $pStyle->getFill());
453. // alignment
454. $objWriter->startElement('alignment');
455. $objWriter->writeAttribute('horizontal', $pStyle->getAlignment()->getHorizontal());
456. $objWriter->writeAttribute('vertical', $pStyle->getAlignment()->getVertical());
458. $textRotation = 0;
459. if ($pStyle->getAlignment()->getTextRotation() >= 0) {
460. $textRotation = $pStyle->getAlignment()->getTextRotation();
461. } else if ($pStyle->getAlignment()->getTextRotation() < 0) {
462. $textRotation = 90 - $pStyle->getAlignment()->getTextRotation();
463. }
465. $objWriter->writeAttribute('textRotation', $textRotation);
466. $objWriter->endElement();
468. // border
469. $this->_writeBorder($objWriter, $pStyle->getBorders());
471. // protection
472. if ($pStyle->getProtection()->getLocked() != PHPExcel_Style_Protection:: PROTECTION_INHERIT || $pStyle->getProtection()->getHidden() != PHPExcel_Style_Protection:: PROTECTION_INHERIT) {
473. $objWriter->startElement('protection');
474. if ($pStyle->getProtection()->getLocked() != PHPExcel_Style_Protection:: PROTECTION_INHERIT) {
475. $objWriter->writeAttribute('locked', ($pStyle->getProtection()->getLocked() == PHPExcel_Style_Protection:: PROTECTION_PROTECTED ? 'true' : 'false'));
476. }
477. if ($pStyle->getProtection()->getHidden() != PHPExcel_Style_Protection:: PROTECTION_INHERIT) {
478. $objWriter->writeAttribute('hidden', ($pStyle->getProtection()->getHidden() == PHPExcel_Style_Protection:: PROTECTION_PROTECTED ? 'true' : 'false'));
479. }
480. $objWriter->endElement();
481. }
483. $objWriter->endElement();
484. }
486. /**
487. * Write BorderPr
488. *
489. * @param PHPExcel_Shared_XMLWriter $objWriter XML Writer
490. * @param string $pName Element name
491. * @param PHPExcel_Style_Border $pBorder Border style
492. * @throws Exception
493. */
494. private function _writeBorderPr(PHPExcel_Shared_XMLWriter $objWriter = null, $pName = 'left', PHPExcel_Style_Border $pBorder = null)
495. {
496. // Write BorderPr
497. if ($pBorder->getBorderStyle() != PHPExcel_Style_Border:: BORDER_NONE) {
498. $objWriter->startElement($pName);
499. $objWriter->writeAttribute('style', $pBorder->getBorderStyle());
501. // color
502. $objWriter->startElement('color');
503. $objWriter->writeAttribute('rgb', $pBorder->getColor()->getARGB());
504. $objWriter->endElement();
506. $objWriter->endElement();
507. }
508. }
510. /**
511. * Write NumberFormat
512. *
513. * @param PHPExcel_Shared_XMLWriter $objWriter XML Writer
514. * @param PHPExcel_Style_NumberFormat $pNumberFormat Number Format
515. * @param int $pId Number Format identifier
516. * @throws Exception
517. */
518. private function _writeNumFmt(PHPExcel_Shared_XMLWriter $objWriter = null, PHPExcel_Style_NumberFormat $pNumberFormat = null, $pId = 0)
519. {
520. // Translate formatcode
521. $formatCode = $pNumberFormat->getFormatCode();
523. // numFmt
524. $objWriter->startElement('numFmt');
525. $objWriter->writeAttribute('numFmtId', ($pId + 164));
526. $objWriter->writeAttribute('formatCode', $formatCode);
527. $objWriter->endElement();
528. }
530. /**
531. * Get an array of all styles
532. *
533. * @param PHPExcel $pPHPExcel
534. * @return PHPExcel_Style[] All styles in PHPExcel
535. * @throws Exception
536. */
537. public function allStyles(PHPExcel $pPHPExcel = null)
538. {
539. $aStyles = $pPHPExcel->getCellXfCollection();
541. return $aStyles;
542. }
544. /**
545. * Get an array of all conditional styles
546. *
547. * @param PHPExcel $pPHPExcel
548. * @return PHPExcel_Style_Conditional[] All conditional styles in PHPExcel
549. * @throws Exception
550. */
551. public function allConditionalStyles(PHPExcel $pPHPExcel = null)
552. {
553. // Get an array of all styles
554. $aStyles = array();
556. $sheetCount = $pPHPExcel->getSheetCount();
557. for ($i = 0; $i < $sheetCount; ++$i) {
558. foreach ($pPHPExcel->getSheet($i)->getConditionalStylesCollection() as $conditionalStyles) {
559. foreach ($conditionalStyles as $conditionalStyle) {
560. $aStyles[] = $conditionalStyle;
561. }
562. }
563. }
565. return $aStyles;
566. }
568. /**
569. * Get an array of all fills
570. *
571. * @param PHPExcel $pPHPExcel
572. * @return PHPExcel_Style_Fill[] All fills in PHPExcel
573. * @throws Exception
574. */
575. public function allFills(PHPExcel $pPHPExcel = null)
576. {
577. // Get an array of unique fills
578. $aFills = array();
580. // Two first fills are predefined
581. $fill0 = new PHPExcel_Style_Fill();
582. $fill0->setFillType( PHPExcel_Style_Fill:: FILL_NONE);
583. $aFills[] = $fill0;
585. $fill1 = new PHPExcel_Style_Fill();
586. $fill1->setFillType( PHPExcel_Style_Fill:: FILL_PATTERN_GRAY125);
587. $aFills[] = $fill1;
589. // The remaining fills
590. $aStyles = $this-> allStyles($pPHPExcel);
591. foreach ($aStyles as $style) {
592. if (! array_key_exists($style->getFill()->getHashCode(), $aFills)) {
593. $aFills[ $style->getFill()->getHashCode() ] = $style->getFill();
594. }
595. }
597. return $aFills;
598. }
600. /**
601. * Get an array of all fonts
602. *
603. * @param PHPExcel $pPHPExcel
604. * @return PHPExcel_Style_Font[] All fonts in PHPExcel
605. * @throws Exception
606. */
607. public function allFonts(PHPExcel $pPHPExcel = null)
608. {
609. // Get an array of unique fonts
610. $aFonts = array();
611. $aStyles = $this-> allStyles($pPHPExcel);
613. foreach ($aStyles as $style) {
614. if (! array_key_exists($style->getFont()->getHashCode(), $aFonts)) {
615. $aFonts[ $style->getFont()->getHashCode() ] = $style->getFont();
616. }
617. }
619. return $aFonts;
620. }
622. /**
623. * Get an array of all borders
624. *
625. * @param PHPExcel $pPHPExcel
626. * @return PHPExcel_Style_Borders[] All borders in PHPExcel
627. * @throws Exception
628. */
629. public function allBorders(PHPExcel $pPHPExcel = null)
630. {
631. // Get an array of unique borders
632. $aBorders = array();
633. $aStyles = $this-> allStyles($pPHPExcel);
635. foreach ($aStyles as $style) {
636. if (! array_key_exists($style->getBorders()->getHashCode(), $aBorders)) {
637. $aBorders[ $style->getBorders()->getHashCode() ] = $style->getBorders();
638. }
639. }
641. return $aBorders;
642. }
644. /**
645. * Get an array of all number formats
646. *
647. * @param PHPExcel $pPHPExcel
648. * @return PHPExcel_Style_NumberFormat[] All number formats in PHPExcel
649. * @throws Exception
650. */
651. public function allNumberFormats(PHPExcel $pPHPExcel = null)
652. {
653. // Get an array of unique number formats
654. $aNumFmts = array();
655. $aStyles = $this-> allStyles($pPHPExcel);
657. foreach ($aStyles as $style) {
658. if ($style->getNumberFormat()->getBuiltInFormatCode() === false && ! array_key_exists($style->getNumberFormat()->getHashCode(), $aNumFmts)) {
659. $aNumFmts[ $style->getNumberFormat()->getHashCode() ] = $style->getNumberFormat();
660. }
661. }
663. return $aNumFmts;
664. }
665. }

Documentation generated on Sun, 27 Feb 2011 16:34:18 -0800 by phpDocumentor 1.4.3