Source for file Excel2007.php
Documentation is available at Excel2007.php
* Copyright (c) 2006 - 2009 PHPExcel
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
* @package PHPExcel_Writer_Excel2007
* @copyright Copyright (c) 2006 - 2009 PHPExcel (http://www.codeplex.com/PHPExcel)
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version 1.6.5, 2009-01-05
require_once 'PHPExcel.php';
/** PHPExcel_HashTable */
require_once 'PHPExcel/HashTable.php';
/** PHPExcel_IComparable */
require_once 'PHPExcel/IComparable.php';
/** PHPExcel_Worksheet */
require_once 'PHPExcel/Worksheet.php';
require_once 'PHPExcel/Cell.php';
require_once 'PHPExcel/Writer/IWriter.php';
/** PHPExcel_Shared_XMLWriter */
require_once 'PHPExcel/Shared/XMLWriter.php';
/** PHPExcel_Writer_Excel2007_WriterPart */
require_once 'PHPExcel/Writer/Excel2007/WriterPart.php';
/** PHPExcel_Writer_Excel2007_StringTable */
require_once 'PHPExcel/Writer/Excel2007/StringTable.php';
/** PHPExcel_Writer_Excel2007_ContentTypes */
require_once 'PHPExcel/Writer/Excel2007/ContentTypes.php';
/** PHPExcel_Writer_Excel2007_DocProps */
require_once 'PHPExcel/Writer/Excel2007/DocProps.php';
/** PHPExcel_Writer_Excel2007_Rels */
require_once 'PHPExcel/Writer/Excel2007/Rels.php';
/** PHPExcel_Writer_Excel2007_Theme */
require_once 'PHPExcel/Writer/Excel2007/Theme.php';
/** PHPExcel_Writer_Excel2007_Style */
require_once 'PHPExcel/Writer/Excel2007/Style.php';
/** PHPExcel_Writer_Excel2007_Workbook */
require_once 'PHPExcel/Writer/Excel2007/Workbook.php';
/** PHPExcel_Writer_Excel2007_Worksheet */
require_once 'PHPExcel/Writer/Excel2007/Worksheet.php';
/** PHPExcel_Writer_Excel2007_Drawing */
require_once 'PHPExcel/Writer/Excel2007/Drawing.php';
/** PHPExcel_Writer_Excel2007_Comments */
require_once 'PHPExcel/Writer/Excel2007/Comments.php';
* PHPExcel_Writer_Excel2007
* @package PHPExcel_Writer_Excel2007
* @copyright Copyright (c) 2006 - 2009 PHPExcel (http://www.codeplex.com/PHPExcel)
* Office2003 compatibility
* @var PHPExcel_Writer_Excel2007_WriterPart[]
* Private unique PHPExcel_Style HashTable
* @var PHPExcel_HashTable
* Private unique PHPExcel_Style_Conditional HashTable
* @var PHPExcel_HashTable
* Private unique PHPExcel_Style_Fill HashTable
* @var PHPExcel_HashTable
* Private unique PHPExcel_Style_Font HashTable
* @var PHPExcel_HashTable
* Private unique PHPExcel_Style_Borders HashTable
* @var PHPExcel_HashTable
* Private unique PHPExcel_Style_NumberFormat HashTable
* @var PHPExcel_HashTable
* Private unique PHPExcel_Worksheet_BaseDrawing HashTable
* @var PHPExcel_HashTable
* Use disk caching where possible?
* Create a new PHPExcel_Writer_Excel2007
* @param PHPExcel $pPHPExcel
public function __construct(PHPExcel $pPHPExcel = null)
// Initialise writer parts
$writer->setParentWriter($this);
// Set HashTable variables
$this->_serializePHPExcel = false;
* @param string $pPartName Writer part name
* @return PHPExcel_Writer_Excel2007_WriterPart
* @param string $pFileName
public function save($pFilename = null)
// If $pFilename is php://output or php://stdout, make it a temporary file...
$originalFilename = $pFilename;
$pFilename = @tempnam('./', 'phpxl');
$pFilename = $originalFilename;
// Create string lookup table
for ($i = 0; $i < $this->_spreadSheet->getSheetCount(); ++ $i) {
// Create styles dictionaries
// Create drawing dictionary
// Create new ZIP file and open it for writing
$objZip = new ZipArchive();
// Try opening the ZIP file
if ($objZip->open($pFilename, ZIPARCHIVE::OVERWRITE) !== true) {
if ($objZip->open($pFilename, ZIPARCHIVE::CREATE) !== true) {
throw new Exception("Could not open " . $pFilename . " for writing.");
// Add [Content_Types].xml to ZIP file
// Add relationships to ZIP file
$objZip->addFromString('xl/_rels/workbook.xml.rels', $this->getWriterPart('Rels')->writeWorkbookRelationships($this->_spreadSheet));
// Add document properties to ZIP file
// Add string table to ZIP file
// Add styles to ZIP file
// Add workbook to ZIP file
for ($i = 0; $i < $this->_spreadSheet->getSheetCount(); ++ $i) {
// Add worksheet relationships (drawings, ...)
for ($i = 0; $i < $this->_spreadSheet->getSheetCount(); ++ $i) {
$objZip->addFromString('xl/worksheets/_rels/sheet' . ($i + 1) . '.xml.rels', $this->getWriterPart('Rels')->writeWorksheetRelationships($this->_spreadSheet->getSheet($i), ($i + 1)));
// Add drawing relationship parts
if ($this->_spreadSheet->getSheet($i)->getDrawingCollection()->count() > 0) {
$objZip->addFromString('xl/drawings/_rels/drawing' . ($i + 1) . '.xml.rels', $this->getWriterPart('Rels')->writeDrawingRelationships($this->_spreadSheet->getSheet($i)));
$objZip->addFromString('xl/drawings/drawing' . ($i + 1) . '.xml', $this->getWriterPart('Drawing')->writeDrawings($this->_spreadSheet->getSheet($i)));
// Add comment relationship parts
$objZip->addFromString('xl/drawings/vmlDrawing' . ($i + 1) . '.vml', $this->getWriterPart('Comments')->writeVMLComments($this->_spreadSheet->getSheet($i)));
$objZip->addFromString('xl/comments' . ($i + 1) . '.xml', $this->getWriterPart('Comments')->writeComments($this->_spreadSheet->getSheet($i)));
// Add header/footer relationship parts
$objZip->addFromString('xl/drawings/vmlDrawingHF' . ($i + 1) . '.vml', $this->getWriterPart('Drawing')->writeVMLHeaderFooterImages($this->_spreadSheet->getSheet($i)));
// VML Drawing relationships
$objZip->addFromString('xl/drawings/_rels/vmlDrawingHF' . ($i + 1) . '.vml.rels', $this->getWriterPart('Rels')->writeHeaderFooterDrawingRelationships($this->_spreadSheet->getSheet($i)));
foreach ($this->_spreadSheet->getSheet($i)->getHeaderFooter()->getImages() as $image) {
$objZip->addFromString('xl/media/' . $image->getIndexedFilename(), file_get_contents($image->getPath()));
if (strpos($imagePath, 'zip://') !== false) {
$imagePath = substr($imagePath, 6);
$imagePathSplitted = explode('#', $imagePath);
$imageZip = new ZipArchive();
$imageZip->open($imagePathSplitted[0]);
$imageContents = $imageZip->getFromName($imagePathSplitted[1]);
if ($objZip->close() === false) {
throw new Exception("Could not close zip file $pFilename.");
// If a temporary file was used, copy it to the correct file stream
if ($originalFilename != $pFilename) {
if (copy($pFilename, $originalFilename) === false) {
throw new Exception("Could not copy temporary zip file $pFilename to $originalFilename.");
throw new Exception("PHPExcel object unassigned.");
throw new Exception("No PHPExcel assigned.");
* @param PHPExcel $pPHPExcel PHPExcel object
public function setPHPExcel(PHPExcel $pPHPExcel = null) {
* Get PHPExcel_Style HashTable
* @return PHPExcel_HashTable
* Get PHPExcel_Style_Conditional HashTable
* @return PHPExcel_HashTable
* Get PHPExcel_Style_Fill HashTable
* @return PHPExcel_HashTable
* Get PHPExcel_Style_Font HashTable
* @return PHPExcel_HashTable
* Get PHPExcel_Style_Borders HashTable
* @return PHPExcel_HashTable
* Get PHPExcel_Style_NumberFormat HashTable
* @return PHPExcel_HashTable
* Get PHPExcel_Worksheet_BaseDrawing HashTable
* @return PHPExcel_HashTable
* Get Pre-Calculate Formulas
* Set Pre-Calculate Formulas
* @param boolean $pValue Pre-Calculate Formulas?
* Get Office2003 compatibility
* Set Pre-Calculate Formulas
* @param boolean $pValue Office2003 compatibility?
* Get use disk caching where possible?
* Set use disk caching where possible?
|