public function PHPExcel_Writer_Excel5::save in Loft Data Grids 7.2
Same name and namespace in other branches
- 6.2 vendor/phpoffice/phpexcel/Classes/PHPExcel/Writer/Excel5.php \PHPExcel_Writer_Excel5::save()
* Save PHPExcel to file * *
Parameters
string $pFilename: * @throws PHPExcel_Writer_Exception
Overrides PHPExcel_Writer_IWriter::save
File
- vendor/
phpoffice/ phpexcel/ Classes/ PHPExcel/ Writer/ Excel5.php, line 118
Class
- PHPExcel_Writer_Excel5
- PHPExcel_Writer_Excel5
Code
public function save($pFilename = null) {
// garbage collect
$this->_phpExcel
->garbageCollect();
$saveDebugLog = PHPExcel_Calculation::getInstance($this->_phpExcel)
->getDebugLog()
->getWriteDebugLog();
PHPExcel_Calculation::getInstance($this->_phpExcel)
->getDebugLog()
->setWriteDebugLog(FALSE);
$saveDateReturnType = PHPExcel_Calculation_Functions::getReturnDateType();
PHPExcel_Calculation_Functions::setReturnDateType(PHPExcel_Calculation_Functions::RETURNDATE_EXCEL);
// initialize colors array
$this->_colors = array();
// Initialise workbook writer
$this->_writerWorkbook = new PHPExcel_Writer_Excel5_Workbook($this->_phpExcel, $this->_str_total, $this->_str_unique, $this->_str_table, $this->_colors, $this->_parser);
// Initialise worksheet writers
$countSheets = $this->_phpExcel
->getSheetCount();
for ($i = 0; $i < $countSheets; ++$i) {
$this->_writerWorksheets[$i] = new PHPExcel_Writer_Excel5_Worksheet($this->_str_total, $this->_str_unique, $this->_str_table, $this->_colors, $this->_parser, $this->_preCalculateFormulas, $this->_phpExcel
->getSheet($i));
}
// build Escher objects. Escher objects for workbooks needs to be build before Escher object for workbook.
$this
->_buildWorksheetEschers();
$this
->_buildWorkbookEscher();
// add 15 identical cell style Xfs
// for now, we use the first cellXf instead of cellStyleXf
$cellXfCollection = $this->_phpExcel
->getCellXfCollection();
for ($i = 0; $i < 15; ++$i) {
$this->_writerWorkbook
->addXfWriter($cellXfCollection[0], true);
}
// add all the cell Xfs
foreach ($this->_phpExcel
->getCellXfCollection() as $style) {
$this->_writerWorkbook
->addXfWriter($style, false);
}
// add fonts from rich text eleemnts
for ($i = 0; $i < $countSheets; ++$i) {
foreach ($this->_writerWorksheets[$i]->_phpSheet
->getCellCollection() as $cellID) {
$cell = $this->_writerWorksheets[$i]->_phpSheet
->getCell($cellID);
$cVal = $cell
->getValue();
if ($cVal instanceof PHPExcel_RichText) {
$elements = $cVal
->getRichTextElements();
foreach ($elements as $element) {
if ($element instanceof PHPExcel_RichText_Run) {
$font = $element
->getFont();
$this->_writerWorksheets[$i]->_fntHashIndex[$font
->getHashCode()] = $this->_writerWorkbook
->_addFont($font);
}
}
}
}
}
// initialize OLE file
$workbookStreamName = 'Workbook';
$OLE = new PHPExcel_Shared_OLE_PPS_File(PHPExcel_Shared_OLE::Asc2Ucs($workbookStreamName));
// Write the worksheet streams before the global workbook stream,
// because the byte sizes of these are needed in the global workbook stream
$worksheetSizes = array();
for ($i = 0; $i < $countSheets; ++$i) {
$this->_writerWorksheets[$i]
->close();
$worksheetSizes[] = $this->_writerWorksheets[$i]->_datasize;
}
// add binary data for global workbook stream
$OLE
->append($this->_writerWorkbook
->writeWorkbook($worksheetSizes));
// add binary data for sheet streams
for ($i = 0; $i < $countSheets; ++$i) {
$OLE
->append($this->_writerWorksheets[$i]
->getData());
}
$this->_documentSummaryInformation = $this
->_writeDocumentSummaryInformation();
// initialize OLE Document Summary Information
if (isset($this->_documentSummaryInformation) && !empty($this->_documentSummaryInformation)) {
$OLE_DocumentSummaryInformation = new PHPExcel_Shared_OLE_PPS_File(PHPExcel_Shared_OLE::Asc2Ucs(chr(5) . 'DocumentSummaryInformation'));
$OLE_DocumentSummaryInformation
->append($this->_documentSummaryInformation);
}
$this->_summaryInformation = $this
->_writeSummaryInformation();
// initialize OLE Summary Information
if (isset($this->_summaryInformation) && !empty($this->_summaryInformation)) {
$OLE_SummaryInformation = new PHPExcel_Shared_OLE_PPS_File(PHPExcel_Shared_OLE::Asc2Ucs(chr(5) . 'SummaryInformation'));
$OLE_SummaryInformation
->append($this->_summaryInformation);
}
// define OLE Parts
$arrRootData = array(
$OLE,
);
// initialize OLE Properties file
if (isset($OLE_SummaryInformation)) {
$arrRootData[] = $OLE_SummaryInformation;
}
// initialize OLE Extended Properties file
if (isset($OLE_DocumentSummaryInformation)) {
$arrRootData[] = $OLE_DocumentSummaryInformation;
}
$root = new PHPExcel_Shared_OLE_PPS_Root(time(), time(), $arrRootData);
// save the OLE file
$res = $root
->save($pFilename);
PHPExcel_Calculation_Functions::setReturnDateType($saveDateReturnType);
PHPExcel_Calculation::getInstance($this->_phpExcel)
->getDebugLog()
->setWriteDebugLog($saveDebugLog);
}