30 if (!defined(
'PHPEXCEL_ROOT')) {
34 define(
'PHPEXCEL_ROOT', dirname(__FILE__) .
'/../../');
38 require_once PHPEXCEL_ROOT .
'PHPExcel.php';
41 require_once PHPEXCEL_ROOT .
'PHPExcel/HashTable.php';
44 require_once PHPEXCEL_ROOT .
'PHPExcel/IComparable.php';
47 require_once PHPEXCEL_ROOT .
'PHPExcel/Worksheet.php';
50 require_once PHPEXCEL_ROOT .
'PHPExcel/Cell.php';
53 require_once PHPEXCEL_ROOT .
'PHPExcel/Writer/IWriter.php';
89 public function save($pFilename = null)
91 if (!is_null($this->_spreadSheet)) {
93 $this->_spreadSheet->garbageCollect();
96 foreach ($this->_spreadSheet->getAllSheets() as $sheet) {
97 $sheet->garbageCollect();
101 $objZip =
new ZipArchive();
104 if ($objZip->open($pFilename, ZIPARCHIVE::OVERWRITE) !==
true) {
105 if ($objZip->open($pFilename, ZIPARCHIVE::CREATE) !==
true) {
106 throw new Exception(
"Could not open " . $pFilename .
" for writing.");
111 $sheetCount = $this->_spreadSheet->getSheetCount();
112 for ($i = 0; $i < $sheetCount; ++$i) {
113 for ($j = 0; $j < $this->_spreadSheet->getSheet($i)->getDrawingCollection()->count(); ++$j) {
115 $imgTemp = $this->_spreadSheet->getSheet($i)->getDrawingCollection()->offsetGet($j);
116 $objZip->addFromString(
'media/' . $imgTemp->getFilename(), file_get_contents($imgTemp->getPath()));
122 $objZip->addFromString(
'phpexcel.xml', $this->
_writeSerialized($this->_spreadSheet, $pFilename));
125 if ($objZip->close() ===
false) {
126 throw new Exception(
"Could not close zip file $pFilename.");
129 throw new Exception(
"PHPExcel object unassigned.");
140 if (!is_null($this->_spreadSheet)) {
143 throw new Exception(
"No PHPExcel assigned.");
155 $this->_spreadSheet = $pPHPExcel;
170 $pPHPExcel = clone $pPHPExcel;
173 $sheetCount = $pPHPExcel->getSheetCount();
174 for ($i = 0; $i < $sheetCount; ++$i) {
175 for ($j = 0; $j < $pPHPExcel->getSheet($i)->getDrawingCollection()->count(); ++$j) {
177 $imgTemp =& $pPHPExcel->getSheet($i)->getDrawingCollection()->offsetGet($j);
178 $imgTemp->setPath(
'zip://' . $pFilename .
'#media/' . $imgTemp->getFilename(),
false);
184 $objWriter =
new xmlWriter();
185 $objWriter->openMemory();
186 $objWriter->setIndent(
true);
189 $objWriter->startDocument(
'1.0',
'UTF-8',
'yes');
192 $objWriter->startElement(
'PHPExcel');
193 $objWriter->writeAttribute(
'version',
'1.7.0');
196 $objWriter->writeComment(
'This file has been generated using PHPExcel v1.7.0 (http://www.codeplex.com/PHPExcel). It contains a base64 encoded serialized version of the PHPExcel internal object.');
199 $objWriter->startElement(
'data');
200 $objWriter->writeCData( base64_encode(serialize($pPHPExcel)) );
201 $objWriter->endElement();
203 $objWriter->endElement();
206 return $objWriter->outputMemory(
true);