You are here

public function PHPExcel_Writer_Excel2007_Comments::writeComments in Loft Data Grids 6.2

Same name and namespace in other branches
  1. 7.2 vendor/phpoffice/phpexcel/Classes/PHPExcel/Writer/Excel2007/Comments.php \PHPExcel_Writer_Excel2007_Comments::writeComments()

* Write comments to XML format * *

Parameters

PHPExcel_Worksheet $pWorksheet: * @return string XML Output * @throws PHPExcel_Writer_Exception

File

vendor/phpoffice/phpexcel/Classes/PHPExcel/Writer/Excel2007/Comments.php, line 45

Class

PHPExcel_Writer_Excel2007_Comments
PHPExcel_Writer_Excel2007_Comments

Code

public function writeComments(PHPExcel_Worksheet $pWorksheet = null) {

  // 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');

  // Comments cache
  $comments = $pWorksheet
    ->getComments();

  // Authors cache
  $authors = array();
  $authorId = 0;
  foreach ($comments as $comment) {
    if (!isset($authors[$comment
      ->getAuthor()])) {
      $authors[$comment
        ->getAuthor()] = $authorId++;
    }
  }

  // comments
  $objWriter
    ->startElement('comments');
  $objWriter
    ->writeAttribute('xmlns', 'http://schemas.openxmlformats.org/spreadsheetml/2006/main');

  // Loop through authors
  $objWriter
    ->startElement('authors');
  foreach ($authors as $author => $index) {
    $objWriter
      ->writeElement('author', $author);
  }
  $objWriter
    ->endElement();

  // Loop through comments
  $objWriter
    ->startElement('commentList');
  foreach ($comments as $key => $value) {
    $this
      ->_writeComment($objWriter, $key, $value, $authors);
  }
  $objWriter
    ->endElement();
  $objWriter
    ->endElement();

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