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

Source for file OLE_File.php

Documentation is available at OLE_File.php

  1. <?php
  2. /* vim: set expandtab tabstop=4 shiftwidth=4: */
  3. // +----------------------------------------------------------------------+
  4. // | PHP Version 4                                                        |
  5. // +----------------------------------------------------------------------+
  6. // | Copyright (c) 1997-2002 The PHP Group                                |
  7. // +----------------------------------------------------------------------+
  8. // | This source file is subject to version 2.02 of the PHP license,      |
  9. // | that is bundled with this package in the file LICENSE, and is        |
  10. // | available at through the world-wide-web at                           |
  11. // | http://www.php.net/license/2_02.txt.                                 |
  12. // | If you did not receive a copy of the PHP license and are unable to   |
  13. // | obtain it through the world-wide-web, please send a note to          |
  14. // | license@php.net so we can mail you a copy immediately.               |
  15. // +----------------------------------------------------------------------+
  16. // | Author: Xavier Noguer <xnoguer@php.net>                              |
  17. // | Based on OLE::Storage_Lite by Kawai, Takanori                        |
  18. // +----------------------------------------------------------------------+
  19. //
  20. // $Id: File.php,v 1.11 2007/02/13 21:00:42 schmidt Exp $
  21.  
  22.  
  23. require_once 'PHPExcel/Shared/OLE/OLE_PPS.php';
  24.  
  25. /**
  26. * Class for creating File PPS's for OLE containers
  27. *
  28. @author   Xavier Noguer <xnoguer@php.net>
  29. @category PHPExcel
  30. @package  PHPExcel_Shared_OLE
  31. */
  32.     {
  33.     /**
  34.     * The temporary dir for storing the OLE file
  35.     * @var string 
  36.     */
  37.     public $_tmp_dir;
  38.  
  39.     /**
  40.     * The constructor
  41.     *
  42.     * @access public
  43.     * @param string $name The name of the file (in Unicode)
  44.     * @see OLE::Asc2Ucs()
  45.     */
  46.     public function __construct($name)
  47.     {
  48.         $this->_tmp_dir = '';
  49.         parent::__construct(
  50.             null
  51.             $name,
  52.             PHPExcel_Shared_OLE::OLE_PPS_TYPE_FILE,
  53.             null,
  54.             null,
  55.             null,
  56.             null,
  57.             null,
  58.             '',
  59.             array());
  60.     }
  61.  
  62.     /**
  63.     * Sets the temp dir used for storing the OLE file
  64.     *
  65.     * @access public
  66.     * @param string $dir The dir to be used as temp dir
  67.     * @return true if given dir is valid, false otherwise
  68.     */
  69.     public function setTempDir($dir)
  70.     {
  71.         if (is_dir($dir)) {
  72.             $this->_tmp_dir = $dir;
  73.             return true;
  74.         }
  75.         return false;
  76.     }
  77.  
  78.     /**
  79.     * Initialization method. Has to be called right after OLE_PPS_File().
  80.     *
  81.     * @access public
  82.     * @return mixed true on success
  83.     */
  84.     public function init()
  85.     {
  86.         $this->_tmp_filename tempnam($this->_tmp_dir"OLE_PPS_File");
  87.         $fh fopen($this->_tmp_filename"w+b");
  88.         if ($fh === false{
  89.             throw new Exception("Can't create temporary file");
  90.         }
  91.         $this->_PPS_FILE $fh;
  92.         if ($this->_PPS_FILE{
  93.             fseek($this->_PPS_FILE0);
  94.         }
  95.         return true;
  96.     }
  97.  
  98.     /**
  99.     * Append data to PPS
  100.     *
  101.     * @access public
  102.     * @param string $data The data to append
  103.     */
  104.     public function append($data)
  105.     {
  106.         if ($this->_PPS_FILE{
  107.             fwrite($this->_PPS_FILE$data);
  108.         else {
  109.             $this->_data .= $data;
  110.         }
  111.     }
  112.  
  113.     /**
  114.      * Returns a stream for reading this file using fread() etc.
  115.      * @return  resource  a read-only stream
  116.      */
  117.     public function getStream()
  118.     {
  119.         $this->ole->getStream($this);
  120.     }
  121. }

Documentation generated on Mon, 05 Jan 2009 20:38:11 +0100 by phpDocumentor 1.4.1