136 $writerPartsArray =
array(
'stringtable' =>
'PHPExcel_Writer_Excel2007_StringTable',
137 'contenttypes' =>
'PHPExcel_Writer_Excel2007_ContentTypes',
138 'docprops' =>
'PHPExcel_Writer_Excel2007_DocProps',
139 'rels' =>
'PHPExcel_Writer_Excel2007_Rels',
140 'theme' =>
'PHPExcel_Writer_Excel2007_Theme',
141 'style' =>
'PHPExcel_Writer_Excel2007_Style',
142 'workbook' =>
'PHPExcel_Writer_Excel2007_Workbook',
143 'worksheet' =>
'PHPExcel_Writer_Excel2007_Worksheet',
144 'drawing' =>
'PHPExcel_Writer_Excel2007_Drawing',
145 'comments' =>
'PHPExcel_Writer_Excel2007_Comments',
146 'chart' =>
'PHPExcel_Writer_Excel2007_Chart',
147 'relsvba' =>
'PHPExcel_Writer_Excel2007_RelsVBA',
148 'relsribbonobjects' =>
'PHPExcel_Writer_Excel2007_RelsRibbon' 153 foreach ($writerPartsArray as $writer => $class) {
154 $this->_writerParts[$writer] =
new $class($this);
157 $hashTablesArray =
array(
'_stylesConditionalHashTable',
'_fillHashTable',
'_fontHashTable',
158 '_bordersHashTable',
'_numFmtHashTable',
'_drawingHashTable',
163 foreach ($hashTablesArray as $tableName) {
175 if ($pPartName !=
'' && isset($this->_writerParts[strtolower($pPartName)])) {
176 return $this->_writerParts[strtolower($pPartName)];
188 public function save($pFilename = null)
190 if ($this->_spreadSheet !== NULL) {
192 $this->_spreadSheet->garbageCollect();
195 $originalFilename = $pFilename;
196 if (strtolower($pFilename) ==
'php://output' || strtolower($pFilename) ==
'php://stdout') {
198 if ($pFilename ==
'') {
199 $pFilename = $originalFilename;
209 $this->_stringTable =
array();
210 for ($i = 0; $i < $this->_spreadSheet->getSheetCount(); ++$i) {
215 $this->_styleHashTable->addFromSource( $this->
getWriterPart(
'Style')->allStyles($this->_spreadSheet) );
216 $this->_stylesConditionalHashTable->addFromSource( $this->
getWriterPart(
'Style')->allConditionalStyles($this->_spreadSheet) );
217 $this->_fillHashTable->addFromSource( $this->
getWriterPart(
'Style')->allFills($this->_spreadSheet) );
218 $this->_fontHashTable->addFromSource( $this->
getWriterPart(
'Style')->allFonts($this->_spreadSheet) );
219 $this->_bordersHashTable->addFromSource( $this->
getWriterPart(
'Style')->allBorders($this->_spreadSheet) );
220 $this->_numFmtHashTable->addFromSource( $this->
getWriterPart(
'Style')->allNumberFormats($this->_spreadSheet) );
223 $this->_drawingHashTable->addFromSource( $this->
getWriterPart(
'Drawing')->allDrawings($this->_spreadSheet) );
227 $objZip =
new $zipClass();
231 $ro =
new ReflectionObject($objZip);
232 $zipOverWrite = $ro->getConstant(
'OVERWRITE');
233 $zipCreate = $ro->getConstant(
'CREATE');
235 if (file_exists($pFilename)) {
239 if ($objZip->open($pFilename, $zipOverWrite) !==
true) {
240 if ($objZip->open($pFilename, $zipCreate) !==
true) {
246 $objZip->addFromString(
'[Content_Types].xml', $this->
getWriterPart(
'ContentTypes')->writeContentTypes($this->_spreadSheet, $this->_includeCharts));
249 if($this->_spreadSheet->hasMacros()){
250 $macrosCode=$this->_spreadSheet->getMacrosCode();
251 if(!is_null($macrosCode)){
252 $objZip->addFromString(
'xl/vbaProject.bin', $macrosCode);
253 if($this->_spreadSheet->hasMacrosCertificate()){
255 $objZip->addFromString(
'xl/vbaProjectSignature.bin', $this->_spreadSheet->getMacrosCertificate());
256 $objZip->addFromString(
'xl/_rels/vbaProject.bin.rels',
257 $this->
getWriterPart(
'RelsVBA')->writeVBARelationships($this->_spreadSheet));
262 if($this->_spreadSheet->hasRibbon()){
263 $tmpRibbonTarget=$this->_spreadSheet->getRibbonXMLData(
'target');
264 $objZip->addFromString($tmpRibbonTarget, $this->_spreadSheet->getRibbonXMLData(
'data'));
265 if($this->_spreadSheet->hasRibbonBinObjects()){
266 $tmpRootPath=dirname($tmpRibbonTarget).
'/';
267 $ribbonBinObjects=$this->_spreadSheet->getRibbonBinObjects(
'data');
268 foreach($ribbonBinObjects as $aPath=>$aContent){
269 $objZip->addFromString($tmpRootPath.$aPath, $aContent);
272 $objZip->addFromString($tmpRootPath.
'_rels/'.basename($tmpRibbonTarget).
'.rels',
273 $this->
getWriterPart(
'RelsRibbonObjects')->writeRibbonRelationships($this->_spreadSheet));
278 $objZip->addFromString(
'_rels/.rels', $this->
getWriterPart(
'Rels')->writeRelationships($this->_spreadSheet));
279 $objZip->addFromString(
'xl/_rels/workbook.xml.rels', $this->
getWriterPart(
'Rels')->writeWorkbookRelationships($this->_spreadSheet));
282 $objZip->addFromString(
'docProps/app.xml', $this->
getWriterPart(
'DocProps')->writeDocPropsApp($this->_spreadSheet));
283 $objZip->addFromString(
'docProps/core.xml', $this->
getWriterPart(
'DocProps')->writeDocPropsCore($this->_spreadSheet));
284 $customPropertiesPart = $this->
getWriterPart(
'DocProps')->writeDocPropsCustom($this->_spreadSheet);
285 if ($customPropertiesPart !== NULL) {
286 $objZip->addFromString(
'docProps/custom.xml', $customPropertiesPart);
290 $objZip->addFromString(
'xl/theme/theme1.xml', $this->
getWriterPart(
'Theme')->writeTheme($this->_spreadSheet));
293 $objZip->addFromString(
'xl/sharedStrings.xml', $this->
getWriterPart(
'StringTable')->writeStringTable($this->_stringTable));
296 $objZip->addFromString(
'xl/styles.xml', $this->
getWriterPart(
'Style')->writeStyles($this->_spreadSheet));
299 $objZip->addFromString(
'xl/workbook.xml', $this->
getWriterPart(
'Workbook')->writeWorkbook($this->_spreadSheet, $this->_preCalculateFormulas));
303 for ($i = 0; $i < $this->_spreadSheet->getSheetCount(); ++$i) {
305 if ($this->_includeCharts) {
306 $charts = $this->_spreadSheet->getSheet($i)->getChartCollection();
307 if (count($charts) > 0) {
308 foreach($charts as
$chart) {
309 $objZip->addFromString(
'xl/charts/chart' . ($chartCount + 1) .
'.xml', $this->
getWriterPart(
'Chart')->writeChart($chart));
316 $chartRef1 = $chartRef2 = 0;
318 for ($i = 0; $i < $this->_spreadSheet->getSheetCount(); ++$i) {
321 $objZip->addFromString(
'xl/worksheets/_rels/sheet' . ($i + 1) .
'.xml.rels', $this->
getWriterPart(
'Rels')->writeWorksheetRelationships($this->_spreadSheet->getSheet($i), ($i + 1), $this->_includeCharts));
323 $drawings = $this->_spreadSheet->getSheet($i)->getDrawingCollection();
324 $drawingCount = count($drawings);
325 if ($this->_includeCharts) {
326 $chartCount = $this->_spreadSheet->getSheet($i)->getChartCount();
330 if (($drawingCount > 0) || ($chartCount > 0)) {
332 $objZip->addFromString(
'xl/drawings/_rels/drawing' . ($i + 1) .
'.xml.rels', $this->
getWriterPart(
'Rels')->writeDrawingRelationships($this->_spreadSheet->getSheet($i),$chartRef1,
$this->_includeCharts));
335 $objZip->addFromString(
'xl/drawings/drawing' . ($i + 1) .
'.xml', $this->
getWriterPart(
'Drawing')->writeDrawings($this->_spreadSheet->getSheet($i),$chartRef2,
$this->_includeCharts));
339 if (count($this->_spreadSheet->getSheet($i)->getComments()) > 0) {
341 $objZip->addFromString(
'xl/drawings/vmlDrawing' . ($i + 1) .
'.vml', $this->
getWriterPart(
'Comments')->writeVMLComments($this->_spreadSheet->getSheet($i)));
344 $objZip->addFromString(
'xl/comments' . ($i + 1) .
'.xml', $this->
getWriterPart(
'Comments')->writeComments($this->_spreadSheet->getSheet($i)));
348 if (count($this->_spreadSheet->getSheet($i)->getHeaderFooter()->getImages()) > 0) {
350 $objZip->addFromString(
'xl/drawings/vmlDrawingHF' . ($i + 1) .
'.vml', $this->
getWriterPart(
'Drawing')->writeVMLHeaderFooterImages($this->_spreadSheet->getSheet($i)));
353 $objZip->addFromString(
'xl/drawings/_rels/vmlDrawingHF' . ($i + 1) .
'.vml.rels', $this->
getWriterPart(
'Rels')->writeHeaderFooterDrawingRelationships($this->_spreadSheet->getSheet($i)));
356 foreach ($this->_spreadSheet->getSheet($i)->getHeaderFooter()->getImages() as $image) {
357 $objZip->addFromString(
'xl/media/' . $image->getIndexedFilename(), file_get_contents($image->getPath()));
365 $imageContents = null;
367 if (strpos($imagePath,
'zip://') !==
false) {
368 $imagePath = substr($imagePath, 6);
369 $imagePathSplitted = explode(
'#', $imagePath);
371 $imageZip =
new ZipArchive();
372 $imageZip->open($imagePathSplitted[0]);
373 $imageContents = $imageZip->getFromName($imagePathSplitted[1]);
377 $imageContents = file_get_contents($imagePath);
380 $objZip->addFromString(
'xl/media/' . str_replace(
' ',
'_', $this->
getDrawingHashTable()->getByIndex($i)->getIndexedFilename()), $imageContents);
387 $imageContents = ob_get_contents();
390 $objZip->addFromString(
'xl/media/' . str_replace(
' ',
'_', $this->
getDrawingHashTable()->getByIndex($i)->getIndexedFilename()), $imageContents);
398 if ($objZip->close() ===
false) {
403 if ($originalFilename != $pFilename) {
404 if (copy($pFilename, $originalFilename) ===
false) {
421 if ($this->_spreadSheet !== null) {
436 $this->_spreadSheet = $pPHPExcel;
528 $this->_office2003compatibility = $pValue;
static getZipClass()
Return the name of the Zip handler Class that PHPExcel is configured to use (PCLZip or ZipArchive) or...
getStringTable()
Get string table.
getFillHashTable()
Get PHPExcel_Style_Fill HashTable.
$_office2003compatibility
getStylesConditionalHashTable()
Get PHPExcel_Style_Conditional HashTable.
getPHPExcel()
Get PHPExcel object.
setPHPExcel(PHPExcel $pPHPExcel=null)
Set PHPExcel object.
getFontHashTable()
Get PHPExcel_Style_Font HashTable.
getDrawingHashTable()
Get PHPExcel_Worksheet_BaseDrawing HashTable.
getNumFmtHashTable()
Get PHPExcel_Style_NumberFormat HashTable.
static sys_get_temp_dir()
Get the systems temporary directory.
static getReturnDateType()
getOffice2003Compatibility()
Get Office2003 compatibility.
Create styles array
The data for the language used.
getBordersHashTable()
Get PHPExcel_Style_Borders HashTable.
$_stylesConditionalHashTable
static setReturnDateType($returnDateType)
static getInstance(PHPExcel $workbook=NULL)
Get an instance of this class.
getStyleHashTable()
Get PHPExcel_Style HashTable.
__construct(PHPExcel $pPHPExcel=null)
Create a new PHPExcel_Writer_Excel2007.
save($pFilename=null)
Save PHPExcel to file.
getWriterPart($pPartName='')
Get writer part.
setOffice2003Compatibility($pValue=false)
Set Office2003 compatibility.