using OLE package for OLE container

git-svn-id: https://svn.php.net/repository/pear/packages/Spreadsheet_Excel_Writer/trunk@138419 c90b9560-bf6c-de11-be94-00142212c4b1
This commit is contained in:
Xavier Noguer Gallego 2003-08-21 14:05:57 +00:00
parent 4899df7fb4
commit a850ec9d03
1 changed files with 34 additions and 21 deletions

View File

@ -33,10 +33,11 @@
*/ */
require_once('Spreadsheet/Excel/Writer/Format.php'); require_once('Spreadsheet/Excel/Writer/Format.php');
require_once('Spreadsheet/Excel/Writer/OLEwriter.php');
require_once('Spreadsheet/Excel/Writer/BIFFwriter.php'); require_once('Spreadsheet/Excel/Writer/BIFFwriter.php');
require_once('Spreadsheet/Excel/Writer/Worksheet.php'); require_once('Spreadsheet/Excel/Writer/Worksheet.php');
require_once('Spreadsheet/Excel/Writer/Parser.php'); require_once('Spreadsheet/Excel/Writer/Parser.php');
require_once('OLE/PPS/Root.php');
require_once('OLE/PPS/File.php');
/** /**
* Class for generating Excel Spreadsheets * Class for generating Excel Spreadsheets
@ -184,17 +185,21 @@ class Spreadsheet_Excel_Writer_Workbook extends Spreadsheet_Excel_Writer_BIFFwri
* This method should always be the last one to be called on every workbook * This method should always be the last one to be called on every workbook
* *
* @access public * @access public
* @return mixed true on success. PEAR_Error on failure
*/ */
function close() function close()
{ {
if ($this->_fileclosed) { // Prevent close() from being called twice. if ($this->_fileclosed) { // Prevent close() from being called twice.
return; return true;
}
$res = $this->_storeWorkbook();
if ($this->isError($res)) {
$this->raiseError($res->getMessage());
} }
$this->_storeWorkbook();
$this->_fileclosed = 1; $this->_fileclosed = 1;
return true;
} }
/** /**
* An accessor for the _worksheets[] array * An accessor for the _worksheets[] array
* Returns an array of the worksheet objects in a workbook * Returns an array of the worksheet objects in a workbook
@ -388,6 +393,7 @@ class Spreadsheet_Excel_Writer_Workbook extends Spreadsheet_Excel_Writer_BIFFwri
* storage. * storage.
* *
* @access private * @access private
* @return mixed true on success. PEAR_Error on failure
*/ */
function _storeWorkbook() function _storeWorkbook()
{ {
@ -429,32 +435,39 @@ class Spreadsheet_Excel_Writer_Workbook extends Spreadsheet_Excel_Writer_BIFFwri
$this->_storeEof(); $this->_storeEof();
// Store the workbook in an OLE container // Store the workbook in an OLE container
$this->_storeOLEFile(); $res = $this->_storeOLEFile();
if ($this->isError($res)) {
$this->raiseError($res->getMessage());
}
return true;
} }
/** /**
* Store the workbook in an OLE container if the total size of the workbook data * Store the workbook in an OLE container
* is less than ~ 7MB.
* *
* @access private * @access private
* @return mixed true on success. PEAR_Error on failure
*/ */
function _storeOLEFile() function _storeOLEFile()
{ {
$OLE = new Spreadsheet_Excel_Writer_OLEwriter($this->_filename); $OLE = new OLE_PPS_File(OLE::Asc2Ucs('Book'));
$this->_tmp_filename = $OLE->_tmp_filename; $res = $OLE->init();
// Write Worksheet data if data <~ 7MB if ($this->isError($res)) {
if ($OLE->setSize($this->_biffsize)) $this->raiseError("OLE Error: ".$res->getMessage());
}
$OLE->append($this->_data);
foreach ($this->_worksheets as $sheet)
{ {
$OLE->writeHeader(); while ($tmp = $sheet->getData()) {
$OLE->write($this->_data); $OLE->append($tmp);
foreach($this->_worksheets as $sheet)
{
while ($tmp = $sheet->getData()) {
$OLE->write($tmp);
}
} }
} }
$OLE->close(); $root = new OLE_PPS_Root(time(), time(), array($OLE));
$res = $root->save($this->_filename);
if ($this->isError($res)) {
$this->raiseError("OLE Error: ".$res->getMessage());
}
return true;
} }
/** /**