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

Source for file Excel5.php

Documentation is available at Excel5.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_Excel5
  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.6.7, 2009-04-22
  26.  */
  27.  
  28.  
  29. /** PHPExcel_IWriter */
  30. require_once 'PHPExcel/Writer/IWriter.php';
  31.  
  32. /** PHPExcel_Cell */
  33. require_once 'PHPExcel/Cell.php';
  34.  
  35. /** PHPExcel_Writer_Excel5_Workbook */
  36. require_once 'PHPExcel/Writer/Excel5/Workbook.php';
  37.  
  38. /** PHPExcel_HashTable */
  39. require_once 'PHPExcel/HashTable.php';
  40.  
  41.  
  42. /**
  43.  * PHPExcel_Writer_Excel5
  44.  *
  45.  * @category   PHPExcel
  46.  * @package    PHPExcel_Writer_Excel5
  47.  * @copyright  Copyright (c) 2006 - 2009 PHPExcel (http://www.codeplex.com/PHPExcel)
  48.  */
  49. class PHPExcel_Writer_Excel5 implements PHPExcel_Writer_IWriter {
  50.     /**
  51.      * PHPExcel object
  52.      *
  53.      * @var PHPExcel 
  54.      */
  55.     private $_phpExcel;
  56.  
  57.     /**
  58.      * Temporary storage directory
  59.      *
  60.      * @var string 
  61.      */
  62.     private $_tempDir = '';
  63.  
  64.     /**
  65.      * Create a new PHPExcel_Writer_Excel5
  66.      *
  67.      * @param    PHPExcel    $phpExcel    PHPExcel object
  68.      */
  69.     public function __construct(PHPExcel $phpExcel{
  70.         $this->_phpExcel    = $phpExcel;
  71.         $this->_tempDir        = '';
  72.     }
  73.  
  74.     /**
  75.      * Save PHPExcel to file
  76.      *
  77.      * @param    string        $pFileName 
  78.      * @throws    Exception
  79.      */
  80.     public function save($pFilename null{
  81.  
  82.         $phpExcel $this->_phpExcel;
  83.         $workbook new PHPExcel_Writer_Excel5_Workbook($pFilename$phpExcel);
  84.         $workbook->setVersion(8);
  85.  
  86.         // Set temp dir
  87.         if ($this->_tempDir != ''{
  88.             $workbook->setTempDir($this->_tempDir);
  89.         }
  90.  
  91.         $saveDateReturnType PHPExcel_Calculation_Functions::getReturnDateType();
  92.  
  93.         // Add 15 style Xf's plus 1 cell Xf. Why?
  94.         for ($i 0$i 15++$i{
  95.             $workbook->addXfWriter($phpExcel->getSheet(0)->getDefaultStyle()true);
  96.         }
  97.         $workbook->addXfWriter($phpExcel->getSheet(0)->getDefaultStyle());
  98.  
  99.         // Style dictionary
  100.         $xfIndexes array();
  101.  
  102.         $allStyles $this->_allStyles($this->_phpExcel);
  103.         $cellStyleHashes new PHPExcel_HashTable();
  104.         $cellStyleHashes->addFromSource$allStyles );
  105.  
  106.         $addedStyles array();
  107.         foreach ($allStyles as $style{
  108.             $styleHashIndex $style->getHashIndex();
  109.  
  110.             if(isset($addedStyles[$styleHashIndex])) continue;
  111.             
  112.             // mapping between PHPExcel style hash index and BIFF XF index
  113.             $xfIndexes[$styleHashIndex$workbook->addXfWriter($style);
  114.  
  115.             $addedStyles[$style->getHashIndex()true;
  116.         }
  117.  
  118.         // Add empty sheets
  119.         foreach ($phpExcel->getSheetNames(as $sheetIndex => $sheetName{
  120.             $phpSheet  $phpExcel->getSheet($sheetIndex);
  121.             $worksheet $workbook->addWorksheet($phpSheet$xfIndexes);
  122.         }
  123.  
  124.         PHPExcel_Calculation_Functions::setReturnDateType($saveDateReturnType);
  125.  
  126.         $workbook->close();
  127.     }
  128.  
  129.     /**
  130.      * Get an array of all styles
  131.      *
  132.      * @param    PHPExcel                $pPHPExcel 
  133.      * @return    PHPExcel_Style[]        All styles in PHPExcel
  134.      * @throws    Exception
  135.      */
  136.     private function _allStyles(PHPExcel $pPHPExcel null)
  137.     {
  138.         // Get an array of all styles
  139.         $aStyles        array();
  140.  
  141.         for ($i 0$i $pPHPExcel->getSheetCount()++$i{
  142.             foreach ($pPHPExcel->getSheet($i)->getStyles(as $style{
  143.                 $aStyles[$style;
  144.             }
  145.         }
  146.  
  147.         return $aStyles;
  148.     }
  149.  
  150.     /**
  151.      * Get temporary storage directory
  152.      *
  153.      * @return string 
  154.      */
  155.     public function getTempDir({
  156.         return $this->_tempDir;
  157.     }
  158.  
  159.     /**
  160.      * Set temporary storage directory
  161.      *
  162.      * @param    string    $pValue        Temporary storage directory
  163.      * @throws    Exception    Exception when directory does not exist
  164.      */
  165.     public function setTempDir($pValue ''{
  166.         if (is_dir($pValue)) {
  167.             $this->_tempDir = $pValue;
  168.         else {
  169.             throw new Exception("Directory does not exist: $pValue");
  170.         }
  171.     }
  172. }

Documentation generated on Wed, 22 Apr 2009 08:58:01 +0200 by phpDocumentor 1.4.1