You are here

private function PHPExcel_Reader_Excel5::_readLabelSst in Loft Data Grids 7.2

Same name and namespace in other branches
  1. 6.2 vendor/phpoffice/phpexcel/Classes/PHPExcel/Reader/Excel5.php \PHPExcel_Reader_Excel5::_readLabelSst()

* Read LABELSST record * This record represents a cell that contains a string. It * replaces the LABEL record and RSTRING record used in * BIFF2-BIFF5. * * -- "OpenOffice.org's Documentation of the Microsoft * Excel File Format"

1 call to PHPExcel_Reader_Excel5::_readLabelSst()
PHPExcel_Reader_Excel5::load in vendor/phpoffice/phpexcel/Classes/PHPExcel/Reader/Excel5.php
* Loads PHPExcel from file * *

File

vendor/phpoffice/phpexcel/Classes/PHPExcel/Reader/Excel5.php, line 3616

Class

PHPExcel_Reader_Excel5
PHPExcel_Reader_Excel5

Code

private function _readLabelSst() {
  $length = self::_GetInt2d($this->_data, $this->_pos + 2);
  $recordData = $this
    ->_readRecordData($this->_data, $this->_pos + 4, $length);

  // move stream pointer to next record
  $this->_pos += 4 + $length;

  // offset: 0; size: 2; index to row
  $row = self::_GetInt2d($recordData, 0);

  // offset: 2; size: 2; index to column
  $column = self::_GetInt2d($recordData, 2);
  $columnString = PHPExcel_Cell::stringFromColumnIndex($column);

  // Read cell?
  if ($this
    ->getReadFilter() !== NULL && $this
    ->getReadFilter()
    ->readCell($columnString, $row + 1, $this->_phpSheet
    ->getTitle())) {

    // offset: 4; size: 2; index to XF record
    $xfIndex = self::_GetInt2d($recordData, 4);

    // offset: 6; size: 4; index to SST record
    $index = self::_GetInt4d($recordData, 6);

    // add cell
    if (($fmtRuns = $this->_sst[$index]['fmtRuns']) && !$this->_readDataOnly) {

      // then we should treat as rich text
      $richText = new PHPExcel_RichText();
      $charPos = 0;
      $sstCount = count($this->_sst[$index]['fmtRuns']);
      for ($i = 0; $i <= $sstCount; ++$i) {
        if (isset($fmtRuns[$i])) {
          $text = PHPExcel_Shared_String::Substring($this->_sst[$index]['value'], $charPos, $fmtRuns[$i]['charPos'] - $charPos);
          $charPos = $fmtRuns[$i]['charPos'];
        }
        else {
          $text = PHPExcel_Shared_String::Substring($this->_sst[$index]['value'], $charPos, PHPExcel_Shared_String::CountCharacters($this->_sst[$index]['value']));
        }
        if (PHPExcel_Shared_String::CountCharacters($text) > 0) {
          if ($i == 0) {

            // first text run, no style
            $richText
              ->createText($text);
          }
          else {
            $textRun = $richText
              ->createTextRun($text);
            if (isset($fmtRuns[$i - 1])) {
              if ($fmtRuns[$i - 1]['fontIndex'] < 4) {
                $fontIndex = $fmtRuns[$i - 1]['fontIndex'];
              }
              else {

                // this has to do with that index 4 is omitted in all BIFF versions for some strange reason
                // check the OpenOffice documentation of the FONT record
                $fontIndex = $fmtRuns[$i - 1]['fontIndex'] - 1;
              }
              $textRun
                ->setFont(clone $this->_objFonts[$fontIndex]);
            }
          }
        }
      }
      $cell = $this->_phpSheet
        ->getCell($columnString . ($row + 1));
      $cell
        ->setValueExplicit($richText, PHPExcel_Cell_DataType::TYPE_STRING);
    }
    else {
      $cell = $this->_phpSheet
        ->getCell($columnString . ($row + 1));
      $cell
        ->setValueExplicit($this->_sst[$index]['value'], PHPExcel_Cell_DataType::TYPE_STRING);
    }
    if (!$this->_readDataOnly) {

      // add style information
      $cell
        ->setXfIndex($this->_mapCellXfIndex[$xfIndex]);
    }
  }
}