LookupRef.php 16 KB

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