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

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