You are here

public function PHPExcel_Writer_Excel2007_StringTable::createStringTable in Loft Data Grids 7.2

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

* Create worksheet stringtable * *

Parameters

PHPExcel_Worksheet $pSheet Worksheet: * @param string[] $pExistingTable Existing table to eventually merge with * @return string[] String table for worksheet * @throws PHPExcel_Writer_Exception

File

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

Class

PHPExcel_Writer_Excel2007_StringTable
PHPExcel_Writer_Excel2007_StringTable

Code

public function createStringTable($pSheet = null, $pExistingTable = null) {
  if ($pSheet !== NULL) {

    // Create string lookup table
    $aStringTable = array();
    $cellCollection = null;
    $aFlippedStringTable = null;

    // For faster lookup
    // Is an existing table given?
    if ($pExistingTable !== NULL && is_array($pExistingTable)) {
      $aStringTable = $pExistingTable;
    }

    // Fill index array
    $aFlippedStringTable = $this
      ->flipStringTable($aStringTable);

    // Loop through cells
    foreach ($pSheet
      ->getCellCollection() as $cellID) {
      $cell = $pSheet
        ->getCell($cellID);
      $cellValue = $cell
        ->getValue();
      if (!is_object($cellValue) && $cellValue !== NULL && $cellValue !== '' && !isset($aFlippedStringTable[$cellValue]) && ($cell
        ->getDataType() == PHPExcel_Cell_DataType::TYPE_STRING || $cell
        ->getDataType() == PHPExcel_Cell_DataType::TYPE_STRING2 || $cell
        ->getDataType() == PHPExcel_Cell_DataType::TYPE_NULL)) {
        $aStringTable[] = $cellValue;
        $aFlippedStringTable[$cellValue] = true;
      }
      elseif ($cellValue instanceof PHPExcel_RichText && $cellValue !== NULL && !isset($aFlippedStringTable[$cellValue
        ->getHashCode()])) {
        $aStringTable[] = $cellValue;
        $aFlippedStringTable[$cellValue
          ->getHashCode()] = true;
      }
    }

    // Return
    return $aStringTable;
  }
  else {
    throw new PHPExcel_Writer_Exception("Invalid PHPExcel_Worksheet object passed.");
  }
}