Search moodle.org's
Developer Documentation

See Release Notes
Long Term Support Release

  • Bug fixes for general core bugs in 4.1.x will end 13 November 2023 (12 months).
  • Bug fixes for security issues in 4.1.x will end 10 November 2025 (36 months).
  • PHP version: minimum PHP 7.4.0 Note: minimum PHP version has increased since Moodle 4.0. PHP 8.0.x is supported too.

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

   1  <?php
   2  
   3  namespace PhpOffice\PhpSpreadsheet\Calculation;
   4  
   5  use PhpOffice\PhpSpreadsheet\Calculation\LookupRef\Address;
   6  use PhpOffice\PhpSpreadsheet\Calculation\LookupRef\HLookup;
   7  use PhpOffice\PhpSpreadsheet\Calculation\LookupRef\Indirect;
   8  use PhpOffice\PhpSpreadsheet\Calculation\LookupRef\Lookup;
   9  use PhpOffice\PhpSpreadsheet\Calculation\LookupRef\Matrix;
  10  use PhpOffice\PhpSpreadsheet\Calculation\LookupRef\Offset;
  11  use PhpOffice\PhpSpreadsheet\Calculation\LookupRef\RowColumnInformation;
  12  use PhpOffice\PhpSpreadsheet\Calculation\LookupRef\VLookup;
  13  use PhpOffice\PhpSpreadsheet\Cell\Cell;
  14  use PhpOffice\PhpSpreadsheet\Worksheet\Worksheet;
  15  
  16  /**
  17   * @deprecated 1.18.0
  18   */
  19  class LookupRef
  20  {
  21      /**
  22       * CELL_ADDRESS.
  23       *
  24       * Creates a cell address as text, given specified row and column numbers.
  25       *
  26       * Excel Function:
  27       *        =ADDRESS(row, column, [relativity], [referenceStyle], [sheetText])
  28       *
  29       * @Deprecated 1.18.0
  30       *
  31       * @see LookupRef\Address::cell()
  32       *      Use the cell() method in the LookupRef\Address class instead
  33       *
  34       * @param mixed $row Row number to use in the cell reference
  35       * @param mixed $column Column number to use in the cell reference
  36       * @param int $relativity Flag indicating the type of reference to return
  37       *                                1 or omitted    Absolute
  38       *                                2               Absolute row; relative column
  39       *                                3               Relative row; absolute column
  40       *                                4               Relative
  41       * @param bool $referenceStyle A logical value that specifies the A1 or R1C1 reference style.
  42       *                                TRUE or omitted      CELL_ADDRESS returns an A1-style reference
  43       *                                FALSE                CELL_ADDRESS returns an R1C1-style reference
  44       * @param array|string $sheetText Optional Name of worksheet to use
  45       *
  46       * @return array|string
  47       */
  48      public static function cellAddress($row, $column, $relativity = 1, $referenceStyle = true, $sheetText = '')
  49      {
  50          return Address::cell($row, $column, $relativity, $referenceStyle, $sheetText);
  51      }
  52  
  53      /**
  54       * COLUMN.
  55       *
  56       * Returns the column number of the given cell reference
  57       *     If the cell reference is a range of cells, COLUMN returns the column numbers of each column
  58       *        in the reference as a horizontal array.
  59       *     If cell reference is omitted, and the function is being called through the calculation engine,
  60       *        then it is assumed to be the reference of the cell in which the COLUMN function appears;
  61       *        otherwise this function returns 1.
  62       *
  63       * Excel Function:
  64       *        =COLUMN([cellAddress])
  65       *
  66       * @Deprecated 1.18.0
  67       *
  68       * @see LookupRef\RowColumnInformation::COLUMN()
  69       *      Use the COLUMN() method in the LookupRef\RowColumnInformation class instead
  70       *
  71       * @param null|array|string $cellAddress A reference to a range of cells for which you want the column numbers
  72       *
  73       * @return int|int[]|string
  74       */
  75      public static function COLUMN($cellAddress = null, ?Cell $cell = null)
  76      {
  77          return RowColumnInformation::COLUMN($cellAddress, $cell);
  78      }
  79  
  80      /**
  81       * COLUMNS.
  82       *
  83       * Returns the number of columns in an array or reference.
  84       *
  85       * Excel Function:
  86       *        =COLUMNS(cellAddress)
  87       *
  88       * @Deprecated 1.18.0
  89       *
  90       * @see LookupRef\RowColumnInformation::COLUMNS()
  91       *      Use the COLUMNS() method in the LookupRef\RowColumnInformation class instead
  92       *
  93       * @param null|array|string $cellAddress An array or array formula, or a reference to a range of cells
  94       *                                          for which you want the number of columns
  95       *
  96       * @return int|string The number of columns in cellAddress, or a string if arguments are invalid
  97       */
  98      public static function COLUMNS($cellAddress = null)
  99      {
 100          return RowColumnInformation::COLUMNS($cellAddress);
 101      }
 102  
 103      /**
 104       * ROW.
 105       *
 106       * Returns the row number of the given cell reference
 107       *     If the cell reference is a range of cells, ROW returns the row numbers of each row in the reference
 108       *        as a vertical array.
 109       *     If cell reference is omitted, and the function is being called through the calculation engine,
 110       *        then it is assumed to be the reference of the cell in which the ROW function appears;
 111       *        otherwise this function returns 1.
 112       *
 113       * Excel Function:
 114       *        =ROW([cellAddress])
 115       *
 116       * @Deprecated 1.18.0
 117       *
 118       * @see LookupRef\RowColumnInformation::ROW()
 119       *      Use the ROW() method in the LookupRef\RowColumnInformation class instead
 120       *
 121       * @param null|array|string $cellAddress A reference to a range of cells for which you want the row numbers
 122       *
 123       * @return int|mixed[]|string
 124       */
 125      public static function ROW($cellAddress = null, ?Cell $cell = null)
 126      {
 127          return RowColumnInformation::ROW($cellAddress, $cell);
 128      }
 129  
 130      /**
 131       * ROWS.
 132       *
 133       * Returns the number of rows in an array or reference.
 134       *
 135       * Excel Function:
 136       *        =ROWS(cellAddress)
 137       *
 138       * @Deprecated 1.18.0
 139       *
 140       * @see LookupRef\RowColumnInformation::ROWS()
 141       *      Use the ROWS() method in the LookupRef\RowColumnInformation class instead
 142       *
 143       * @param null|array|string $cellAddress An array or array formula, or a reference to a range of cells
 144       *                                          for which you want the number of rows
 145       *
 146       * @return int|string The number of rows in cellAddress, or a string if arguments are invalid
 147       */
 148      public static function ROWS($cellAddress = null)
 149      {
 150          return RowColumnInformation::ROWS($cellAddress);
 151      }
 152  
 153      /**
 154       * HYPERLINK.
 155       *
 156       * Excel Function:
 157       *        =HYPERLINK(linkURL,displayName)
 158       *
 159       * @Deprecated 1.18.0
 160       *
 161       * @param mixed $linkURL Expect string. Value to check, is also the value returned when no error
 162       * @param mixed $displayName Expect string. Value to return when testValue is an error condition
 163       * @param Cell $cell The cell to set the hyperlink in
 164       *
 165       * @return string The value of $displayName (or $linkURL if $displayName was blank)
 166       *
 167       *@see LookupRef\Hyperlink::set()
 168       *      Use the set() method in the LookupRef\Hyperlink class instead
 169       */
 170      public static function HYPERLINK($linkURL = '', $displayName = null, ?Cell $cell = null)
 171      {
 172          return LookupRef\Hyperlink::set($linkURL, $displayName, $cell);
 173      }
 174  
 175      /**
 176       * INDIRECT.
 177       *
 178       * Returns the reference specified by a text string.
 179       * References are immediately evaluated to display their contents.
 180       *
 181       * Excel Function:
 182       *        =INDIRECT(cellAddress)
 183       *
 184       * @Deprecated 1.18.0
 185       *
 186       * @param array|string $cellAddress $cellAddress The cell address of the current cell (containing this formula)
 187       * @param Cell $cell The current cell (containing this formula)
 188       *
 189       * @return array|string An array containing a cell or range of cells, or a string on error
 190       *
 191       *@see LookupRef\Indirect::INDIRECT()
 192       *      Use the INDIRECT() method in the LookupRef\Indirect class instead
 193       *
 194       * NOTE - INDIRECT() does not yet support the optional a1 parameter introduced in Excel 2010
 195       */
 196      public static function INDIRECT($cellAddress, Cell $cell)
 197      {
 198          return Indirect::INDIRECT($cellAddress, true, $cell);
 199      }
 200  
 201      /**
 202       * OFFSET.
 203       *
 204       * Returns a reference to a range that is a specified number of rows and columns from a cell or range of cells.
 205       * The reference that is returned can be a single cell or a range of cells. You can specify the number of rows and
 206       * the number of columns to be returned.
 207       *
 208       * Excel Function:
 209       *        =OFFSET(cellAddress, rows, cols, [height], [width])
 210       *
 211       * @Deprecated 1.18.0
 212       *
 213       * @see LookupRef\Offset::OFFSET()
 214       *      Use the OFFSET() method in the LookupRef\Offset class instead
 215       *
 216       * @param null|string $cellAddress The reference from which you want to base the offset.
 217       *                                     Reference must refer to a cell or range of adjacent cells;
 218       *                                     otherwise, OFFSET returns the #VALUE! error value.
 219       * @param mixed $rows The number of rows, up or down, that you want the upper-left cell to refer to.
 220       *                        Using 5 as the rows argument specifies that the upper-left cell in the
 221       *                        reference is five rows below reference. Rows can be positive (which means
 222       *                        below the starting reference) or negative (which means above the starting
 223       *                        reference).
 224       * @param mixed $columns The number of columns, to the left or right, that you want the upper-left cell
 225       *                           of the result to refer to. Using 5 as the cols argument specifies that the
 226       *                           upper-left cell in the reference is five columns to the right of reference.
 227       *                           Cols can be positive (which means to the right of the starting reference)
 228       *                           or negative (which means to the left of the starting reference).
 229       * @param mixed $height The height, in number of rows, that you want the returned reference to be.
 230       *                          Height must be a positive number.
 231       * @param mixed $width The width, in number of columns, that you want the returned reference to be.
 232       *                         Width must be a positive number.
 233       *
 234       * @return array|string An array containing a cell or range of cells, or a string on error
 235       */
 236      public static function OFFSET($cellAddress = null, $rows = 0, $columns = 0, $height = null, $width = null, ?Cell $cell = null)
 237      {
 238          return Offset::OFFSET($cellAddress, $rows, $columns, $height, $width, $cell);
 239      }
 240  
 241      /**
 242       * CHOOSE.
 243       *
 244       * Uses lookup_value to return a value from the list of value arguments.
 245       * Use CHOOSE to select one of up to 254 values based on the lookup_value.
 246       *
 247       * Excel Function:
 248       *        =CHOOSE(index_num, value1, [value2], ...)
 249       *
 250       * @Deprecated 1.18.0
 251       *
 252       * @see LookupRef\Selection::choose()
 253       *      Use the choose() method in the LookupRef\Selection class instead
 254       *
 255       * @return mixed The selected value
 256       */
 257      public static function CHOOSE(...$chooseArgs)
 258      {
 259          return LookupRef\Selection::choose(...$chooseArgs);
 260      }
 261  
 262      /**
 263       * MATCH.
 264       *
 265       * The MATCH function searches for a specified item in a range of cells
 266       *
 267       * Excel Function:
 268       *        =MATCH(lookup_value, lookup_array, [match_type])
 269       *
 270       * @Deprecated 1.18.0
 271       *
 272       * @see LookupRef\ExcelMatch::MATCH()
 273       *      Use the MATCH() method in the LookupRef\ExcelMatch class instead
 274       *
 275       * @param mixed $lookupValue The value that you want to match in lookup_array
 276       * @param mixed $lookupArray The range of cells being searched
 277       * @param mixed $matchType The number -1, 0, or 1. -1 means above, 0 means exact match, 1 means below.
 278       *                         If match_type is 1 or -1, the list has to be ordered.
 279       *
 280       * @return array|int|string The relative position of the found item
 281       */
 282      public static function MATCH($lookupValue, $lookupArray, $matchType = 1)
 283      {
 284          return LookupRef\ExcelMatch::MATCH($lookupValue, $lookupArray, $matchType);
 285      }
 286  
 287      /**
 288       * INDEX.
 289       *
 290       * Uses an index to choose a value from a reference or array
 291       *
 292       * Excel Function:
 293       *        =INDEX(range_array, row_num, [column_num])
 294       *
 295       * @Deprecated 1.18.0
 296       *
 297       * @see LookupRef\Matrix::index()
 298       *      Use the index() method in the LookupRef\Matrix class instead
 299       *
 300       * @param mixed $rowNum The row in the array or range from which to return a value.
 301       *                          If row_num is omitted, column_num is required.
 302       * @param mixed $columnNum The column in the array or range from which to return a value.
 303       *                             If column_num is omitted, row_num is required.
 304       * @param mixed $matrix
 305       *
 306       * @return mixed the value of a specified cell or array of cells
 307       */
 308      public static function INDEX($matrix, $rowNum = 0, $columnNum = 0)
 309      {
 310          return Matrix::index($matrix, $rowNum, $columnNum);
 311      }
 312  
 313      /**
 314       * TRANSPOSE.
 315       *
 316       * @Deprecated 1.18.0
 317       *
 318       * @see LookupRef\Matrix::transpose()
 319       *      Use the transpose() method in the LookupRef\Matrix class instead
 320       *
 321       * @param array $matrixData A matrix of values
 322       *
 323       * @return array
 324       *
 325       * Unlike the Excel TRANSPOSE function, which will only work on a single row or column,
 326       *     this function will transpose a full matrix
 327       */
 328      public static function TRANSPOSE($matrixData)
 329      {
 330          return Matrix::transpose($matrixData);
 331      }
 332  
 333      /**
 334       * VLOOKUP
 335       * The VLOOKUP function searches for value in the left-most column of lookup_array and returns the value
 336       *     in the same row based on the index_number.
 337       *
 338       * @Deprecated 1.18.0
 339       *
 340       * @see LookupRef\VLookup::lookup()
 341       *      Use the lookup() method in the LookupRef\VLookup class instead
 342       *
 343       * @param mixed $lookup_value The value that you want to match in lookup_array
 344       * @param mixed $lookup_array The range of cells being searched
 345       * @param mixed $index_number The column number in table_array from which the matching value must be returned.
 346       *                                The first column is 1.
 347       * @param mixed $not_exact_match determines if you are looking for an exact match based on lookup_value
 348       *
 349       * @return mixed The value of the found cell
 350       */
 351      public static function VLOOKUP($lookup_value, $lookup_array, $index_number, $not_exact_match = true)
 352      {
 353          return VLookup::lookup($lookup_value, $lookup_array, $index_number, $not_exact_match);
 354      }
 355  
 356      /**
 357       * HLOOKUP
 358       * The HLOOKUP function searches for value in the top-most row of lookup_array and returns the value
 359       *     in the same column based on the index_number.
 360       *
 361       * @Deprecated 1.18.0
 362       *
 363       * @see LookupRef\HLookup::lookup()
 364       *      Use the lookup() method in the LookupRef\HLookup class instead
 365       *
 366       * @param mixed $lookup_value The value that you want to match in lookup_array
 367       * @param mixed $lookup_array The range of cells being searched
 368       * @param mixed $index_number The row number in table_array from which the matching value must be returned.
 369       *                                The first row is 1.
 370       * @param mixed $not_exact_match determines if you are looking for an exact match based on lookup_value
 371       *
 372       * @return mixed The value of the found cell
 373       */
 374      public static function HLOOKUP($lookup_value, $lookup_array, $index_number, $not_exact_match = true)
 375      {
 376          return HLookup::lookup($lookup_value, $lookup_array, $index_number, $not_exact_match);
 377      }
 378  
 379      /**
 380       * LOOKUP
 381       * The LOOKUP function searches for value either from a one-row or one-column range or from an array.
 382       *
 383       * @Deprecated 1.18.0
 384       *
 385       * @see LookupRef\Lookup::lookup()
 386       *      Use the lookup() method in the LookupRef\Lookup class instead
 387       *
 388       * @param mixed $lookup_value The value that you want to match in lookup_array
 389       * @param mixed $lookup_vector The range of cells being searched
 390       * @param null|mixed $result_vector The column from which the matching value must be returned
 391       *
 392       * @return mixed The value of the found cell
 393       */
 394      public static function LOOKUP($lookup_value, $lookup_vector, $result_vector = null)
 395      {
 396          return Lookup::lookup($lookup_value, $lookup_vector, $result_vector);
 397      }
 398  
 399      /**
 400       * FORMULATEXT.
 401       *
 402       * @Deprecated 1.18.0
 403       *
 404       * @param mixed $cellReference The cell to check
 405       * @param Cell $cell The current cell (containing this formula)
 406       *
 407       * @return string
 408       *
 409       *@see LookupRef\Formula::text()
 410       *      Use the text() method in the LookupRef\Formula class instead
 411       */
 412      public static function FORMULATEXT($cellReference = '', ?Cell $cell = null)
 413      {
 414          return LookupRef\Formula::text($cellReference, $cell);
 415      }
 416  }