You are here

public function PHPExcel_Writer_Excel2007_StringTable::writeStringTable in Loft Data Grids 6.2

Same name and namespace in other branches
  1. 7.2 vendor/phpoffice/phpexcel/Classes/PHPExcel/Writer/Excel2007/StringTable.php \PHPExcel_Writer_Excel2007_StringTable::writeStringTable()

* Write string table to XML format * *

Parameters

string[] $pStringTable: * @return string XML Output * @throws PHPExcel_Writer_Exception

File

vendor/phpoffice/phpexcel/Classes/PHPExcel/Writer/Excel2007/StringTable.php, line 95

Class

PHPExcel_Writer_Excel2007_StringTable
PHPExcel_Writer_Excel2007_StringTable

Code

public function writeStringTable($pStringTable = null) {
  if ($pStringTable !== 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');

    // String table
    $objWriter
      ->startElement('sst');
    $objWriter
      ->writeAttribute('xmlns', 'http://schemas.openxmlformats.org/spreadsheetml/2006/main');
    $objWriter
      ->writeAttribute('uniqueCount', count($pStringTable));

    // Loop through string table
    foreach ($pStringTable as $textElement) {
      $objWriter
        ->startElement('si');
      if (!$textElement instanceof PHPExcel_RichText) {
        $textToWrite = PHPExcel_Shared_String::ControlCharacterPHP2OOXML($textElement);
        $objWriter
          ->startElement('t');
        if ($textToWrite !== trim($textToWrite)) {
          $objWriter
            ->writeAttribute('xml:space', 'preserve');
        }
        $objWriter
          ->writeRawData($textToWrite);
        $objWriter
          ->endElement();
      }
      else {
        if ($textElement instanceof PHPExcel_RichText) {
          $this
            ->writeRichText($objWriter, $textElement);
        }
      }
      $objWriter
        ->endElement();
    }
    $objWriter
      ->endElement();

    // Return
    return $objWriter
      ->getData();
  }
  else {
    throw new PHPExcel_Writer_Exception("Invalid string table array passed.");
  }
}