PHPExcel_Writer_Excel2007
[ class tree: PHPExcel_Writer_Excel2007 ] [ index: PHPExcel_Writer_Excel2007 ] [ all elements ]

Source for file Style.php

Documentation is available at Style.php

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

Documentation generated on Mon, 25 Aug 2008 13:50:30 +0200 by phpDocumentor 1.4.1