/branches/v1.3.0/Classes/PHPExcel/Writer/Excel2007/Style.php

# · PHP · 747 lines · 390 code · 118 blank · 239 comment · 68 complexity · fd41ae2dc320a2b5a64394278ecf6505 MD5 · raw file

  1. <?php
  2. /**
  3. * PHPExcel
  4. *
  5. * Copyright (c) 2006 - 2007 PHPExcel, Maarten Balliauw
  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 - 2007 PHPExcel (http://www.codeplex.com/PHPExcel)
  24. * @license http://www.gnu.org/licenses/lgpl.txt LGPL
  25. * @version ##VERSION##, ##DATE##
  26. */
  27. /** PHPExcel */
  28. require_once 'PHPExcel.php';
  29. /** PHPExcel_Writer_Excel2007 */
  30. require_once 'PHPExcel/Writer/Excel2007.php';
  31. /** PHPExcel_Writer_Excel2007_WriterPart */
  32. require_once 'PHPExcel/Writer/Excel2007/WriterPart.php';
  33. /** PHPExcel_Style */
  34. require_once 'PHPExcel/Style.php';
  35. /** PHPExcel_Style_Borders */
  36. require_once 'PHPExcel/Style/Borders.php';
  37. /** PHPExcel_Style_Border */
  38. require_once 'PHPExcel/Style/Border.php';
  39. /** PHPExcel_Style_Color */
  40. require_once 'PHPExcel/Style/Color.php';
  41. /** PHPExcel_Style_Fill */
  42. require_once 'PHPExcel/Style/Fill.php';
  43. /** PHPExcel_Style_Font */
  44. require_once 'PHPExcel/Style/Font.php';
  45. /** PHPExcel_Style_NumberFormat */
  46. require_once 'PHPExcel/Style/NumberFormat.php';
  47. /** PHPExcel_Style_Conditional */
  48. require_once 'PHPExcel/Style/Conditional.php';
  49. /**
  50. * PHPExcel_Writer_Excel2007_Style
  51. *
  52. * @category PHPExcel
  53. * @package PHPExcel_Writer_Excel2007
  54. * @copyright Copyright (c) 2006 - 2007 PHPExcel (http://www.codeplex.com/PHPExcel)
  55. */
  56. class PHPExcel_Writer_Excel2007_Style extends PHPExcel_Writer_Excel2007_WriterPart
  57. {
  58. /**
  59. * Write styles to XML format
  60. *
  61. * @param PHPExcel $pPHPExcel
  62. * @return string XML Output
  63. * @throws Exception
  64. */
  65. public function writeStyles($pPHPExcel = null)
  66. {
  67. if ($pPHPExcel instanceof PHPExcel) {
  68. // Create XML writer
  69. $objWriter = new xmlWriter();
  70. $objWriter->openMemory();
  71. // XML header
  72. $objWriter->startDocument('1.0','UTF-8','yes');
  73. // styleSheet
  74. $objWriter->startElement('styleSheet');
  75. $objWriter->writeAttribute('xml:space', 'preserve');
  76. $objWriter->writeAttribute('xmlns', 'http://schemas.openxmlformats.org/spreadsheetml/2006/main');
  77. // numFmts
  78. $objWriter->startElement('numFmts');
  79. $objWriter->writeAttribute('count', $this->getParentWriter()->getNumFmtHashTable()->count());
  80. // numFmt
  81. for ($i = 0; $i < $this->getParentWriter()->getNumFmtHashTable()->count(); $i++) {
  82. $this->_writeNumFmt($objWriter, $this->getParentWriter()->getNumFmtHashTable()->getByIndex($i), $i);
  83. }
  84. $objWriter->endElement();
  85. // fonts
  86. $objWriter->startElement('fonts');
  87. $objWriter->writeAttribute('count', $this->getParentWriter()->getFontHashTable()->count());
  88. // font
  89. for ($i = 0; $i < $this->getParentWriter()->getFontHashTable()->count(); $i++) {
  90. $this->_writeFont($objWriter, $this->getParentWriter()->getFontHashTable()->getByIndex($i));
  91. }
  92. $objWriter->endElement();
  93. // fills
  94. $objWriter->startElement('fills');
  95. $objWriter->writeAttribute('count', $this->getParentWriter()->getFillHashTable()->count());
  96. // fill
  97. for ($i = 0; $i < $this->getParentWriter()->getFillHashTable()->count(); $i++) {
  98. $this->_writeFill($objWriter, $this->getParentWriter()->getFillHashTable()->getByIndex($i));
  99. }
  100. $objWriter->endElement();
  101. // borders
  102. $objWriter->startElement('borders');
  103. $objWriter->writeAttribute('count', $this->getParentWriter()->getBordersHashTable()->count());
  104. // border
  105. for ($i = 0; $i < $this->getParentWriter()->getBordersHashTable()->count(); $i++) {
  106. $this->_writeBorder($objWriter, $this->getParentWriter()->getBordersHashTable()->getByIndex($i));
  107. }
  108. $objWriter->endElement();
  109. // cellStyleXfs
  110. $objWriter->startElement('cellStyleXfs');
  111. $objWriter->writeAttribute('count', $this->getParentWriter()->getStylesHashTable()->count());
  112. // xf
  113. for ($i = 0; $i < $this->getParentWriter()->getStylesHashTable()->count(); $i++) {
  114. $this->_writeCellStyleXf($objWriter, $this->getParentWriter()->getStylesHashTable()->getByIndex($i));
  115. }
  116. $objWriter->endElement();
  117. // cellXfs
  118. $objWriter->startElement('cellXfs');
  119. $objWriter->writeAttribute('count', $this->getParentWriter()->getStylesHashTable()->count());
  120. // xf
  121. for ($i = 0; $i < $this->getParentWriter()->getStylesHashTable()->count(); $i++) {
  122. $this->_writeCellStyleXf($objWriter, $this->getParentWriter()->getStylesHashTable()->getByIndex($i));
  123. }
  124. $objWriter->endElement();
  125. // cellStyles
  126. $objWriter->startElement('cellStyles');
  127. $objWriter->writeAttribute('count', $this->getParentWriter()->getStylesHashTable()->count());
  128. // cellStyle
  129. for ($i = 0; $i < $this->getParentWriter()->getStylesHashTable()->count(); $i++) {
  130. $this->_writeCellStyle($objWriter, $i);
  131. }
  132. $objWriter->endElement();
  133. // dxfs
  134. $objWriter->startElement('dxfs');
  135. $objWriter->writeAttribute('count', $this->getParentWriter()->getStylesConditionalHashTable()->count());
  136. // dxf
  137. for ($i = 0; $i < $this->getParentWriter()->getStylesConditionalHashTable()->count(); $i++) {
  138. $this->_writeCellStyleDxf($objWriter, $this->getParentWriter()->getStylesConditionalHashTable()->getByIndex($i)->getStyle());
  139. }
  140. $objWriter->endElement();
  141. // tableStyles
  142. $objWriter->startElement('tableStyles');
  143. $objWriter->writeAttribute('defaultTableStyle', 'TableStyleMedium9');
  144. $objWriter->writeAttribute('defaultPivotStyle', 'PivotTableStyle1');
  145. $objWriter->endElement();
  146. // colors
  147. $objWriter->startElement('colors');
  148. // indexedColors
  149. $objWriter->startElement('indexedColors');
  150. // rgbColor
  151. $objWriter->startElement('rgbColor');
  152. $objWriter->writeAttribute('rgb', '00000000');
  153. $objWriter->endElement();
  154. // rgbColor
  155. $objWriter->startElement('rgbColor');
  156. $objWriter->writeAttribute('rgb', '00FFFFFF');
  157. $objWriter->endElement();
  158. // rgbColor
  159. $objWriter->startElement('rgbColor');
  160. $objWriter->writeAttribute('rgb', '00FF0000');
  161. $objWriter->endElement();
  162. // rgbColor
  163. $objWriter->startElement('rgbColor');
  164. $objWriter->writeAttribute('rgb', '0000FF00');
  165. $objWriter->endElement();
  166. // rgbColor
  167. $objWriter->startElement('rgbColor');
  168. $objWriter->writeAttribute('rgb', '000000FF');
  169. $objWriter->endElement();
  170. // rgbColor
  171. $objWriter->startElement('rgbColor');
  172. $objWriter->writeAttribute('rgb', '00FFFF00');
  173. $objWriter->endElement();
  174. // rgbColor
  175. $objWriter->startElement('rgbColor');
  176. $objWriter->writeAttribute('rgb', '00FF00FF');
  177. $objWriter->endElement();
  178. // rgbColor
  179. $objWriter->startElement('rgbColor');
  180. $objWriter->writeAttribute('rgb', '0000FFFF');
  181. $objWriter->endElement();
  182. $objWriter->endElement();
  183. $objWriter->endElement();
  184. $objWriter->endElement();
  185. // Return
  186. return $objWriter->outputMemory(true);
  187. } else {
  188. throw new Exception("Invalid PHPExcel object passed.");
  189. }
  190. }
  191. /**
  192. * Write Fill
  193. *
  194. * @param xmlWriter $objWriter XML Writer
  195. * @param PHPExcel_Style_Fill $pFill Fill style
  196. * @throws Exception
  197. */
  198. private function _writeFill($objWriter = null, $pFill = null)
  199. {
  200. if ($objWriter instanceof xmlWriter && $pFill instanceof PHPExcel_Style_Fill) {
  201. // Check if this is a pattern type or gradient type
  202. if ($pFill->getFillType() == PHPExcel_Style_Fill::FILL_GRADIENT_LINEAR
  203. || $pFill->getFillType() == PHPExcel_Style_Fill::FILL_GRADIENT_PATH) {
  204. // Gradient fill
  205. $this->_writeGradientFill($objWriter, $pFill);
  206. } else {
  207. // Pattern fill
  208. $this->_writePatternFill($objWriter, $pFill);
  209. }
  210. } else {
  211. throw new Exception("Invalid parameters passed.");
  212. }
  213. }
  214. /**
  215. * Write Gradient Fill
  216. *
  217. * @param xmlWriter $objWriter XML Writer
  218. * @param PHPExcel_Style_Fill $pFill Fill style
  219. * @throws Exception
  220. */
  221. private function _writeGradientFill($objWriter = null, $pFill = null)
  222. {
  223. if ($objWriter instanceof xmlWriter && $pFill instanceof PHPExcel_Style_Fill) {
  224. // fill
  225. $objWriter->startElement('fill');
  226. // gradientFill
  227. $objWriter->startElement('gradientFill');
  228. $objWriter->writeAttribute('type', $pFill->getFillType());
  229. $objWriter->writeAttribute('degree', $pFill->getRotation());
  230. // stop
  231. $objWriter->startElement('stop');
  232. $objWriter->writeAttribute('position', '0');
  233. // color
  234. $objWriter->startElement('color');
  235. $objWriter->writeAttribute('rgb', $pFill->getStartColor()->getARGB());
  236. $objWriter->endElement();
  237. $objWriter->endElement();
  238. // stop
  239. $objWriter->startElement('stop');
  240. $objWriter->writeAttribute('position', '1');
  241. // color
  242. $objWriter->startElement('color');
  243. $objWriter->writeAttribute('rgb', $pFill->getEndColor()->getARGB());
  244. $objWriter->endElement();
  245. $objWriter->endElement();
  246. $objWriter->endElement();
  247. $objWriter->endElement();
  248. } else {
  249. throw new Exception("Invalid parameters passed.");
  250. }
  251. }
  252. /**
  253. * Write Pattern Fill
  254. *
  255. * @param xmlWriter $objWriter XML Writer
  256. * @param PHPExcel_Style_Fill $pFill Fill style
  257. * @throws Exception
  258. */
  259. private function _writePatternFill($objWriter = null, $pFill = null)
  260. {
  261. if ($objWriter instanceof xmlWriter && $pFill instanceof PHPExcel_Style_Fill) {
  262. // fill
  263. $objWriter->startElement('fill');
  264. // patternFill
  265. $objWriter->startElement('patternFill');
  266. $objWriter->writeAttribute('patternType', $pFill->getFillType());
  267. // If no fill is selected, there is no need for color information
  268. if ($pFill->getFillType() != 'none') {
  269. // fgColor
  270. $objWriter->startElement('fgColor');
  271. $objWriter->writeAttribute('rgb', $pFill->getStartColor()->getARGB());
  272. $objWriter->endElement();
  273. // bgColor
  274. $objWriter->startElement('bgColor');
  275. $objWriter->writeAttribute('rgb', $pFill->getEndColor()->getARGB());
  276. $objWriter->endElement();
  277. }
  278. $objWriter->endElement();
  279. $objWriter->endElement();
  280. } else {
  281. throw new Exception("Invalid parameters passed.");
  282. }
  283. }
  284. /**
  285. * Write Font
  286. *
  287. * @param xmlWriter $objWriter XML Writer
  288. * @param PHPExcel_Style_Font $pFont Font style
  289. * @throws Exception
  290. */
  291. private function _writeFont($objWriter = null, $pFont = null)
  292. {
  293. if ($objWriter instanceof xmlWriter && $pFont instanceof PHPExcel_Style_Font) {
  294. // font
  295. $objWriter->startElement('font');
  296. // Name
  297. $objWriter->startElement('name');
  298. $objWriter->writeAttribute('val', $pFont->getName());
  299. $objWriter->endElement();
  300. // Size
  301. $objWriter->startElement('sz');
  302. $objWriter->writeAttribute('val', $pFont->getSize());
  303. $objWriter->endElement();
  304. // Bold
  305. $objWriter->startElement('b');
  306. $objWriter->writeAttribute('val', ($pFont->getBold() ? 'true' : 'false'));
  307. $objWriter->endElement();
  308. // Italic
  309. $objWriter->startElement('i');
  310. $objWriter->writeAttribute('val', ($pFont->getItalic() ? 'true' : 'false'));
  311. $objWriter->endElement();
  312. // Underline
  313. $objWriter->startElement('u');
  314. $objWriter->writeAttribute('val', $pFont->getUnderline());
  315. $objWriter->endElement();
  316. // Striketrough
  317. $objWriter->startElement('strike');
  318. $objWriter->writeAttribute('val', ($pFont->getStriketrough() ? 'true' : 'false'));
  319. $objWriter->endElement();
  320. // Foreground color
  321. $objWriter->startElement('color');
  322. $objWriter->writeAttribute('rgb', $pFont->getColor()->getARGB());
  323. $objWriter->endElement();
  324. $objWriter->endElement();
  325. } else {
  326. throw new Exception("Invalid parameters passed.");
  327. }
  328. }
  329. /**
  330. * Write Border
  331. *
  332. * @param xmlWriter $objWriter XML Writer
  333. * @param PHPExcel_Style_Borders $pBorders Borders style
  334. * @throws Exception
  335. */
  336. private function _writeBorder($objWriter = null, $pBorders = null)
  337. {
  338. if ($objWriter instanceof xmlWriter && $pBorders instanceof PHPExcel_Style_Borders) {
  339. // Write border
  340. $objWriter->startElement('border');
  341. // Diagonal?
  342. switch ($pBorders->getDiagonalDirection()) {
  343. case PHPExcel_Style_Borders::DIAGONAL_UP:
  344. $objWriter->writeAttribute('diagonalUp', 'true');
  345. $objWriter->writeAttribute('diagonalDown', 'false');
  346. break;
  347. case PHPExcel_Style_Borders::DIAGONAL_DOWN:
  348. $objWriter->writeAttribute('diagonalUp', 'false');
  349. $objWriter->writeAttribute('diagonalDown', 'true');
  350. break;
  351. }
  352. // Outline?
  353. $objWriter->writeAttribute('outline', ($pBorders->getOutline() ? 'true' : 'false'));
  354. // BorderPr
  355. $this->_writeBorderPr($objWriter, 'left', $pBorders->getLeft());
  356. $this->_writeBorderPr($objWriter, 'right', $pBorders->getRight());
  357. $this->_writeBorderPr($objWriter, 'top', $pBorders->getTop());
  358. $this->_writeBorderPr($objWriter, 'bottom', $pBorders->getBottom());
  359. $this->_writeBorderPr($objWriter, 'diagonal', $pBorders->getDiagonal());
  360. $this->_writeBorderPr($objWriter, 'vertical', $pBorders->getVertical());
  361. $this->_writeBorderPr($objWriter, 'horizontal', $pBorders->getHorizontal());
  362. $objWriter->endElement();
  363. } else {
  364. throw new Exception("Invalid parameters passed.");
  365. }
  366. }
  367. /**
  368. * Write Cell Style Xf
  369. *
  370. * @param xmlWriter $objWriter XML Writer
  371. * @param PHPExcel_Style $pStyle Style
  372. * @throws Exception
  373. */
  374. private function _writeCellStyleXf($objWriter = null, $pStyle = null)
  375. {
  376. if ($objWriter instanceof xmlWriter && $pStyle instanceof PHPExcel_Style) {
  377. // xf
  378. $objWriter->startElement('xf');
  379. $objWriter->writeAttribute('fontId', $this->getParentWriter()->getFontHashTable()->getIndexForHashCode($pStyle->getFont()->getHashCode()));
  380. $objWriter->writeAttribute('numFmtId', ($this->getParentWriter()->getNumFmtHashTable()->getIndexForHashCode($pStyle->getNumberFormat()->getHashCode()) + 164) );
  381. $objWriter->writeAttribute('fillId', $this->getParentWriter()->getFillHashTable()->getIndexForHashCode($pStyle->getFill()->getHashCode()));
  382. $objWriter->writeAttribute('borderId', $this->getParentWriter()->getBordersHashTable()->getIndexForHashCode($pStyle->getBorders()->getHashCode()));
  383. // alignment
  384. $objWriter->startElement('alignment');
  385. $objWriter->writeAttribute('horizontal', $pStyle->getAlignment()->getHorizontal());
  386. $objWriter->writeAttribute('vertical', $pStyle->getAlignment()->getVertical());
  387. $objWriter->writeAttribute('textRotation', $pStyle->getAlignment()->getTextRotation());
  388. $objWriter->writeAttribute('wrapText', ($pStyle->getAlignment()->getWrapText() ? 'true' : 'false'));
  389. $objWriter->endElement();
  390. $objWriter->endElement();
  391. } else {
  392. throw new Exception("Invalid parameters passed.");
  393. }
  394. }
  395. /**
  396. * Write Cell Style Dxf
  397. *
  398. * @param xmlWriter $objWriter XML Writer
  399. * @param PHPExcel_Style $pStyle Style
  400. * @throws Exception
  401. */
  402. private function _writeCellStyleDxf($objWriter = null, $pStyle = null)
  403. {
  404. if ($objWriter instanceof xmlWriter && $pStyle instanceof PHPExcel_Style) {
  405. // dxf
  406. $objWriter->startElement('dxf');
  407. // font
  408. $this->_writeFont($objWriter, $pStyle->getFont());
  409. // numFmt
  410. $this->_writeNumFmt($objWriter, $pStyle->getNumberFormat());
  411. // fill
  412. $this->_writeFill($objWriter, $pStyle->getFill());
  413. // alignment
  414. $objWriter->startElement('alignment');
  415. $objWriter->writeAttribute('horizontal', $pStyle->getAlignment()->getHorizontal());
  416. $objWriter->writeAttribute('vertical', $pStyle->getAlignment()->getVertical());
  417. $objWriter->writeAttribute('textRotation', $pStyle->getAlignment()->getTextRotation());
  418. $objWriter->endElement();
  419. // border
  420. $this->_writeBorder($objWriter, $pStyle->getBorders());
  421. $objWriter->endElement();
  422. } else {
  423. throw new Exception("Invalid parameters passed.");
  424. }
  425. }
  426. /**
  427. * Write Cell Style
  428. *
  429. * @param xmlWriter $objWriter XML Writer
  430. * @param int $pId Cell style xf identifier
  431. * @throws Exception
  432. */
  433. private function _writeCellStyle($objWriter = null, $pId = 0)
  434. {
  435. if ($objWriter instanceof xmlWriter) {
  436. // cellStyle
  437. $objWriter->startElement('cellStyle');
  438. $objWriter->writeAttribute('xfId', $pId);
  439. $objWriter->endElement();
  440. } else {
  441. throw new Exception("Invalid parameters passed.");
  442. }
  443. }
  444. /**
  445. * Write BorderPr
  446. *
  447. * @param xmlWriter $objWriter XML Writer
  448. * @param string $pName Element name
  449. * @param PHPExcel_Style_Border $pBorder Border style
  450. * @throws Exception
  451. */
  452. private function _writeBorderPr($objWriter = null, $pName = 'left', $pBorder = null)
  453. {
  454. if ($objWriter instanceof xmlWriter && $pBorder instanceof PHPExcel_Style_Border) {
  455. // Write BorderPr
  456. if ($pBorder->getBorderStyle() != PHPExcel_Style_Border::BORDER_NONE) {
  457. $objWriter->startElement($pName);
  458. $objWriter->writeAttribute('style', $pBorder->getBorderStyle());
  459. // color
  460. $objWriter->startElement('color');
  461. $objWriter->writeAttribute('rgb', $pBorder->getColor()->getARGB());
  462. $objWriter->endElement();
  463. $objWriter->endElement();
  464. }
  465. } else {
  466. throw new Exception("Invalid parameters passed.");
  467. }
  468. }
  469. /**
  470. * Write NumberFormat
  471. *
  472. * @param xmlWriter $objWriter XML Writer
  473. * @param PHPExcel_Style_NumberFormat $pNumberFormat Number Format
  474. * @param int $pId Number Format identifier
  475. * @throws Exception
  476. */
  477. private function _writeNumFmt($objWriter = null, $pNumberFormat = null, $pId = 0)
  478. {
  479. if ($objWriter instanceof xmlWriter && $pNumberFormat instanceof PHPExcel_Style_NumberFormat) {
  480. // numFmt
  481. $objWriter->startElement('numFmt');
  482. $objWriter->writeAttribute('numFmtId', ($pId + 164));
  483. $objWriter->writeAttribute('formatCode', $pNumberFormat->getFormatCode());
  484. $objWriter->endElement();
  485. } else {
  486. throw new Exception("Invalid parameters passed.");
  487. }
  488. }
  489. /**
  490. * Get an array of all styles
  491. *
  492. * @param PHPExcel $pPHPExcel
  493. * @return PHPExcel_Style[] All styles in PHPExcel
  494. * @throws Exception
  495. */
  496. public function allStyles($pPHPExcel = null)
  497. {
  498. if ($pPHPExcel instanceof PHPExcel) {
  499. // Get an array of all styles
  500. $aStyles = array();
  501. for ($i = 0; $i < $pPHPExcel->getSheetCount(); $i++) {
  502. foreach ($pPHPExcel->getSheet($i)->getStyles() as $style) {
  503. $aStyles[] = $style;
  504. }
  505. }
  506. return $aStyles;
  507. } else {
  508. throw new Exception("Invalid PHPExcel object passed.");
  509. }
  510. }
  511. /**
  512. * Get an array of all conditional styles
  513. *
  514. * @param PHPExcel $pPHPExcel
  515. * @return PHPExcel_Style[] All styles in PHPExcel
  516. * @throws Exception
  517. */
  518. public function allConditionalStyles($pPHPExcel = null)
  519. {
  520. if ($pPHPExcel instanceof PHPExcel) {
  521. // Get an array of all styles
  522. $aStyles = array();
  523. for ($i = 0; $i < $pPHPExcel->getSheetCount(); $i++) {
  524. foreach ($pPHPExcel->getSheet($i)->getStyles() as $style) {
  525. if (count($style->getConditionalStyles()) > 0) {
  526. foreach ($style->getConditionalStyles() as $conditional) {
  527. array_push($aStyles, $conditional);
  528. }
  529. }
  530. }
  531. }
  532. return $aStyles;
  533. } else {
  534. throw new Exception("Invalid PHPExcel object passed.");
  535. }
  536. }
  537. /**
  538. * Get an array of all fills
  539. *
  540. * @param PHPExcel $pPHPExcel
  541. * @return PHPExcel_Style_Fill[] All fills in PHPExcel
  542. * @throws Exception
  543. */
  544. public function allFills($pPHPExcel = null)
  545. {
  546. if ($pPHPExcel instanceof PHPExcel) {
  547. // Get an array of unique fills
  548. $aFills = array();
  549. $aStyles = $this->allStyles($pPHPExcel);
  550. foreach ($aStyles as $style) {
  551. if (!array_key_exists($style->getFill()->getHashCode(), $aFills)) {
  552. $aFills[ $style->getFill()->getHashCode() ] = $style->getFill();
  553. }
  554. }
  555. return $aFills;
  556. } else {
  557. throw new Exception("Invalid PHPExcel object passed.");
  558. }
  559. }
  560. /**
  561. * Get an array of all fonts
  562. *
  563. * @param PHPExcel $pPHPExcel
  564. * @return PHPExcel_Style_Font[] All fonts in PHPExcel
  565. * @throws Exception
  566. */
  567. public function allFonts($pPHPExcel = null)
  568. {
  569. if ($pPHPExcel instanceof PHPExcel) {
  570. // Get an array of unique fonts
  571. $aFonts = array();
  572. $aStyles = $this->allStyles($pPHPExcel);
  573. foreach ($aStyles as $style) {
  574. if (!array_key_exists($style->getFont()->getHashCode(), $aFonts)) {
  575. $aFonts[ $style->getFont()->getHashCode() ] = $style->getFont();
  576. }
  577. }
  578. return $aFonts;
  579. } else {
  580. throw new Exception("Invalid PHPExcel object passed.");
  581. }
  582. }
  583. /**
  584. * Get an array of all borders
  585. *
  586. * @param PHPExcel $pPHPExcel
  587. * @return PHPExcel_Style_Borders[] All borders in PHPExcel
  588. * @throws Exception
  589. */
  590. public function allBorders($pPHPExcel = null)
  591. {
  592. if ($pPHPExcel instanceof PHPExcel) {
  593. // Get an array of unique borders
  594. $aBorders = array();
  595. $aStyles = $this->allStyles($pPHPExcel);
  596. foreach ($aStyles as $style) {
  597. if (!array_key_exists($style->getBorders()->getHashCode(), $aBorders)) {
  598. $aBorders[ $style->getBorders()->getHashCode() ] = $style->getBorders();
  599. }
  600. }
  601. return $aBorders;
  602. } else {
  603. throw new Exception("Invalid PHPExcel object passed.");
  604. }
  605. }
  606. /**
  607. * Get an array of all number formats
  608. *
  609. * @param PHPExcel $pPHPExcel
  610. * @return PHPExcel_Style_NumberFormat[] All number formats in PHPExcel
  611. * @throws Exception
  612. */
  613. public function allNumberFormats($pPHPExcel = null)
  614. {
  615. if ($pPHPExcel instanceof PHPExcel) {
  616. // Get an array of unique number formats
  617. $aNumFmts = array();
  618. $aStyles = $this->allStyles($pPHPExcel);
  619. foreach ($aStyles as $style) {
  620. if (!array_key_exists($style->getNumberFormat()->getHashCode(), $aNumFmts)) {
  621. $aNumFmts[ $style->getNumberFormat()->getHashCode() ] = $style->getNumberFormat();
  622. }
  623. }
  624. return $aNumFmts;
  625. } else {
  626. throw new Exception("Invalid PHPExcel object passed.");
  627. }
  628. }
  629. }