Search moodle.org's
Developer Documentation

See Release Notes
Long Term Support Release

  • Bug fixes for general core bugs in 3.9.x will end* 10 May 2021 (12 months).
  • Bug fixes for security issues in 3.9.x will end* 8 May 2023 (36 months).
  • PHP version: minimum PHP 7.2.0 Note: minimum PHP version has increased since Moodle 3.8. PHP 7.3.x and 7.4.x are supported too.

Differences Between: [Versions 39 and 311] [Versions 39 and 400] [Versions 39 and 401] [Versions 39 and 402] [Versions 39 and 403]

   1  <?php
   2  
   3  namespace PhpOffice\PhpSpreadsheet\Reader\Xlsx;
   4  
   5  use PhpOffice\PhpSpreadsheet\Cell\Coordinate;
   6  use PhpOffice\PhpSpreadsheet\Worksheet\Worksheet;
   7  
   8  class DataValidations
   9  {
  10      private $worksheet;
  11  
  12      private $worksheetXml;
  13  
  14      public function __construct(Worksheet $workSheet, \SimpleXMLElement $worksheetXml)
  15      {
  16          $this->worksheet = $workSheet;
  17          $this->worksheetXml = $worksheetXml;
  18      }
  19  
  20      public function load()
  21      {
  22          foreach ($this->worksheetXml->dataValidations->dataValidation as $dataValidation) {
  23              // Uppercase coordinate
  24              $range = strtoupper($dataValidation['sqref']);
  25              $rangeSet = explode(' ', $range);
  26              foreach ($rangeSet as $range) {
  27                  $stRange = $this->worksheet->shrinkRangeToFit($range);
  28  
  29                  // Extract all cell references in $range
  30                  foreach (Coordinate::extractAllCellReferencesInRange($stRange) as $reference) {
  31                      // Create validation
  32                      $docValidation = $this->worksheet->getCell($reference)->getDataValidation();
  33                      $docValidation->setType((string) $dataValidation['type']);
  34                      $docValidation->setErrorStyle((string) $dataValidation['errorStyle']);
  35                      $docValidation->setOperator((string) $dataValidation['operator']);
  36                      $docValidation->setAllowBlank($dataValidation['allowBlank'] != 0);
  37                      $docValidation->setShowDropDown($dataValidation['showDropDown'] == 0);
  38                      $docValidation->setShowInputMessage($dataValidation['showInputMessage'] != 0);
  39                      $docValidation->setShowErrorMessage($dataValidation['showErrorMessage'] != 0);
  40                      $docValidation->setErrorTitle((string) $dataValidation['errorTitle']);
  41                      $docValidation->setError((string) $dataValidation['error']);
  42                      $docValidation->setPromptTitle((string) $dataValidation['promptTitle']);
  43                      $docValidation->setPrompt((string) $dataValidation['prompt']);
  44                      $docValidation->setFormula1((string) $dataValidation->formula1);
  45                      $docValidation->setFormula2((string) $dataValidation->formula2);
  46                  }
  47              }
  48          }
  49      }
  50  }