make xlookup function like excel
This commit is contained in:
@@ -84,7 +84,7 @@ These commands operate on selections.
|
||||
| - | - | - | - |
|
||||
| `avg` | ≥ 1 | Numeric | Returns the average of the arguments |
|
||||
| `sum` | ≥ 1 | Numbers | Returns the sum of the arguments |
|
||||
| `xlookup` | 3 | Range, Number/String, Range | Searches for the number/string in the first range, returning the item at the same index in the second range |
|
||||
| `xlookup` | 3 | Number/String, Range, Range | Searches for the number/string in the first range, returning the item at the same index in the second range |
|
||||
| `min` | ≥ 1 | Numeric | Returns the minimum of the arguments |
|
||||
| `max` | ≥ 1 | Numeric | Returns the maximum of the arguments |
|
||||
| `len` | 1 | String/Tuple | Returns the character length of a string, or the amount of elements in a tuple (not recursively) |
|
||||
|
||||
@@ -788,7 +788,7 @@ fn xlookup_function() {
|
||||
grid.set_cell("A1", "Sarah".to_string());
|
||||
grid.set_cell("C0", 31.);
|
||||
grid.set_cell("C1", 41.);
|
||||
grid.set_cell("B0", "=xlookup(A:A,\"Bobby\",C:C)".to_string());
|
||||
grid.set_cell("B0", "=xlookup(\"Bobby\",A:A,C:C)".to_string());
|
||||
let cell = grid.get_cell("B0").as_ref().expect("Just set the cell");
|
||||
let res = grid.evaluate(&cell.to_string());
|
||||
assert!(res.is_ok());
|
||||
|
||||
@@ -104,13 +104,13 @@ impl<'a> CallbackContext<'a> {
|
||||
functions.insert(
|
||||
"xlookup".to_string(),
|
||||
Function::new(|arg| {
|
||||
let expected = vec![ValueType::Tuple, ValueType::String, ValueType::Tuple];
|
||||
let expected = vec![ValueType::String, ValueType::Tuple, ValueType::Tuple];
|
||||
if arg.is_tuple() {
|
||||
let args = arg.as_tuple()?;
|
||||
|
||||
if args.len() == 3 {
|
||||
let lookup_array = &args[0];
|
||||
let lookup_value = &args[1];
|
||||
let lookup_value = &args[0];
|
||||
let lookup_array = &args[1];
|
||||
let return_array = &args[2];
|
||||
|
||||
if lookup_array.is_tuple() && return_array.is_tuple() {
|
||||
|
||||
Reference in New Issue
Block a user