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

Documentation generated on Mon, 10 Aug 2009 08:08:12 +0200 by phpDocumentor 1.4.1