Blame view

vendor/phpoffice/phpspreadsheet/src/PhpSpreadsheet/Calculation/LookupRef/Formula.php 1.22 KB
2db47680   hexiaodong   chore: 初始提交 php 遗...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
  <?php
  
  namespace PhpOffice\PhpSpreadsheet\Calculation\LookupRef;
  
  use PhpOffice\PhpSpreadsheet\Calculation\Calculation;
  use PhpOffice\PhpSpreadsheet\Calculation\Functions;
  use PhpOffice\PhpSpreadsheet\Cell\Cell;
  
  class Formula
  {
      /**
       * FORMULATEXT.
       *
       * @param mixed $cellReference The cell to check
       * @param Cell $pCell The current cell (containing this formula)
       *
       * @return string
       */
      public static function text($cellReference = '', ?Cell $pCell = null)
      {
          if ($pCell === null) {
              return Functions::REF();
          }
  
          preg_match('/^' . Calculation::CALCULATION_REGEXP_CELLREF . '$/i', $cellReference, $matches);
  
          $cellReference = $matches[6] . $matches[7];
          $worksheetName = trim($matches[3], "'");
          $worksheet = (!empty($worksheetName))
              ? $pCell->getWorksheet()->getParent()->getSheetByName($worksheetName)
              : $pCell->getWorksheet();
  
          if (
              $worksheet === null ||
              !$worksheet->cellExists($cellReference) ||
              !$worksheet->getCell($cellReference)->isFormula()
          ) {
              return Functions::NA();
          }
  
          return $worksheet->getCell($cellReference)->getValue();
      }
  }