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

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