You are here

public function PHPExcel_Writer_OpenDocument::save in Loft Data Grids 7.2

Same name and namespace in other branches
  1. 6.2 vendor/phpoffice/phpexcel/Classes/PHPExcel/Writer/OpenDocument.php \PHPExcel_Writer_OpenDocument::save()

Save PHPExcel to file

Parameters

string $pFilename:

Throws

PHPExcel_Writer_Exception

Overrides PHPExcel_Writer_IWriter::save

File

vendor/phpoffice/phpexcel/Classes/PHPExcel/Writer/OpenDocument.php, line 99

Class

PHPExcel_Writer_OpenDocument
PHPExcel_Writer_OpenDocument

Code

public function save($pFilename = NULL) {
  if (!$this->_spreadSheet) {
    throw new PHPExcel_Writer_Exception('PHPExcel object unassigned.');
  }

  // garbage collect
  $this->_spreadSheet
    ->garbageCollect();

  // If $pFilename is php://output or php://stdout, make it a temporary file...
  $originalFilename = $pFilename;
  if (strtolower($pFilename) == 'php://output' || strtolower($pFilename) == 'php://stdout') {
    $pFilename = @tempnam(PHPExcel_Shared_File::sys_get_temp_dir(), 'phpxltmp');
    if ($pFilename == '') {
      $pFilename = $originalFilename;
    }
  }
  $objZip = $this
    ->_createZip($pFilename);
  $objZip
    ->addFromString('META-INF/manifest.xml', $this
    ->getWriterPart('meta_inf')
    ->writeManifest());
  $objZip
    ->addFromString('Thumbnails/thumbnail.png', $this
    ->getWriterPart('thumbnails')
    ->writeThumbnail());
  $objZip
    ->addFromString('content.xml', $this
    ->getWriterPart('content')
    ->write());
  $objZip
    ->addFromString('meta.xml', $this
    ->getWriterPart('meta')
    ->write());
  $objZip
    ->addFromString('mimetype', $this
    ->getWriterPart('mimetype')
    ->write());
  $objZip
    ->addFromString('settings.xml', $this
    ->getWriterPart('settings')
    ->write());
  $objZip
    ->addFromString('styles.xml', $this
    ->getWriterPart('styles')
    ->write());

  // Close file
  if ($objZip
    ->close() === false) {
    throw new PHPExcel_Writer_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 PHPExcel_Writer_Exception("Could not copy temporary zip file {$pFilename} to {$originalFilename}.");
    }
    @unlink($pFilename);
  }
}