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 - 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_Excel5
  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_IWriter */
  38. require_once PHPEXCEL_ROOT 'PHPExcel/Writer/IWriter.php';
  39.  
  40. /** PHPExcel_Cell */
  41. require_once PHPEXCEL_ROOT 'PHPExcel/Cell.php';
  42.  
  43. /** PHPExcel_HashTable */
  44. require_once PHPEXCEL_ROOT 'PHPExcel/HashTable.php';
  45.  
  46. /** PHPExcel_Shared_File */
  47. require_once PHPEXCEL_ROOT 'PHPExcel/Shared/File.php';
  48.  
  49. /** PHPExcel_Shared_OLE_PPS_Root */
  50. require_once PHPEXCEL_ROOT 'PHPExcel/Shared/OLE/OLE_Root.php';
  51.  
  52. /** PHPExcel_Shared_OLE_PPS_File */
  53. require_once PHPEXCEL_ROOT 'PHPExcel/Shared/OLE/OLE_File.php';
  54.  
  55. /** PHPExcel_Writer_Excel5_Parser */
  56. require_once PHPEXCEL_ROOT 'PHPExcel/Writer/Excel5/Parser.php';
  57.  
  58. /** PHPExcel_Writer_Excel5_Workbook */
  59. require_once PHPEXCEL_ROOT 'PHPExcel/Writer/Excel5/Workbook.php';
  60.  
  61.  
  62. /**
  63.  * PHPExcel_Writer_Excel5
  64.  *
  65.  * @category   PHPExcel
  66.  * @package    PHPExcel_Writer_Excel5
  67.  * @copyright  Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/PHPExcel)
  68.  */
  69. class PHPExcel_Writer_Excel5 implements PHPExcel_Writer_IWriter
  70. {
  71.     /**
  72.      * Pre-calculate formulas
  73.      *
  74.      * @var boolean 
  75.      */
  76.     private $_preCalculateFormulas;
  77.  
  78.     /**
  79.      * PHPExcel object
  80.      *
  81.      * @var PHPExcel 
  82.      */
  83.     private $_phpExcel;
  84.  
  85.     /**
  86.      * The BIFF version of the written Excel file, BIFF5 = 0x0500, BIFF8 = 0x0600
  87.      *
  88.      * @var integer 
  89.      */
  90.     private $_BIFF_version;
  91.  
  92.     /**
  93.      * Temporary storage directory
  94.      *
  95.      * @var string 
  96.      */
  97.     private $_tempDir = '';
  98.  
  99.     /**
  100.      * Total number of shared strings in workbook
  101.      *
  102.      * @var int 
  103.      */
  104.     private $_str_total;
  105.  
  106.     /**
  107.      * Number of unique shared strings in workbook
  108.      *
  109.      * @var int 
  110.      */
  111.     private $_str_unique;
  112.  
  113.     /**
  114.      * Array of unique shared strings in workbook
  115.      *
  116.      * @var array 
  117.      */
  118.     private $_str_table;
  119.  
  120.     /**
  121.      * Color cache. Mapping between RGB value and color index.
  122.      *
  123.      * @var array 
  124.      */
  125.     private $_colors;
  126.  
  127.     /**
  128.      * Formula parser
  129.      *
  130.      * @var PHPExcel_Writer_Excel5_Parser 
  131.      */
  132.     private $_parser;
  133.  
  134.  
  135.     /**
  136.      * Create a new PHPExcel_Writer_Excel5
  137.      *
  138.      * @param    PHPExcel    $phpExcel    PHPExcel object
  139.      */
  140.     public function __construct(PHPExcel $phpExcel{
  141.         $this->_preCalculateFormulas = true;
  142.         $this->_phpExcel        = $phpExcel;
  143.         $this->_BIFF_version    = 0x0600;
  144.         $this->_tempDir            = PHPExcel_Shared_File::sys_get_temp_dir();
  145.         
  146.         $this->_str_total       = 0;
  147.         $this->_str_unique      = 0;
  148.         $this->_str_table       = array();
  149.         $this->_parser          = new PHPExcel_Writer_Excel5_Parser($this->_BIFF_version);
  150.         
  151.     }
  152.  
  153.     /**
  154.      * Save PHPExcel to file
  155.      *
  156.      * @param    string        $pFileName 
  157.      * @throws    Exception
  158.      */
  159.     public function save($pFilename null{
  160.  
  161.         // check mbstring.func_overload
  162.         if (ini_get('mbstring.func_overload'!= 0{
  163.             throw new Exception('Multibyte string function overloading in PHP must be disabled.');
  164.         }
  165.  
  166.         // garbage collect
  167.         $this->_phpExcel->garbageCollect();
  168.  
  169.         $saveDateReturnType PHPExcel_Calculation_Functions::getReturnDateType();
  170.  
  171.         // initialize colors array
  172.         $this->_colors          = array();
  173.  
  174.         // Initialise workbook writer
  175.         $this->_writerWorkbook new PHPExcel_Writer_Excel5_Workbook($this->_phpExcel$this->_BIFF_version,
  176.                     $this->_str_total$this->_str_unique$this->_str_table$this->_colors$this->_parser$this->_tempDir);
  177.  
  178.         // Initialise worksheet writers
  179.         $countSheets count($this->_phpExcel->getAllSheets());
  180.         for ($i 0$i $countSheets++$i{
  181.             $phpSheet  $this->_phpExcel->getSheet($i);
  182.             
  183.             $writerWorksheet new PHPExcel_Writer_Excel5_Worksheet($this->_BIFF_version,
  184.                                        $this->_str_total$this->_str_unique,
  185.                                        $this->_str_table$this->_colors,
  186.                                        $this->_parser$this->_tempDir,
  187.                                        $this->_preCalculateFormulas,
  188.                                        $phpSheet);
  189.             $this->_writerWorksheets[$i$writerWorksheet;
  190.         }
  191.  
  192.         // add 15 identical cell style Xfs
  193.         // for now, we use the first cellXf instead of cellStyleXf
  194.         $cellXfCollection $this->_phpExcel->getCellXfCollection();
  195.         for ($i 0$i 15++$i{
  196.             $this->_writerWorkbook->addXfWriter($cellXfCollection[0]true);
  197.         }
  198.  
  199.         // add all the cell Xfs
  200.         foreach ($this->_phpExcel->getCellXfCollection(as $style{
  201.             $this->_writerWorkbook->addXfWriter($stylefalse);
  202.         }
  203.  
  204.         // initialize OLE file
  205.         $workbookStreamName ($this->_BIFF_version == 0x0600'Workbook' 'Book';
  206.         $OLE new PHPExcel_Shared_OLE_PPS_File(PHPExcel_Shared_OLE::Asc2Ucs($workbookStreamName));
  207.  
  208.         if ($this->_tempDir != ''{
  209.             $OLE->setTempDir($this->_tempDir);
  210.         }
  211.         $res $OLE->init();
  212.  
  213.         // Write the worksheet streams before the global workbook stream,
  214.         // because the byte sizes of these are needed in the global workbook stream
  215.         $worksheetSizes array();
  216.         for ($i 0$i $countSheets++$i{
  217.             $this->_writerWorksheets[$i]->close();
  218.             $worksheetSizes[$this->_writerWorksheets[$i]->_datasize;
  219.         }
  220.  
  221.         // add binary data for global workbook stream
  222.         $OLE->append$this->_writerWorkbook->writeWorkbook($worksheetSizes) );
  223.  
  224.         // add binary data for sheet streams
  225.         for ($i 0$i $countSheets++$i{
  226.             while ( ($tmp $this->_writerWorksheets[$i]->getData()) !== false {
  227.                 $OLE->append($tmp);
  228.             }
  229.         }
  230.  
  231.         $root new PHPExcel_Shared_OLE_PPS_Root(time()time()array($OLE));
  232.         if ($this->_tempDir != ''{
  233.             $root->setTempDir($this->_tempDir);
  234.         }
  235.  
  236.         // save the OLE file
  237.         $res $root->save($pFilename);
  238.  
  239.         PHPExcel_Calculation_Functions::setReturnDateType($saveDateReturnType);
  240.  
  241.         // clean up
  242.         foreach ($this->_writerWorksheets as $sheet{
  243.             $sheet->cleanup();
  244.         }
  245.     }
  246.  
  247.     /**
  248.      * Get temporary storage directory
  249.      *
  250.      * @return string 
  251.      */
  252.     public function getTempDir({
  253.         return $this->_tempDir;
  254.     }
  255.  
  256.     /**
  257.      * Set temporary storage directory
  258.      *
  259.      * @param    string    $pValue        Temporary storage directory
  260.      * @throws    Exception    Exception when directory does not exist
  261.      * @return PHPExcel_Writer_Excel5 
  262.      */
  263.     public function setTempDir($pValue ''{
  264.         if (is_dir($pValue)) {
  265.             $this->_tempDir = $pValue;
  266.         else {
  267.             throw new Exception("Directory does not exist: $pValue");
  268.         }
  269.         return $this;
  270.     }
  271.  
  272.     /**
  273.      * Get Pre-Calculate Formulas
  274.      *
  275.      * @return boolean 
  276.      */
  277.     public function getPreCalculateFormulas({
  278.         return $this->_preCalculateFormulas;
  279.     }
  280.  
  281.     /**
  282.      * Set Pre-Calculate Formulas
  283.      *
  284.      * @param boolean $pValue    Pre-Calculate Formulas?
  285.      */
  286.     public function setPreCalculateFormulas($pValue true{
  287.         $this->_preCalculateFormulas = $pValue;
  288.     }
  289.  
  290. }

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