You are here

public function PHPExcel_Writer_Excel2007_Rels::writeDrawingRelationships in Loft Data Grids 7.2

Same name and namespace in other branches
  1. 6.2 vendor/phpoffice/phpexcel/Classes/PHPExcel/Writer/Excel2007/Rels.php \PHPExcel_Writer_Excel2007_Rels::writeDrawingRelationships()

* Write drawing relationships to XML format * *

Parameters

PHPExcel_Worksheet $pWorksheet: * @param int &$chartRef Chart ID * @param boolean $includeCharts Flag indicating if we should write charts * @return string XML Output * @throws PHPExcel_Writer_Exception

File

vendor/phpoffice/phpexcel/Classes/PHPExcel/Writer/Excel2007/Rels.php, line 311

Class

PHPExcel_Writer_Excel2007_Rels
PHPExcel_Writer_Excel2007_Rels

Code

public function writeDrawingRelationships(PHPExcel_Worksheet $pWorksheet = null, &$chartRef, $includeCharts = FALSE) {

  // Create XML writer
  $objWriter = null;
  if ($this
    ->getParentWriter()
    ->getUseDiskCaching()) {
    $objWriter = new PHPExcel_Shared_XMLWriter(PHPExcel_Shared_XMLWriter::STORAGE_DISK, $this
      ->getParentWriter()
      ->getDiskCachingDirectory());
  }
  else {
    $objWriter = new PHPExcel_Shared_XMLWriter(PHPExcel_Shared_XMLWriter::STORAGE_MEMORY);
  }

  // XML header
  $objWriter
    ->startDocument('1.0', 'UTF-8', 'yes');

  // Relationships
  $objWriter
    ->startElement('Relationships');
  $objWriter
    ->writeAttribute('xmlns', 'http://schemas.openxmlformats.org/package/2006/relationships');

  // Loop through images and write relationships
  $i = 1;
  $iterator = $pWorksheet
    ->getDrawingCollection()
    ->getIterator();
  while ($iterator
    ->valid()) {
    if ($iterator
      ->current() instanceof PHPExcel_Worksheet_Drawing || $iterator
      ->current() instanceof PHPExcel_Worksheet_MemoryDrawing) {

      // Write relationship for image drawing
      $this
        ->_writeRelationship($objWriter, $i, 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/image', '../media/' . str_replace(' ', '', $iterator
        ->current()
        ->getIndexedFilename()));
    }
    $iterator
      ->next();
    ++$i;
  }
  if ($includeCharts) {

    // Loop through charts and write relationships
    $chartCount = $pWorksheet
      ->getChartCount();
    if ($chartCount > 0) {
      for ($c = 0; $c < $chartCount; ++$c) {
        $this
          ->_writeRelationship($objWriter, $i++, 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/chart', '../charts/chart' . ++$chartRef . '.xml');
      }
    }
  }
  $objWriter
    ->endElement();

  // Return
  return $objWriter
    ->getData();
}