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 - 2010 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 - 2010 PHPExcel (http://www.codeplex.com/PHPExcel)
  24.  * @license    http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt    LGPL
  25.  * @version    1.7.2, 2010-01-11
  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 - 2010 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.                 case PHPExcel_Style_Borders::DIAGONAL_BOTH:
  399.                     $objWriter->writeAttribute('diagonalUp',     'true');
  400.                     $objWriter->writeAttribute('diagonalDown',     'true');
  401.                     break;
  402.             }
  403.  
  404.             // BorderPr
  405.             $this->_writeBorderPr($objWriter'left',             $pBorders->getLeft());
  406.             $this->_writeBorderPr($objWriter'right',             $pBorders->getRight());
  407.             $this->_writeBorderPr($objWriter'top',             $pBorders->getTop());
  408.             $this->_writeBorderPr($objWriter'bottom',         $pBorders->getBottom());
  409.             $this->_writeBorderPr($objWriter'diagonal',         $pBorders->getDiagonal());
  410.         $objWriter->endElement();
  411.     }
  412.  
  413.     /**
  414.      * Write Cell Style Xf
  415.      *
  416.      * @param     PHPExcel_Shared_XMLWriter            $objWriter         XML Writer
  417.      * @param     PHPExcel_Style                        $pStyle            Style
  418.      * @param     PHPExcel                            $pPHPExcel        Workbook
  419.      * @throws     Exception
  420.      */
  421.     private function _writeCellStyleXf(PHPExcel_Shared_XMLWriter $objWriter nullPHPExcel_Style $pStyle nullPHPExcel $pPHPExcel null)
  422.     {
  423.         // xf
  424.         $objWriter->startElement('xf');
  425.             $objWriter->writeAttribute('xfId'0);
  426.             $objWriter->writeAttribute('fontId',             (int)$this->getParentWriter()->getFontHashTable()->getIndexForHashCode($pStyle->getFont()->getHashCode()));
  427.             
  428.             if ($pStyle->getNumberFormat()->getBuiltInFormatCode(=== false{
  429.                 $objWriter->writeAttribute('numFmtId',             (int)($this->getParentWriter()->getNumFmtHashTable()->getIndexForHashCode($pStyle->getNumberFormat()->getHashCode()) 164)   );
  430.             else {
  431.                 $objWriter->writeAttribute('numFmtId',             (int)$pStyle->getNumberFormat()->getBuiltInFormatCode());
  432.             }
  433.             
  434.             $objWriter->writeAttribute('fillId',             (int)$this->getParentWriter()->getFillHashTable()->getIndexForHashCode($pStyle->getFill()->getHashCode()));
  435.             $objWriter->writeAttribute('borderId',             (int)$this->getParentWriter()->getBordersHashTable()->getIndexForHashCode($pStyle->getBorders()->getHashCode()));
  436.  
  437.             // Apply styles?
  438.             $objWriter->writeAttribute('applyFont',         ($pPHPExcel->getDefaultStyle()->getFont()->getHashCode(!= $pStyle->getFont()->getHashCode()) '1' '0');
  439.             $objWriter->writeAttribute('applyNumberFormat'($pPHPExcel->getDefaultStyle()->getNumberFormat()->getHashCode(!= $pStyle->getNumberFormat()->getHashCode()) '1' '0');
  440.             $objWriter->writeAttribute('applyFill',         ($pPHPExcel->getDefaultStyle()->getFill()->getHashCode(!= $pStyle->getFill()->getHashCode()) '1' '0');
  441.             $objWriter->writeAttribute('applyBorder',         ($pPHPExcel->getDefaultStyle()->getBorders()->getHashCode(!= $pStyle->getBorders()->getHashCode()) '1' '0');
  442.             $objWriter->writeAttribute('applyAlignment',    ($pPHPExcel->getDefaultStyle()->getAlignment()->getHashCode(!= $pStyle->getAlignment()->getHashCode()) '1' '0');
  443.             if ($pStyle->getProtection()->getLocked(!= PHPExcel_Style_Protection::PROTECTION_INHERIT || $pStyle->getProtection()->getHidden(!= PHPExcel_Style_Protection::PROTECTION_INHERIT{
  444.                 $objWriter->writeAttribute('applyProtection''true');
  445.             }
  446.  
  447.             // alignment
  448.             $objWriter->startElement('alignment');
  449.                 $objWriter->writeAttribute('horizontal',     $pStyle->getAlignment()->getHorizontal());
  450.                 $objWriter->writeAttribute('vertical',         $pStyle->getAlignment()->getVertical());
  451.  
  452.                 $textRotation 0;
  453.                 if ($pStyle->getAlignment()->getTextRotation(>= 0{
  454.                     $textRotation $pStyle->getAlignment()->getTextRotation();
  455.                 else if ($pStyle->getAlignment()->getTextRotation(0{
  456.                     $textRotation 90 $pStyle->getAlignment()->getTextRotation();
  457.                 }
  458.  
  459.                 $objWriter->writeAttribute('textRotation',     $textRotation);
  460.                 $objWriter->writeAttribute('wrapText',         ($pStyle->getAlignment()->getWrapText('true' 'false'));
  461.                 $objWriter->writeAttribute('shrinkToFit',     ($pStyle->getAlignment()->getShrinkToFit('true' 'false'));
  462.  
  463.                 if ($pStyle->getAlignment()->getIndent(0{
  464.                     $objWriter->writeAttribute('indent',     $pStyle->getAlignment()->getIndent());
  465.                 }
  466.             $objWriter->endElement();
  467.  
  468.             // protection
  469.             if ($pStyle->getProtection()->getLocked(!= PHPExcel_Style_Protection::PROTECTION_INHERIT || $pStyle->getProtection()->getHidden(!= PHPExcel_Style_Protection::PROTECTION_INHERIT{
  470.                 $objWriter->startElement('protection');
  471.                     if ($pStyle->getProtection()->getLocked(!= PHPExcel_Style_Protection::PROTECTION_INHERIT{
  472.                         $objWriter->writeAttribute('locked',         ($pStyle->getProtection()->getLocked(== PHPExcel_Style_Protection::PROTECTION_PROTECTED 'true' 'false'));
  473.                     }
  474.                     if ($pStyle->getProtection()->getHidden(!= PHPExcel_Style_Protection::PROTECTION_INHERIT{
  475.                         $objWriter->writeAttribute('hidden',         ($pStyle->getProtection()->getHidden(== PHPExcel_Style_Protection::PROTECTION_PROTECTED 'true' 'false'));
  476.                     }
  477.                 $objWriter->endElement();
  478.             }
  479.  
  480.         $objWriter->endElement();
  481.     }
  482.  
  483.     /**
  484.      * Write Cell Style Dxf
  485.      *
  486.      * @param     PHPExcel_Shared_XMLWriter         $objWriter         XML Writer
  487.      * @param     PHPExcel_Style                    $pStyle            Style
  488.      * @throws     Exception
  489.      */
  490.     private function _writeCellStyleDxf(PHPExcel_Shared_XMLWriter $objWriter nullPHPExcel_Style $pStyle null)
  491.     {
  492.         // dxf
  493.         $objWriter->startElement('dxf');
  494.  
  495.             // font
  496.             $this->_writeFont($objWriter$pStyle->getFont());
  497.  
  498.             // numFmt
  499.             $this->_writeNumFmt($objWriter$pStyle->getNumberFormat());
  500.  
  501.             // fill
  502.             $this->_writeFill($objWriter$pStyle->getFill());
  503.  
  504.             // alignment
  505.             $objWriter->startElement('alignment');
  506.                 $objWriter->writeAttribute('horizontal',     $pStyle->getAlignment()->getHorizontal());
  507.                 $objWriter->writeAttribute('vertical',         $pStyle->getAlignment()->getVertical());
  508.  
  509.                 $textRotation 0;
  510.                 if ($pStyle->getAlignment()->getTextRotation(>= 0{
  511.                     $textRotation $pStyle->getAlignment()->getTextRotation();
  512.                 else if ($pStyle->getAlignment()->getTextRotation(0{
  513.                     $textRotation 90 $pStyle->getAlignment()->getTextRotation();
  514.                 }
  515.  
  516.                 $objWriter->writeAttribute('textRotation',     $textRotation);
  517.             $objWriter->endElement();
  518.  
  519.             // border
  520.             $this->_writeBorder($objWriter$pStyle->getBorders());
  521.  
  522.             // protection
  523.             if ($pStyle->getProtection()->getLocked(!= PHPExcel_Style_Protection::PROTECTION_INHERIT || $pStyle->getProtection()->getHidden(!= PHPExcel_Style_Protection::PROTECTION_INHERIT{
  524.                 $objWriter->startElement('protection');
  525.                     if ($pStyle->getProtection()->getLocked(!= PHPExcel_Style_Protection::PROTECTION_INHERIT{
  526.                         $objWriter->writeAttribute('locked',         ($pStyle->getProtection()->getLocked(== PHPExcel_Style_Protection::PROTECTION_PROTECTED 'true' 'false'));
  527.                     }
  528.                     if ($pStyle->getProtection()->getHidden(!= PHPExcel_Style_Protection::PROTECTION_INHERIT{
  529.                         $objWriter->writeAttribute('hidden',         ($pStyle->getProtection()->getHidden(== PHPExcel_Style_Protection::PROTECTION_PROTECTED 'true' 'false'));
  530.                     }
  531.                 $objWriter->endElement();
  532.             }
  533.  
  534.         $objWriter->endElement();
  535.     }
  536.  
  537.     /**
  538.      * Write BorderPr
  539.      *
  540.      * @param     PHPExcel_Shared_XMLWriter        $objWriter         XML Writer
  541.      * @param     string                            $pName            Element name
  542.      * @param     PHPExcel_Style_Border            $pBorder        Border style
  543.      * @throws     Exception
  544.      */
  545.     private function _writeBorderPr(PHPExcel_Shared_XMLWriter $objWriter null$pName 'left'PHPExcel_Style_Border $pBorder null)
  546.     {
  547.         // Write BorderPr
  548.         if ($pBorder->getBorderStyle(!= PHPExcel_Style_Border::BORDER_NONE{
  549.             $objWriter->startElement($pName);
  550.             $objWriter->writeAttribute('style',     $pBorder->getBorderStyle());
  551.  
  552.                 // color
  553.                 $objWriter->startElement('color');
  554.                 $objWriter->writeAttribute('rgb',     $pBorder->getColor()->getARGB());
  555.                 $objWriter->endElement();
  556.  
  557.             $objWriter->endElement();
  558.         }
  559.     }
  560.  
  561.     /**
  562.      * Write NumberFormat
  563.      *
  564.      * @param     PHPExcel_Shared_XMLWriter            $objWriter         XML Writer
  565.      * @param     PHPExcel_Style_NumberFormat            $pNumberFormat    Number Format
  566.      * @param     int                                    $pId            Number Format identifier
  567.      * @throws     Exception
  568.      */
  569.     private function _writeNumFmt(PHPExcel_Shared_XMLWriter $objWriter nullPHPExcel_Style_NumberFormat $pNumberFormat null$pId 0)
  570.     {
  571.         // Translate formatcode
  572.         $formatCode $pNumberFormat->getFormatCode();
  573.  
  574.         // numFmt
  575.         $objWriter->startElement('numFmt');
  576.             $objWriter->writeAttribute('numFmtId',         ($pId 164));
  577.             $objWriter->writeAttribute('formatCode',     $formatCode);
  578.         $objWriter->endElement();
  579.     }
  580.  
  581.     /**
  582.      * Get an array of all styles
  583.      *
  584.      * @param     PHPExcel                $pPHPExcel 
  585.      * @return     PHPExcel_Style[]        All styles in PHPExcel
  586.      * @throws     Exception
  587.      */
  588.     public function allStyles(PHPExcel $pPHPExcel null)
  589.     {
  590.         $aStyles $pPHPExcel->getCellXfCollection();
  591.  
  592.         return $aStyles;
  593.     }
  594.  
  595.     /**
  596.      * Get an array of all conditional styles
  597.      *
  598.      * @param     PHPExcel                            $pPHPExcel 
  599.      * @return     PHPExcel_Style_Conditional[]        All conditional styles in PHPExcel
  600.      * @throws     Exception
  601.      */
  602.     public function allConditionalStyles(PHPExcel $pPHPExcel null)
  603.     {
  604.         // Get an array of all styles
  605.         $aStyles        array();
  606.  
  607.         $sheetCount $pPHPExcel->getSheetCount();
  608.         for ($i 0$i $sheetCount++$i{
  609.             foreach ($pPHPExcel->getSheet($i)->getConditionalStylesCollection(as $conditionalStyles{
  610.                 foreach ($conditionalStyles as $conditionalStyle{
  611.                     $aStyles[$conditionalStyle;
  612.                 }
  613.             }
  614.         }
  615.  
  616.         return $aStyles;
  617.     }
  618.  
  619.     /**
  620.      * Get an array of all fills
  621.      *
  622.      * @param     PHPExcel                        $pPHPExcel 
  623.      * @return     PHPExcel_Style_Fill[]        All fills in PHPExcel
  624.      * @throws     Exception
  625.      */
  626.     public function allFills(PHPExcel $pPHPExcel null)
  627.     {
  628.         // Get an array of unique fills
  629.         $aFills     array();
  630.  
  631.         // Two first fills are predefined
  632.         $fill0 new PHPExcel_Style_Fill();
  633.         $fill0->setFillType(PHPExcel_Style_Fill::FILL_NONE);
  634.         $aFills[$fill0;
  635.  
  636.         $fill1 new PHPExcel_Style_Fill();
  637.         $fill1->setFillType(PHPExcel_Style_Fill::FILL_PATTERN_GRAY125);
  638.         $aFills[$fill1;
  639.  
  640.         // The remaining fills
  641.         $aStyles     $this->allStyles($pPHPExcel);
  642.         foreach ($aStyles as $style{
  643.             if (!array_key_exists($style->getFill()->getHashCode()$aFills)) {
  644.                 $aFills$style->getFill()->getHashCode($style->getFill();
  645.             }
  646.         }
  647.  
  648.         return $aFills;
  649.     }
  650.  
  651.     /**
  652.      * Get an array of all fonts
  653.      *
  654.      * @param     PHPExcel                        $pPHPExcel 
  655.      * @return     PHPExcel_Style_Font[]        All fonts in PHPExcel
  656.      * @throws     Exception
  657.      */
  658.     public function allFonts(PHPExcel $pPHPExcel null)
  659.     {
  660.         // Get an array of unique fonts
  661.         $aFonts     array();
  662.         $aStyles     $this->allStyles($pPHPExcel);
  663.  
  664.         foreach ($aStyles as $style{
  665.             if (!array_key_exists($style->getFont()->getHashCode()$aFonts)) {
  666.                 $aFonts$style->getFont()->getHashCode($style->getFont();
  667.             }
  668.         }
  669.  
  670.         return $aFonts;
  671.     }
  672.  
  673.     /**
  674.      * Get an array of all borders
  675.      *
  676.      * @param     PHPExcel                        $pPHPExcel 
  677.      * @return     PHPExcel_Style_Borders[]        All borders in PHPExcel
  678.      * @throws     Exception
  679.      */
  680.     public function allBorders(PHPExcel $pPHPExcel null)
  681.     {
  682.         // Get an array of unique borders
  683.         $aBorders     array();
  684.         $aStyles     $this->allStyles($pPHPExcel);
  685.  
  686.         foreach ($aStyles as $style{
  687.             if (!array_key_exists($style->getBorders()->getHashCode()$aBorders)) {
  688.                 $aBorders$style->getBorders()->getHashCode($style->getBorders();
  689.             }
  690.         }
  691.  
  692.         return $aBorders;
  693.     }
  694.  
  695.     /**
  696.      * Get an array of all number formats
  697.      *
  698.      * @param     PHPExcel                                $pPHPExcel 
  699.      * @return     PHPExcel_Style_NumberFormat[]        All number formats in PHPExcel
  700.      * @throws     Exception
  701.      */
  702.     public function allNumberFormats(PHPExcel $pPHPExcel null)
  703.     {
  704.         // Get an array of unique number formats
  705.         $aNumFmts     array();
  706.         $aStyles     $this->allStyles($pPHPExcel);
  707.  
  708.         foreach ($aStyles as $style{
  709.             if ($style->getNumberFormat()->getBuiltInFormatCode(=== false && !array_key_exists($style->getNumberFormat()->getHashCode()$aNumFmts)) {
  710.                 $aNumFmts$style->getNumberFormat()->getHashCode($style->getNumberFormat();
  711.             }
  712.         }
  713.  
  714.         return $aNumFmts;
  715.     }
  716. }

Documentation generated on Mon, 11 Jan 2010 08:14:27 +0100 by phpDocumentor 1.4.1