You are here

private function PHPExcel_Reader_Excel5::_readDataValidation in Loft Data Grids 6.2

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

* Read DATAVALIDATION record

1 call to PHPExcel_Reader_Excel5::_readDataValidation()
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 4677

Class

PHPExcel_Reader_Excel5
PHPExcel_Reader_Excel5

Code

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

  // move stream pointer forward to next record
  $this->_pos += 4 + $length;
  if ($this->_readDataOnly) {
    return;
  }

  // offset: 0; size: 4; Options
  $options = self::_GetInt4d($recordData, 0);

  // bit: 0-3; mask: 0x0000000F; type
  $type = (0xf & $options) >> 0;
  switch ($type) {
    case 0x0:
      $type = PHPExcel_Cell_DataValidation::TYPE_NONE;
      break;
    case 0x1:
      $type = PHPExcel_Cell_DataValidation::TYPE_WHOLE;
      break;
    case 0x2:
      $type = PHPExcel_Cell_DataValidation::TYPE_DECIMAL;
      break;
    case 0x3:
      $type = PHPExcel_Cell_DataValidation::TYPE_LIST;
      break;
    case 0x4:
      $type = PHPExcel_Cell_DataValidation::TYPE_DATE;
      break;
    case 0x5:
      $type = PHPExcel_Cell_DataValidation::TYPE_TIME;
      break;
    case 0x6:
      $type = PHPExcel_Cell_DataValidation::TYPE_TEXTLENGTH;
      break;
    case 0x7:
      $type = PHPExcel_Cell_DataValidation::TYPE_CUSTOM;
      break;
  }

  // bit: 4-6; mask: 0x00000070; error type
  $errorStyle = (0x70 & $options) >> 4;
  switch ($errorStyle) {
    case 0x0:
      $errorStyle = PHPExcel_Cell_DataValidation::STYLE_STOP;
      break;
    case 0x1:
      $errorStyle = PHPExcel_Cell_DataValidation::STYLE_WARNING;
      break;
    case 0x2:
      $errorStyle = PHPExcel_Cell_DataValidation::STYLE_INFORMATION;
      break;
  }

  // bit: 7; mask: 0x00000080; 1= formula is explicit (only applies to list)
  // I have only seen cases where this is 1
  $explicitFormula = (0x80 & $options) >> 7;

  // bit: 8; mask: 0x00000100; 1= empty cells allowed
  $allowBlank = (0x100 & $options) >> 8;

  // bit: 9; mask: 0x00000200; 1= suppress drop down arrow in list type validity
  $suppressDropDown = (0x200 & $options) >> 9;

  // bit: 18; mask: 0x00040000; 1= show prompt box if cell selected
  $showInputMessage = (0x40000 & $options) >> 18;

  // bit: 19; mask: 0x00080000; 1= show error box if invalid values entered
  $showErrorMessage = (0x80000 & $options) >> 19;

  // bit: 20-23; mask: 0x00F00000; condition operator
  $operator = (0xf00000 & $options) >> 20;
  switch ($operator) {
    case 0x0:
      $operator = PHPExcel_Cell_DataValidation::OPERATOR_BETWEEN;
      break;
    case 0x1:
      $operator = PHPExcel_Cell_DataValidation::OPERATOR_NOTBETWEEN;
      break;
    case 0x2:
      $operator = PHPExcel_Cell_DataValidation::OPERATOR_EQUAL;
      break;
    case 0x3:
      $operator = PHPExcel_Cell_DataValidation::OPERATOR_NOTEQUAL;
      break;
    case 0x4:
      $operator = PHPExcel_Cell_DataValidation::OPERATOR_GREATERTHAN;
      break;
    case 0x5:
      $operator = PHPExcel_Cell_DataValidation::OPERATOR_LESSTHAN;
      break;
    case 0x6:
      $operator = PHPExcel_Cell_DataValidation::OPERATOR_GREATERTHANOREQUAL;
      break;
    case 0x7:
      $operator = PHPExcel_Cell_DataValidation::OPERATOR_LESSTHANOREQUAL;
      break;
  }

  // offset: 4; size: var; title of the prompt box
  $offset = 4;
  $string = self::_readUnicodeStringLong(substr($recordData, $offset));
  $promptTitle = $string['value'] !== chr(0) ? $string['value'] : '';
  $offset += $string['size'];

  // offset: var; size: var; title of the error box
  $string = self::_readUnicodeStringLong(substr($recordData, $offset));
  $errorTitle = $string['value'] !== chr(0) ? $string['value'] : '';
  $offset += $string['size'];

  // offset: var; size: var; text of the prompt box
  $string = self::_readUnicodeStringLong(substr($recordData, $offset));
  $prompt = $string['value'] !== chr(0) ? $string['value'] : '';
  $offset += $string['size'];

  // offset: var; size: var; text of the error box
  $string = self::_readUnicodeStringLong(substr($recordData, $offset));
  $error = $string['value'] !== chr(0) ? $string['value'] : '';
  $offset += $string['size'];

  // offset: var; size: 2; size of the formula data for the first condition
  $sz1 = self::_GetInt2d($recordData, $offset);
  $offset += 2;

  // offset: var; size: 2; not used
  $offset += 2;

  // offset: var; size: $sz1; formula data for first condition (without size field)
  $formula1 = substr($recordData, $offset, $sz1);
  $formula1 = pack('v', $sz1) . $formula1;

  // prepend the length
  try {
    $formula1 = $this
      ->_getFormulaFromStructure($formula1);

    // in list type validity, null characters are used as item separators
    if ($type == PHPExcel_Cell_DataValidation::TYPE_LIST) {
      $formula1 = str_replace(chr(0), ',', $formula1);
    }
  } catch (PHPExcel_Exception $e) {
    return;
  }
  $offset += $sz1;

  // offset: var; size: 2; size of the formula data for the first condition
  $sz2 = self::_GetInt2d($recordData, $offset);
  $offset += 2;

  // offset: var; size: 2; not used
  $offset += 2;

  // offset: var; size: $sz2; formula data for second condition (without size field)
  $formula2 = substr($recordData, $offset, $sz2);
  $formula2 = pack('v', $sz2) . $formula2;

  // prepend the length
  try {
    $formula2 = $this
      ->_getFormulaFromStructure($formula2);
  } catch (PHPExcel_Exception $e) {
    return;
  }
  $offset += $sz2;

  // offset: var; size: var; cell range address list with
  $cellRangeAddressList = $this
    ->_readBIFF8CellRangeAddressList(substr($recordData, $offset));
  $cellRangeAddresses = $cellRangeAddressList['cellRangeAddresses'];
  foreach ($cellRangeAddresses as $cellRange) {
    $stRange = $this->_phpSheet
      ->shrinkRangeToFit($cellRange);
    $stRange = PHPExcel_Cell::extractAllCellReferencesInRange($stRange);
    foreach ($stRange as $coordinate) {
      $objValidation = $this->_phpSheet
        ->getCell($coordinate)
        ->getDataValidation();
      $objValidation
        ->setType($type);
      $objValidation
        ->setErrorStyle($errorStyle);
      $objValidation
        ->setAllowBlank((bool) $allowBlank);
      $objValidation
        ->setShowInputMessage((bool) $showInputMessage);
      $objValidation
        ->setShowErrorMessage((bool) $showErrorMessage);
      $objValidation
        ->setShowDropDown(!$suppressDropDown);
      $objValidation
        ->setOperator($operator);
      $objValidation
        ->setErrorTitle($errorTitle);
      $objValidation
        ->setError($error);
      $objValidation
        ->setPromptTitle($promptTitle);
      $objValidation
        ->setPrompt($prompt);
      $objValidation
        ->setFormula1($formula1);
      $objValidation
        ->setFormula2($formula2);
    }
  }
}