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.4, 2008-10-27
  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 nullPHPExcel_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 nullPHPExcel_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 nullPHPExcel_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.                 // fgColor
  288.                 $objWriter->startElement('fgColor');
  289.                 $objWriter->writeAttribute('rgb'$pFill->getStartColor()->getARGB());
  290.                 $objWriter->endElement();
  291.  
  292.                 // bgColor
  293.                 $objWriter->startElement('bgColor');
  294.                 $objWriter->writeAttribute('rgb'$pFill->getEndColor()->getARGB());
  295.                 $objWriter->endElement();
  296.  
  297.             $objWriter->endElement();
  298.  
  299.         $objWriter->endElement();
  300.     }
  301.  
  302.     /**
  303.      * Write Font
  304.      *
  305.      * @param     PHPExcel_Shared_XMLWriter        $objWriter         XML Writer
  306.      * @param     PHPExcel_Style_Font                $pFont            Font style
  307.      * @throws     Exception
  308.      */
  309.     private function _writeFont(PHPExcel_Shared_XMLWriter $objWriter nullPHPExcel_Style_Font $pFont null)
  310.     {
  311.         // font
  312.         $objWriter->startElement('font');
  313.  
  314.             // Name
  315.             $objWriter->startElement('name');
  316.             $objWriter->writeAttribute('val'$pFont->getName());
  317.             $objWriter->endElement();
  318.  
  319.             // Size
  320.             $objWriter->startElement('sz');
  321.             $objWriter->writeAttribute('val'$pFont->getSize());
  322.             $objWriter->endElement();
  323.  
  324.             // Bold
  325.             $objWriter->startElement('b');
  326.             $objWriter->writeAttribute('val'($pFont->getBold('true' 'false'));
  327.             $objWriter->endElement();
  328.  
  329.             // Italic
  330.             $objWriter->startElement('i');
  331.             $objWriter->writeAttribute('val'($pFont->getItalic('true' 'false'));
  332.             $objWriter->endElement();
  333.  
  334.             // Superscript / subscript
  335.             if ($pFont->getSuperScript(|| $pFont->getSubScript()) {
  336.                 $objWriter->startElement('vertAlign');
  337.                 if ($pFont->getSuperScript()) {
  338.                     $objWriter->writeAttribute('val''superscript');
  339.                 else if ($pFont->getSubScript()) {
  340.                     $objWriter->writeAttribute('val''subscript');
  341.                 }
  342.                 $objWriter->endElement();
  343.             }
  344.  
  345.             // Underline
  346.             $objWriter->startElement('u');
  347.             $objWriter->writeAttribute('val'$pFont->getUnderline());
  348.             $objWriter->endElement();
  349.  
  350.             // Striketrough
  351.             $objWriter->startElement('strike');
  352.             $objWriter->writeAttribute('val'($pFont->getStriketrough('true' 'false'));
  353.             $objWriter->endElement();
  354.  
  355.             // Foreground color
  356.             $objWriter->startElement('color');
  357.             $objWriter->writeAttribute('rgb'$pFont->getColor()->getARGB());
  358.             $objWriter->endElement();
  359.  
  360.         $objWriter->endElement();
  361.     }
  362.  
  363.     /**
  364.      * Write Border
  365.      *
  366.      * @param     PHPExcel_Shared_XMLWriter            $objWriter         XML Writer
  367.      * @param     PHPExcel_Style_Borders                $pBorders        Borders style
  368.      * @throws     Exception
  369.      */
  370.     private function _writeBorder(PHPExcel_Shared_XMLWriter $objWriter nullPHPExcel_Style_Borders $pBorders null)
  371.     {
  372.         // Write border
  373.         $objWriter->startElement('border');
  374.             // Diagonal?
  375.             switch ($pBorders->getDiagonalDirection()) {
  376.                 case PHPExcel_Style_Borders::DIAGONAL_UP:
  377.                     $objWriter->writeAttribute('diagonalUp',     'true');
  378.                     $objWriter->writeAttribute('diagonalDown',     'false');
  379.                     break;
  380.                 case PHPExcel_Style_Borders::DIAGONAL_DOWN:
  381.                     $objWriter->writeAttribute('diagonalUp',     'false');
  382.                     $objWriter->writeAttribute('diagonalDown',     'true');
  383.                     break;
  384.             }
  385.  
  386.             // Outline?
  387.             $objWriter->writeAttribute('outline'($pBorders->getOutline('true' 'false'));
  388.  
  389.             // BorderPr
  390.             $this->_writeBorderPr($objWriter'left',             $pBorders->getLeft());
  391.             $this->_writeBorderPr($objWriter'right',             $pBorders->getRight());
  392.             $this->_writeBorderPr($objWriter'top',             $pBorders->getTop());
  393.             $this->_writeBorderPr($objWriter'bottom',         $pBorders->getBottom());
  394.             $this->_writeBorderPr($objWriter'diagonal',         $pBorders->getDiagonal());
  395.             $this->_writeBorderPr($objWriter'vertical',         $pBorders->getVertical());
  396.             $this->_writeBorderPr($objWriter'horizontal',     $pBorders->getHorizontal());
  397.         $objWriter->endElement();
  398.     }
  399.  
  400.     /**
  401.      * Write Cell Style Xf
  402.      *
  403.      * @param     PHPExcel_Shared_XMLWriter            $objWriter         XML Writer
  404.      * @param     PHPExcel_Style                        $pStyle            Style
  405.      * @throws     Exception
  406.      */
  407.     private function _writeCellStyleXf(PHPExcel_Shared_XMLWriter $objWriter nullPHPExcel_Style $pStyle null)
  408.     {
  409.         // xf
  410.         $objWriter->startElement('xf');
  411.             $objWriter->writeAttribute('xfId'0);
  412.             $objWriter->writeAttribute('fontId',             (int)$this->getParentWriter()->getFontHashTable()->getIndexForHashCode($pStyle->getFont()->getHashCode()));
  413.             $objWriter->writeAttribute('numFmtId',             (int)($this->getParentWriter()->getNumFmtHashTable()->getIndexForHashCode($pStyle->getNumberFormat()->getHashCode()) 164)   );
  414.             $objWriter->writeAttribute('fillId',             (int)$this->getParentWriter()->getFillHashTable()->getIndexForHashCode($pStyle->getFill()->getHashCode()));
  415.             $objWriter->writeAttribute('borderId',             (int)$this->getParentWriter()->getBordersHashTable()->getIndexForHashCode($pStyle->getBorders()->getHashCode()));
  416.  
  417.             // Apply styles?
  418.             $objWriter->writeAttribute('applyFont',         (PHPExcel_Style::getDefaultStyle()->getFont()->getHashCode(!= $pStyle->getFont()->getHashCode()) '1' '0');
  419.             $objWriter->writeAttribute('applyNumberFormat'(PHPExcel_Style::getDefaultStyle()->getNumberFormat()->getHashCode(!= $pStyle->getNumberFormat()->getHashCode()) '1' '0');
  420.             $objWriter->writeAttribute('applyFill',         (PHPExcel_Style::getDefaultStyle()->getFill()->getHashCode(!= $pStyle->getFill()->getHashCode()) '1' '0');
  421.             $objWriter->writeAttribute('applyBorder',         (PHPExcel_Style::getDefaultStyle()->getBorders()->getHashCode(!= $pStyle->getBorders()->getHashCode()) '1' '0');
  422.             $objWriter->writeAttribute('applyAlignment',    (PHPExcel_Style::getDefaultStyle()->getAlignment()->getHashCode(!= $pStyle->getAlignment()->getHashCode()) '1' '0');
  423.             if ($pStyle->getProtection()->getLocked(!= PHPExcel_Style_Protection::PROTECTION_INHERIT || $pStyle->getProtection()->getHidden(!= PHPExcel_Style_Protection::PROTECTION_INHERIT{
  424.                 $objWriter->writeAttribute('applyProtection''true');
  425.             }
  426.  
  427.             // alignment
  428.             $objWriter->startElement('alignment');
  429.                 $objWriter->writeAttribute('horizontal',     $pStyle->getAlignment()->getHorizontal());
  430.                 $objWriter->writeAttribute('vertical',         $pStyle->getAlignment()->getVertical());
  431.  
  432.                 $textRotation 0;
  433.                 if ($pStyle->getAlignment()->getTextRotation(>= 0{
  434.                     $textRotation $pStyle->getAlignment()->getTextRotation();
  435.                 else if ($pStyle->getAlignment()->getTextRotation(0{
  436.                     $textRotation 90 $pStyle->getAlignment()->getTextRotation();
  437.                 }
  438.  
  439.                 $objWriter->writeAttribute('textRotation',     $textRotation);
  440.                 $objWriter->writeAttribute('wrapText',         ($pStyle->getAlignment()->getWrapText('true' 'false'));
  441.                 $objWriter->writeAttribute('shrinkToFit',     ($pStyle->getAlignment()->getShrinkToFit('true' 'false'));
  442.                 
  443.                 if ($pStyle->getAlignment()->getIndent(0{
  444.                     $objWriter->writeAttribute('indent',     $pStyle->getAlignment()->getIndent());
  445.                 }
  446.             $objWriter->endElement();
  447.  
  448.             // protection
  449.             if ($pStyle->getProtection()->getLocked(!= PHPExcel_Style_Protection::PROTECTION_INHERIT || $pStyle->getProtection()->getHidden(!= PHPExcel_Style_Protection::PROTECTION_INHERIT{
  450.                 $objWriter->startElement('protection');
  451.                     if ($pStyle->getProtection()->getLocked(!= PHPExcel_Style_Protection::PROTECTION_INHERIT{
  452.                         $objWriter->writeAttribute('locked',         ($pStyle->getProtection()->getLocked(== PHPExcel_Style_Protection::PROTECTION_PROTECTED 'true' 'false'));
  453.                     }
  454.                     if ($pStyle->getProtection()->getHidden(!= PHPExcel_Style_Protection::PROTECTION_INHERIT{
  455.                         $objWriter->writeAttribute('hidden',         ($pStyle->getProtection()->getHidden(== PHPExcel_Style_Protection::PROTECTION_PROTECTED 'true' 'false'));
  456.                     }
  457.                 $objWriter->endElement();
  458.             }
  459.  
  460.         $objWriter->endElement();
  461.     }
  462.  
  463.     /**
  464.      * Write Cell Style Dxf
  465.      *
  466.      * @param     PHPExcel_Shared_XMLWriter         $objWriter         XML Writer
  467.      * @param     PHPExcel_Style                    $pStyle            Style
  468.      * @throws     Exception
  469.      */
  470.     private function _writeCellStyleDxf(PHPExcel_Shared_XMLWriter $objWriter nullPHPExcel_Style $pStyle null)
  471.     {
  472.         // dxf
  473.         $objWriter->startElement('dxf');
  474.  
  475.             // font
  476.             $this->_writeFont($objWriter$pStyle->getFont());
  477.  
  478.             // numFmt
  479.             $this->_writeNumFmt($objWriter$pStyle->getNumberFormat());
  480.  
  481.             // fill
  482.             $this->_writeFill($objWriter$pStyle->getFill());
  483.  
  484.             // alignment
  485.             $objWriter->startElement('alignment');
  486.                 $objWriter->writeAttribute('horizontal',     $pStyle->getAlignment()->getHorizontal());
  487.                 $objWriter->writeAttribute('vertical',         $pStyle->getAlignment()->getVertical());
  488.  
  489.                 $textRotation 0;
  490.                 if ($pStyle->getAlignment()->getTextRotation(>= 0{
  491.                     $textRotation $pStyle->getAlignment()->getTextRotation();
  492.                 else if ($pStyle->getAlignment()->getTextRotation(0{
  493.                     $textRotation 90 $pStyle->getAlignment()->getTextRotation();
  494.                 }
  495.  
  496.                 $objWriter->writeAttribute('textRotation',     $textRotation);
  497.             $objWriter->endElement();
  498.  
  499.             // border
  500.             $this->_writeBorder($objWriter$pStyle->getBorders());
  501.  
  502.             // protection
  503.             if ($pStyle->getProtection()->getLocked(!= PHPExcel_Style_Protection::PROTECTION_INHERIT || $pStyle->getProtection()->getHidden(!= PHPExcel_Style_Protection::PROTECTION_INHERIT{
  504.                 $objWriter->startElement('protection');
  505.                     if ($pStyle->getProtection()->getLocked(!= PHPExcel_Style_Protection::PROTECTION_INHERIT{
  506.                         $objWriter->writeAttribute('locked',         ($pStyle->getProtection()->getLocked(== PHPExcel_Style_Protection::PROTECTION_PROTECTED 'true' 'false'));
  507.                     }
  508.                     if ($pStyle->getProtection()->getHidden(!= PHPExcel_Style_Protection::PROTECTION_INHERIT{
  509.                         $objWriter->writeAttribute('hidden',         ($pStyle->getProtection()->getHidden(== PHPExcel_Style_Protection::PROTECTION_PROTECTED 'true' 'false'));
  510.                     }
  511.                 $objWriter->endElement();
  512.             }
  513.  
  514.         $objWriter->endElement();
  515.     }
  516.  
  517.     /**
  518.      * Write BorderPr
  519.      *
  520.      * @param     PHPExcel_Shared_XMLWriter        $objWriter         XML Writer
  521.      * @param     string                            $pName            Element name
  522.      * @param     PHPExcel_Style_Border            $pBorder        Border style
  523.      * @throws     Exception
  524.      */
  525.     private function _writeBorderPr(PHPExcel_Shared_XMLWriter $objWriter null$pName 'left'PHPExcel_Style_Border $pBorder null)
  526.     {
  527.         // Write BorderPr
  528.         if ($pBorder->getBorderStyle(!= PHPExcel_Style_Border::BORDER_NONE{
  529.             $objWriter->startElement($pName);
  530.             $objWriter->writeAttribute('style',     $pBorder->getBorderStyle());
  531.  
  532.                 // color
  533.                 $objWriter->startElement('color');
  534.                 $objWriter->writeAttribute('rgb',     $pBorder->getColor()->getARGB());
  535.                 $objWriter->endElement();
  536.  
  537.             $objWriter->endElement();
  538.         }
  539.     }
  540.  
  541.     /**
  542.      * Write NumberFormat
  543.      *
  544.      * @param     PHPExcel_Shared_XMLWriter            $objWriter         XML Writer
  545.      * @param     PHPExcel_Style_NumberFormat            $pNumberFormat    Number Format
  546.      * @param     int                                    $pId            Number Format identifier
  547.      * @throws     Exception
  548.      */
  549.     private function _writeNumFmt(PHPExcel_Shared_XMLWriter $objWriter nullPHPExcel_Style_NumberFormat $pNumberFormat null$pId 0)
  550.     {
  551.         // Translate formatcode
  552.         $formatCode $pNumberFormat->getFormatCode();
  553.  
  554.         // numFmt
  555.         $objWriter->startElement('numFmt');
  556.             $objWriter->writeAttribute('numFmtId',         ($pId 164));
  557.             $objWriter->writeAttribute('formatCode',     $formatCode);
  558.         $objWriter->endElement();
  559.     }
  560.  
  561.     /**
  562.      * Get an array of all styles
  563.      *
  564.      * @param     PHPExcel                $pPHPExcel 
  565.      * @return     PHPExcel_Style[]        All styles in PHPExcel
  566.      * @throws     Exception
  567.      */
  568.     public function allStyles(PHPExcel $pPHPExcel null)
  569.     {
  570.         // Get an array of all styles
  571.         $aStyles        array();
  572.  
  573.         $sheetCount $pPHPExcel->getSheetCount();
  574.         for ($i 0$i $sheetCount++$i{
  575.             foreach ($pPHPExcel->getSheet($i)->getStyles(as $style{
  576.                 $aStyles[$style;
  577.             }
  578.         }
  579.  
  580.         return $aStyles;
  581.     }
  582.  
  583.     /**
  584.      * Get an array of all conditional styles
  585.      *
  586.      * @param     PHPExcel                $pPHPExcel 
  587.      * @return     PHPExcel_Style[]        All styles in PHPExcel
  588.      * @throws     Exception
  589.      */
  590.     public function allConditionalStyles(PHPExcel $pPHPExcel null)
  591.     {
  592.         // Get an array of all styles
  593.         $aStyles        array();
  594.  
  595.         $sheetCount $pPHPExcel->getSheetCount();
  596.         for ($i 0$i $sheetCount++$i{
  597.             foreach ($pPHPExcel->getSheet($i)->getStyles(as $style{
  598.                 if (count($style->getConditionalStyles()) 0{
  599.                     foreach ($style->getConditionalStyles(as $conditional{
  600.                         array_push($aStyles$conditional);
  601.                     }
  602.                 }
  603.             }
  604.         }
  605.  
  606.         return $aStyles;
  607.     }
  608.  
  609.     /**
  610.      * Get an array of all fills
  611.      *
  612.      * @param     PHPExcel                        $pPHPExcel 
  613.      * @return     PHPExcel_Style_Fill[]        All fills in PHPExcel
  614.      * @throws     Exception
  615.      */
  616.     public function allFills(PHPExcel $pPHPExcel null)
  617.     {
  618.         // Get an array of unique fills
  619.         $aFills     array();
  620.         $aStyles     $this->allStyles($pPHPExcel);
  621.  
  622.         foreach ($aStyles as $style{
  623.             if (!array_key_exists($style->getFill()->getHashCode()$aFills)) {
  624.                 $aFills$style->getFill()->getHashCode($style->getFill();
  625.             }
  626.         }
  627.  
  628.         return $aFills;
  629.     }
  630.  
  631.     /**
  632.      * Get an array of all fonts
  633.      *
  634.      * @param     PHPExcel                        $pPHPExcel 
  635.      * @return     PHPExcel_Style_Font[]        All fonts in PHPExcel
  636.      * @throws     Exception
  637.      */
  638.     public function allFonts(PHPExcel $pPHPExcel null)
  639.     {
  640.         // Get an array of unique fonts
  641.         $aFonts     array();
  642.         $aStyles     $this->allStyles($pPHPExcel);
  643.  
  644.         foreach ($aStyles as $style{
  645.             if (!array_key_exists($style->getFont()->getHashCode()$aFonts)) {
  646.                 $aFonts$style->getFont()->getHashCode($style->getFont();
  647.             }
  648.         }
  649.  
  650.         return $aFonts;
  651.     }
  652.  
  653.     /**
  654.      * Get an array of all borders
  655.      *
  656.      * @param     PHPExcel                        $pPHPExcel 
  657.      * @return     PHPExcel_Style_Borders[]        All borders in PHPExcel
  658.      * @throws     Exception
  659.      */
  660.     public function allBorders(PHPExcel $pPHPExcel null)
  661.     {
  662.         // Get an array of unique borders
  663.         $aBorders     array();
  664.         $aStyles     $this->allStyles($pPHPExcel);
  665.  
  666.         foreach ($aStyles as $style{
  667.             if (!array_key_exists($style->getBorders()->getHashCode()$aBorders)) {
  668.                 $aBorders$style->getBorders()->getHashCode($style->getBorders();
  669.             }
  670.         }
  671.  
  672.         return $aBorders;
  673.     }
  674.  
  675.     /**
  676.      * Get an array of all number formats
  677.      *
  678.      * @param     PHPExcel                                $pPHPExcel 
  679.      * @return     PHPExcel_Style_NumberFormat[]        All number formats in PHPExcel
  680.      * @throws     Exception
  681.      */
  682.     public function allNumberFormats(PHPExcel $pPHPExcel null)
  683.     {
  684.         // Get an array of unique number formats
  685.         $aNumFmts     array();
  686.         $aStyles     $this->allStyles($pPHPExcel);
  687.  
  688.         foreach ($aStyles as $style{
  689.             if (!array_key_exists($style->getNumberFormat()->getHashCode()$aNumFmts)) {
  690.                 $aNumFmts$style->getNumberFormat()->getHashCode($style->getNumberFormat();
  691.             }
  692.         }
  693.  
  694.         return $aNumFmts;
  695.     }
  696. }

Documentation generated on Mon, 27 Oct 2008 08:41:28 +0100 by phpDocumentor 1.4.1