Пример #1
0
 /**
  * Method for saving the whole OLE container (including files).
  * In fact, if called with an empty argument (or '-'), it saves to a
  * temporary file and then outputs it's contents to stdout.
  *
  * @param string $filename The name of the file where to save the OLE container
  * @access public
  * @return mixed true on success, PEAR_Error on failure
  */
 function save($filename)
 {
     // Initial Setting for saving
     $this->_BIG_BLOCK_SIZE = pow(2, isset($this->_BIG_BLOCK_SIZE) ? $this->_adjust2($this->_BIG_BLOCK_SIZE) : 9);
     $this->_SMALL_BLOCK_SIZE = pow(2, isset($this->_SMALL_BLOCK_SIZE) ? $this->_adjust2($this->_SMALL_BLOCK_SIZE) : 6);
     // Open temp file if we are sending output to stdout
     if ($filename == '-' || $filename == '') {
         $this->_tmp_filename = tempnam($this->_tmp_dir, "OLE_PPS_Root");
         $this->_FILEH_ = @fopen($this->_tmp_filename, "w+b");
         if ($this->_FILEH_ == false) {
             return $this->raiseError("Can't create temporary file.");
         }
     } else {
         $this->_FILEH_ = @fopen($filename, "wb");
         if ($this->_FILEH_ == false) {
             return $this->raiseError("Can't open {$filename}. It may be in use or protected.");
         }
     }
     // Make an array of PPS's (for Save)
     $aList = array();
     OLE_PPS_Root::_savePpsSetPnt($aList, array($this));
     // calculate values for header
     list($iSBDcnt, $iBBcnt, $iPPScnt) = $this->_calcSize($aList);
     //, $rhInfo);
     // Save Header
     $this->_saveHeader($iSBDcnt, $iBBcnt, $iPPScnt);
     // Make Small Data string (write SBD)
     $this->_data = $this->_makeSmallData($aList);
     // Write BB
     $this->_saveBigData($iSBDcnt, $aList);
     // Write PPS
     $this->_savePps($aList);
     // Write Big Block Depot and BDList and Adding Header informations
     $this->_saveBbd($iSBDcnt, $iBBcnt, $iPPScnt);
     // Close File, send it to stdout if necessary
     if ($filename == '-' || $filename == '') {
         fseek($this->_FILEH_, 0);
         fpassthru($this->_FILEH_);
         @fclose($this->_FILEH_);
         // Delete the temporary file.
         @unlink($this->_tmp_filename);
     } else {
         @fclose($this->_FILEH_);
     }
     return true;
 }
Пример #2
0
 /**
  * Store the workbook in an OLE container
  *
  * @access private
  * @return mixed true on success. PEAR_Error on failure
  */
 function _storeOLEFile()
 {
     if ($this->_BIFF_version == 0x600) {
         $OLE = new OLE_PPS_File(OLE::Asc2Ucs('Workbook'));
     } else {
         $OLE = new OLE_PPS_File(OLE::Asc2Ucs('Book'));
     }
     if ($this->_tmp_dir != '') {
         $OLE->setTempDir($this->_tmp_dir);
     }
     $res = $OLE->init();
     if ($this->isError($res)) {
         return $this->raiseError("OLE Error: " . $res->getMessage());
     }
     $OLE->append($this->_data);
     $total_worksheets = count($this->_worksheets);
     for ($i = 0; $i < $total_worksheets; $i++) {
         while ($tmp = $this->_worksheets[$i]->getData()) {
             $OLE->append($tmp);
         }
     }
     $root = new OLE_PPS_Root(time(), time(), array($OLE));
     if ($this->_tmp_dir != '') {
         $root->setTempDir($this->_tmp_dir);
     }
     $res = $root->save($this->_filename);
     if ($this->isError($res)) {
         return $this->raiseError("OLE Error: " . $res->getMessage());
     }
     return true;
 }
 /**
  * Store the workbook in an OLE container
  *
  * @access private
  * @return mixed true on success. PEAR_Error on failure
  */
 protected function storeOLEFile()
 {
     if ($this->BIFF_version == 0x600) {
         $OLE = new OLE_PPS_File(OLE::Asc2Ucs('Workbook'));
     } else {
         $OLE = new OLE_PPS_File(OLE::Asc2Ucs('Book'));
     }
     if ($this->temporaryDirectory != '') {
         $OLE->setTempDir($this->temporaryDirectory);
     }
     $res = $OLE->init();
     if ($this->isError($res)) {
         return $this->raiseError('OLE Error: ' . $res->getMessage());
     }
     $OLE->append($this->data);
     $total_worksheets = count($this->workSheet);
     for ($i = 0; $i < $total_worksheets; ++$i) {
         while ($tmp = $this->workSheet[$i]->getData()) {
             $OLE->append($tmp);
         }
     }
     $root = new OLE_PPS_Root(time(), time(), array($OLE));
     if ($this->temporaryDirectory != '') {
         $root->setTempDir($this->temporaryDirectory);
     }
     $res = $root->save($this->fileName);
     if ($this->isError($res)) {
         return $this->raiseError('OLE Error: ' . $res->getMessage());
     }
     return true;
 }