Commit 6963c2b0 authored by Jukka-Pekka Iivonen's avatar Jukka-Pekka Iivonen Committed by jpekka

Added ADDRESS(). Cleaned up too long lines.

1999-05-31  Jukka-Pekka Iivonen  <iivonen@iki.fi>

	* src/fn-lookup.c: Added ADDRESS().  Cleaned up too long lines.
parent 04e080b4
......@@ -2,9 +2,9 @@ Changes between version 0.26 and 0.27
Jukka has added the following functions:
* CHITEST(), BETAINV(), PERCENTRANK(), SERIESSUM(), SUMA(),
* SUBTOTAL(), SLOPE(), AVERAGEA(), MAXA(), MINA(), STDEVA(),
* STDEVPA(), VARA(), and VARPA().
* ADDRESS(), CHITEST(), BETAINV(), PERCENTRANK(), SERIESSUM(),
* SUMA(), SUBTOTAL(), SLOPE(), AVERAGEA(), MAXA(), MINA(),
* STDEVA(), STDEVPA(), VARA(), and VARPA().
And fixed these:
* BETADIST(), NORMDIST(), and POISSON().
......
1999-05-31 Jukka-Pekka Iivonen <iivonen@iki.fi>
* src/fn-lookup.c: Added ADDRESS(). Cleaned up too long lines.
1999-05-28 Morten Welinder <terra@diku.dk>
* src/file.c (workbook_read): Temporarily switch to "C" locale
......
1999-05-31 Jukka-Pekka Iivonen <iivonen@iki.fi>
* src/fn-lookup.c: Added ADDRESS(). Cleaned up too long lines.
1999-05-28 Morten Welinder <terra@diku.dk>
* src/file.c (workbook_read): Temporarily switch to "C" locale
......
1999-05-31 Jukka-Pekka Iivonen <iivonen@iki.fi>
* src/fn-lookup.c: Added ADDRESS(). Cleaned up too long lines.
1999-05-28 Morten Welinder <terra@diku.dk>
* src/file.c (workbook_read): Temporarily switch to "C" locale
......
1999-05-31 Jukka-Pekka Iivonen <iivonen@iki.fi>
* src/fn-lookup.c: Added ADDRESS(). Cleaned up too long lines.
1999-05-28 Morten Welinder <terra@diku.dk>
* src/file.c (workbook_read): Temporarily switch to "C" locale
......
/*
* fn-lookup.c: Built in lookup functions and functions registration
*
* Author:
* Authors:
* Michael Meeks <michael@imaginator.com>
* Jukka-Pekka Iivonen <iivonen@iki.fi>
*/
#include <config.h>
......@@ -14,6 +15,123 @@
#include "utils.h"
#include "func.h"
static char *help_address = {
N_("@FUNCTION=ADDRESS\n"
"@SYNTAX=ADDRESS(row_num,col_num[,abs_num,a1,text])\n"
"@DESCRIPTION="
"ADDRESS returns a cell address as text for specified row "
"and column numbers. "
"\n"
"If abs_num is 1 or omitted, ADDRESS returns absolute reference. "
"If abs_num is 2 ADDRESS returns absolute row and relative column. "
"If abs_num is 3 ADDRESS returns relative row and absolute column. "
"If abs_num is 4 ADDRESS returns relative reference. "
"If abs_num is greater than 4 ADDRESS returns #NUM! error. "
"\n"
"@a1 is a logical value that specifies the reference style. If "
"@a1 is TRUE or omitted, ADDRESS returns an A1-style reference, "
"i.e. $D$4. Otherwise ADDRESS returns an R1C1-style reference, "
"i.e. R4C4. "
"\n"
"@text specifies the name of the worksheet to be used as the "
"external reference. "
"\n"
"If @row_num or @col_num is less than one, ADDRESS returns #NUM! "
"error. "
"@SEEALSO=")
};
static Value *
gnumeric_address (struct FunctionDefinition *i,
Value *argv [], char **error_string)
{
int row, col, abs_num, a1, err;
gchar *text, *buf;
Value *v;
row = value_get_as_int (argv[0]);
col = value_get_as_int (argv[1]);
if (row < 1 || col < 1) {
*error_string = _("#NUM!");
return NULL;
}
if (argv[2] == NULL)
abs_num = 1;
else
abs_num = value_get_as_int (argv [2]);
if (argv[3] == NULL)
a1 = 1;
else {
a1 = value_get_as_bool (argv[3], &err);
if (err) {
*error_string = _("#VALUE!");
return NULL;
}
}
if (argv[4] == NULL) {
text = g_new(gchar, 1);
text[0] = '\0';
} else {
gchar *p = argv[4]->v.str->str;
int n=0, space=0;
text = g_new(gchar, strlen(p) + 3);
while (*p)
if (*p++ == ' ')
space = 1;
if (space)
sprintf(text, "'%s'", argv[4]->v.str->str);
else
strcpy(text, argv[4]->v.str->str);
strcat(text, "!");
}
buf = g_new(gchar, strlen(text) + 50);
switch (abs_num) {
case 1:
if (a1)
sprintf(buf, "%s$%s$%d", text, col_name(col-1), row);
else
sprintf(buf, "%sR%dC%d", text, row, col);
break;
case 2:
if (a1)
sprintf(buf, "%s%s$%d", text, col_name(col-1), row);
else
sprintf(buf, "%sR%dC[%d]", text, row, col);
break;
case 3:
if (a1)
sprintf(buf, "%s$%s%d", text, col_name(col-1), row);
else
sprintf(buf, "%sR[%d]C%d", text, row, col);
break;
case 4:
if (a1)
sprintf(buf, "%s%s%d", text, col_name(col-1), row);
else
sprintf(buf, "%sR[%d]C[%d]", text, row, col);
break;
default:
g_free(text);
g_free(buf);
*error_string = _("#NUM!");
return NULL;
}
v = value_new_string (buf);
g_free(text);
g_free(buf);
return v;
}
static char *help_choose = {
N_("@FUNCTION=CHOOSE\n"
"@SYNTAX=CHOOSE(index[,value1][,value2]...)\n"
......@@ -28,7 +146,8 @@ static char *help_choose = {
};
static Value *
gnumeric_choose (Sheet *sheet, GList *expr_node_list, int eval_col, int eval_row, char **error_string)
gnumeric_choose (Sheet *sheet, GList *expr_node_list,
int eval_col, int eval_row, char **error_string)
{
int index;
int argc;
......@@ -59,7 +178,8 @@ gnumeric_choose (Sheet *sheet, GList *expr_node_list, int eval_col, int eval_row
while (l){
index--;
if (!index)
return eval_expr (sheet, l->data, eval_col, eval_row, error_string);
return eval_expr (sheet, l->data, eval_col,
eval_row, error_string);
l = g_list_next (l);
}
*error_string = _("#VALUE!");
......@@ -71,11 +191,13 @@ static char *help_vlookup = {
"@SYNTAX=VLOOKUP(value,range,column,[approximate])\n"
"@DESCRIPTION="
"The VLOOKUP function finds the row in range that has a first column similar to value. "
"if approximate is not true it finds the row with an exact equivilance. "
"if approximate is true, then the values must be sorted in order of ascending value for "
"correct function; in this case it finds the row with value less than value. "
"it returns the value in the row found at a 1 based offset in column columns into the range."
"The VLOOKUP function finds the row in range that has a first "
"column similar to value. If approximate is not true it finds "
"the row with an exact equivilance. If approximate is true, "
"then the values must be sorted in order of ascending value for "
"correct function; in this case it finds the row with value less "
"than value. it returns the value in the row found at a 1 based "
"offset in column columns into the range."
"\n"
"Returns #NUM! if column < 0."
"Returns #REF! if column falls outside range."
......@@ -84,7 +206,8 @@ static char *help_vlookup = {
};
static int
lookup_similar (const Value *data, const Value *templ, const Value *next_largest, int approx)
lookup_similar (const Value *data, const Value *templ,
const Value *next_largest, int approx)
{
int ans;
......@@ -124,7 +247,8 @@ lookup_similar (const Value *data, const Value *templ, const Value *next_largest
ans = strcasecmp (a,b);
if (approx && ans < 0){
if (next_largest){
char *c = value_get_as_string (next_largest);
char *c = value_get_as_string
(next_largest);
int cmp = strcasecmp (a,c);
g_free (c);
if (cmp >= 0) {
......@@ -151,7 +275,8 @@ lookup_similar (const Value *data, const Value *templ, const Value *next_largest
}
static Value *
gnumeric_vlookup (struct FunctionDefinition *i, Value *argv [], char **error_string)
gnumeric_vlookup (struct FunctionDefinition *i,
Value *argv [], char **error_string)
{
const Value *next_largest = NULL;
int height, lp, approx, col_idx, next_largest_row = 0;
......@@ -206,7 +331,8 @@ gnumeric_vlookup (struct FunctionDefinition *i, Value *argv [], char **error_str
if (approx && next_largest){
const Value *v;
v = value_area_get_at_x_y (argv [1], col_idx-1, next_largest_row);
v = value_area_get_at_x_y (argv [1], col_idx-1,
next_largest_row);
g_return_val_if_fail (v != NULL, NULL);
return value_duplicate (v);
}
......@@ -221,11 +347,13 @@ static char *help_hlookup = {
"@SYNTAX=HLOOKUP(value,range,row,[approximate])\n"
"@DESCRIPTION="
"The HLOOKUP function finds the col in range that has a first row cell similar to value. "
"if approximate is not true it finds the col with an exact equivilance. "
"if approximate is true, then the values must be sorted in order of ascending value for "
"correct function; in this case it finds the col with value less than value. "
"it returns the value in the col found at a 1 based offset in row rows into the range."
"The HLOOKUP function finds the col in range that has a first "
"row cell similar to value. If approximate is not true it finds "
"the col with an exact equivilance. If approximate is true, "
"then the values must be sorted in order of ascending value for "
"correct function; in this case it finds the col with value less "
"than value it returns the value in the col found at a 1 based "
"offset in row rows into the range."
"\n"
"Returns #NUM! if row < 0."
"Returns #REF! if row falls outside range."
......@@ -234,7 +362,8 @@ static char *help_hlookup = {
};
static Value *
gnumeric_hlookup (struct FunctionDefinition *i, Value *argv [], char **error_string)
gnumeric_hlookup (struct FunctionDefinition *i,
Value *argv [], char **error_string)
{
const Value *next_largest = NULL;
int height, lp, approx, row_idx, next_largest_col = 0;
......@@ -289,7 +418,8 @@ gnumeric_hlookup (struct FunctionDefinition *i, Value *argv [], char **error_str
if (approx && next_largest){
const Value *v;
v = value_area_get_at_x_y (argv [1], next_largest_col, row_idx-1);
v = value_area_get_at_x_y (argv [1],
next_largest_col, row_idx-1);
g_return_val_if_fail (v != NULL, NULL);
return value_duplicate (v);
......@@ -305,13 +435,14 @@ static char *help_lookup = {
"@SYNTAX=LOOKUP(value,vector1,vector2)\n"
"@DESCRIPTION="
"The LOOKUP function finds the row index of 'value' in vector1 and returns "
"the contents of value2 at that row index."
"If the area is longer than it is wide then the sense of the search is rotated. "
"Alternatively a single array can be used."
"The LOOKUP function finds the row index of 'value' in vector1 "
"and returns the contents of value2 at that row index. "
"If the area is longer than it is wide then the sense of the "
"search is rotated. Alternatively a single array can be used."
"\n"
"If LOOKUP can't find value it uses the next largest value less than value."
"The data must be sorted"
"If LOOKUP can't find value it uses the next largest value less "
"than value. "
"The data must be sorted. "
"\n"
"If value is smaller than the first value it returns #N/A"
"\n"
......@@ -320,7 +451,8 @@ static char *help_lookup = {
/* Not very efficient ! */
static Value *
gnumeric_lookup (struct FunctionDefinition *i, Value *argv [], char **error_string)
gnumeric_lookup (struct FunctionDefinition *i,
Value *argv [], char **error_string)
{
int height, width;
const Value *next_largest = NULL;
......@@ -390,7 +522,8 @@ gnumeric_lookup (struct FunctionDefinition *i, Value *argv [], char **error_stri
*error_string = _("#N/A");
return NULL;
}
return value_duplicate (value_area_get_at_x_y (dest, next_largest_x+x_offset,
return value_duplicate (value_area_get_at_x_y (dest,
next_largest_x+x_offset,
next_largest_y+y_offset));
}
}
......@@ -402,24 +535,27 @@ static char *help_column = {
"@SYNTAX=COLUMN([reference])\n"
"@DESCRIPTION="
"The COLUMN function returns an array of the column numbers taking a default argument "
"of the containing cell position."
"The COLUMN function returns an array of the column numbers "
"taking a default argument of the containing cell position."
"\n"
"If reference is neither an array nor a reference nor a range returns #VALUE!."
"If reference is neither an array nor a reference nor a range "
"returns #VALUE!."
"\n"
"@SEEALSO=COLUMNS,ROW,ROWS")
};
/* FIXME: Needs Array support to be enven slightly meaningful */
static Value *
gnumeric_column (Sheet *sheet, GList *expr_node_list, int eval_col, int eval_row, char **error_string)
gnumeric_column (Sheet *sheet, GList *expr_node_list,
int eval_col, int eval_row, char **error_string)
{
Value *v;
if (!expr_node_list || !expr_node_list->data)
return value_new_int (eval_col+1);
v = eval_expr (sheet, expr_node_list->data, eval_col, eval_row, error_string);
v = eval_expr (sheet, expr_node_list->data,
eval_col, eval_row, error_string);
if (!v)
return NULL;
......@@ -444,16 +580,19 @@ static char *help_columns = {
"@SYNTAX=COLUMNS(reference)\n"
"@DESCRIPTION="
"The COLUMNS function returns the number of columns in area or array reference."
"The COLUMNS function returns the number of columns in area or "
"array reference."
"\n"
"If reference is neither an array nor a reference nor a range returns #VALUE!."
"If reference is neither an array nor a reference nor a range "
"returns #VALUE!."
"\n"
"@SEEALSO=COLUMN,ROW,ROWS")
};
/* FIXME: Needs Array support to be enven slightly meaningful */
static Value *
gnumeric_columns (struct FunctionDefinition *i, Value *argv [], char **error_string)
gnumeric_columns (struct FunctionDefinition *i,
Value *argv [], char **error_string)
{
return value_new_int (value_area_get_width (argv [0]));
}
......@@ -473,7 +612,8 @@ static char *help_offset = {
};
static Value *
gnumeric_offset (struct FunctionDefinition *i, Value *argv [], char **error_string)
gnumeric_offset (struct FunctionDefinition *i,
Value *argv [], char **error_string)
{
CellRef a;
CellRef b;
......@@ -509,24 +649,27 @@ static char *help_row = {
"@SYNTAX=ROW([reference])\n"
"@DESCRIPTION="
"The ROW function returns an array of the row numbers taking a default argument "
"of the containing cell position."
"The ROW function returns an array of the row numbers taking "
"a default argument of the containing cell position."
"\n"
"If reference is neither an array nor a reference nor a range returns #VALUE!."
"If reference is neither an array nor a reference nor a range "
"returns #VALUE!."
"\n"
"@SEEALSO=COLUMN,COLUMNS,ROWS")
};
/* FIXME: Needs Array support to be enven slightly meaningful */
static Value *
gnumeric_row (Sheet *sheet, GList *expr_node_list, int eval_col, int eval_row, char **error_string)
gnumeric_row (Sheet *sheet, GList *expr_node_list,
int eval_col, int eval_row, char **error_string)
{
Value *v;
if (!expr_node_list || !expr_node_list->data)
return value_new_int (eval_row+1);
v = eval_expr (sheet, expr_node_list->data, eval_col, eval_row, error_string);
v = eval_expr (sheet, expr_node_list->data,
eval_col, eval_row, error_string);
if (!v)
return NULL;
......@@ -552,29 +695,43 @@ static char *help_rows = {
"@SYNTAX=ROWS(reference)\n"
"@DESCRIPTION="
"The ROWS function returns the number of rows in area or array reference."
"The ROWS function returns the number of rows in area or array "
"reference."
"\n"
"If reference is neither an array nor a reference nor a range returns #VALUE!."
"If reference is neither an array nor a reference nor a range "
"returns #VALUE!."
"\n"
"@SEEALSO=COLUMN,ROW,ROWS")
};
/* FIXME: Needs Array support to be enven slightly meaningful */
static Value *
gnumeric_rows (struct FunctionDefinition *i, Value *argv [], char **error_string)
gnumeric_rows (struct FunctionDefinition *i,
Value *argv [], char **error_string)
{
return value_new_int (value_area_get_height (argv [0]));
}
FunctionDefinition lookup_functions [] = {
{ "choose", 0, "index,value...", &help_choose, gnumeric_choose, NULL },
{ "column", "?", "ref", &help_column, gnumeric_column, NULL },
{ "columns", "A", "ref", &help_columns, NULL, gnumeric_columns },
{ "hlookup", "?Af|b","val,range,col_idx,approx", &help_hlookup, NULL, gnumeric_hlookup },
{ "lookup", "?A|r", "val,range,range", &help_lookup, NULL, gnumeric_lookup },
{ "offset", "rffff","ref,row,col,hight,width", &help_offset, NULL, gnumeric_offset },
{ "row", "?", "ref", &help_row, gnumeric_row, NULL },
{ "rows", "A", "ref", &help_rows, NULL, gnumeric_rows },
{ "vlookup", "?Af|b","val,range,col_idx,approx", &help_vlookup, NULL, gnumeric_vlookup },
{ "address", "ff|ffs", "row_num,col_num,abs_num,a1,text",
&help_address, NULL, gnumeric_address },
{ "choose", 0, "index,value...",
&help_choose, gnumeric_choose, NULL },
{ "column", "?", "ref",
&help_column, gnumeric_column, NULL },
{ "columns", "A", "ref",
&help_columns, NULL, gnumeric_columns },
{ "hlookup", "?Af|b","val,range,col_idx,approx",
&help_hlookup, NULL, gnumeric_hlookup },
{ "lookup", "?A|r", "val,range,range",
&help_lookup, NULL, gnumeric_lookup },
{ "offset", "rffff","ref,row,col,hight,width",
&help_offset, NULL, gnumeric_offset },
{ "row", "?", "ref",
&help_row, gnumeric_row, NULL },
{ "rows", "A", "ref",
&help_rows, NULL, gnumeric_rows },
{ "vlookup", "?Af|b","val,range,col_idx,approx",
&help_vlookup, NULL, gnumeric_vlookup },
{ NULL, NULL }
};
/*
* fn-lookup.c: Built in lookup functions and functions registration
*
* Author:
* Authors:
* Michael Meeks <michael@imaginator.com>
* Jukka-Pekka Iivonen <iivonen@iki.fi>
*/
#include <config.h>
......@@ -14,6 +15,123 @@
#include "utils.h"
#include "func.h"
static char *help_address = {
N_("@FUNCTION=ADDRESS\n"
"@SYNTAX=ADDRESS(row_num,col_num[,abs_num,a1,text])\n"
"@DESCRIPTION="
"ADDRESS returns a cell address as text for specified row "
"and column numbers. "
"\n"
"If abs_num is 1 or omitted, ADDRESS returns absolute reference. "
"If abs_num is 2 ADDRESS returns absolute row and relative column. "
"If abs_num is 3 ADDRESS returns relative row and absolute column. "
"If abs_num is 4 ADDRESS returns relative reference. "
"If abs_num is greater than 4 ADDRESS returns #NUM! error. "
"\n"
"@a1 is a logical value that specifies the reference style. If "
"@a1 is TRUE or omitted, ADDRESS returns an A1-style reference, "
"i.e. $D$4. Otherwise ADDRESS returns an R1C1-style reference, "
"i.e. R4C4. "
"\n"
"@text specifies the name of the worksheet to be used as the "
"external reference. "
"\n"
"If @row_num or @col_num is less than one, ADDRESS returns #NUM! "
"error. "
"@SEEALSO=")
};
static Value *
gnumeric_address (struct FunctionDefinition *i,
Value *argv [], char **error_string)
{
int row, col, abs_num, a1, err;
gchar *text, *buf;
Value *v;
row = value_get_as_int (argv[0]);
col = value_get_as_int (argv[1]);
if (row < 1 || col < 1) {
*error_string = _("#NUM!");
return NULL;
}
if (argv[2] == NULL)
abs_num = 1;
else
abs_num = value_get_as_int (argv [2]);
if (argv[3] == NULL)
a1 = 1;
else {
a1 = value_get_as_bool (argv[3], &err);
if (err) {
*error_string = _("#VALUE!");
return NULL;
}
}
if (argv[4] == NULL) {
text = g_new(gchar, 1);
text[0] = '\0';
} else {
gchar *p = argv[4]->v.str->str;
int n=0, space=0;
text = g_new(gchar, strlen(p) + 3);
while (*p)
if (*p++ == ' ')
space = 1;
if (space)
sprintf(text, "'%s'", argv[4]->v.str->str);
else
strcpy(text, argv[4]->v.str->str);
strcat(text, "!");
}
buf = g_new(gchar, strlen(text) + 50);
switch (abs_num) {
case 1:
if (a1)
sprintf(buf, "%s$%s$%d", text, col_name(col-1), row);
else
sprintf(buf, "%sR%dC%d", text, row, col);
break;
case 2:
if (a1)
sprintf(buf, "%s%s$%d", text, col_name(col-1), row);
else
sprintf(buf, "%sR%dC[%d]", text, row, col);
break;
case 3:
if (a1)
sprintf(buf, "%s$%s%d", text, col_name(col-1), row);
else
sprintf(buf, "%sR[%d]C%d", text, row, col);
break;
case 4:
if (a1)
sprintf(buf, "%s%s%d", text, col_name(col-1), row);
else
sprintf(buf, "%sR[%d]C[%d]", text, row, col);
break;
default:
g_free(text);
g_free(buf);
*error_string = _("#NUM!");
return NULL;
}
v = value_new_string (buf);
g_free(text);
g_free(buf);
return v;
}
static char *help_choose = {
N_("@FUNCTION=CHOOSE\n"
"@SYNTAX=CHOOSE(index[,value1][,value2]...)\n"
......@@ -28,7 +146,8 @@ static char *help_choose = {
};
static Value *
gnumeric_choose (Sheet *sheet, GList *expr_node_list, int eval_col, int eval_row, char **error_string)
gnumeric_choose (Sheet *sheet, GList *expr_node_list,
int eval_col, int eval_row, char **error_string)
{
int index;
int argc;
......@@ -59,7 +178,8 @@ gnumeric_choose (Sheet *sheet, GList *expr_node_list, int eval_col, int eval_row
while (l){
index--;
if (!index)
return eval_expr (sheet, l->data, eval_col, eval_row, error_string);
return eval_expr (sheet, l->data, eval_col,
eval_row, error_string);
l = g_list_next (l);
}
*error_string = _("#VALUE!");
......@@ -71,11 +191,13 @@ static char *help_vlookup = {
"@SYNTAX=VLOOKUP(value,range,column,[approximate])\n"
"@DESCRIPTION="
"The VLOOKUP function finds the row in range that has a first column similar to value. "
"if approximate is not true it finds the row with an exact equivilance. "
"if approximate is true, then the values must be sorted in order of ascending value for "
"correct function; in this case it finds the row with value less than value. "
"it returns the value in the row found at a 1 based offset in column columns into the range."
"The VLOOKUP function finds the row in range that has a first "
"column similar to value. If approximate is not true it finds "
"the row with an exact equivilance. If approximate is true, "
"then the values must be sorted in order of ascending value for "
"correct function; in this case it finds the row with value less "
"than value. it returns the value in the row found at a 1 based "
"offset in column columns into the range."
"\n"
"Returns #NUM! if column < 0."
"Returns #REF! if column falls outside range."
......@@ -84,7 +206,8 @@ static char *help_vlookup = {
};
static int
lookup_similar (const Value *data, const Value *templ, const Value *next_largest, int approx)
lookup_similar (const Value *data, const Value *templ,
const Value *next_largest, int approx)
{
int ans;
......@@ -124,7 +247,8 @@ lookup_similar (const Value *data, const Value *templ, const Value *next_largest
ans = strcasecmp (a,b);
if (approx && ans < 0){
if (next_largest){
char *c = value_get_as_string (next_largest);
char *c = value_get_as_string
(next_largest);
int cmp = strcasecmp (a,c);
g_free (c);
if (cmp >= 0) {
......@@ -151,7 +275,8 @@ lookup_similar (const Value *data, const Value *templ, const Value *next_largest
}
static Value *
gnumeric_vlookup (struct FunctionDefinition *i, Value *argv [], char **error_string)
gnumeric_vlookup (struct FunctionDefinition *i,
Value *argv [], char **error_string)
{
const Value *next_largest = NULL;
int height, lp, approx, col_idx, next_largest_row = 0;
......@@ -206,7 +331,8 @@ gnumeric_vlookup (struct FunctionDefinition *i, Value *argv [], char **error_str
if (approx && next_largest){
const Value *v;
v = value_area_get_at_x_y (argv [1], col_idx-1, next_largest_row);
v = value_area_get_at_x_y (argv [1], col_idx-1,
next_largest_row);
g_return_val_if_fail (v != NULL, NULL);
return value_duplicate (v);
}
......@@ -221,11 +347,13 @@ static char *help_hlookup = {
"@SYNTAX=HLOOKUP(value,range,row,[approximate])\n"
"@DESCRIPTION="
"The HLOOKUP function finds the col in range that has a first row cell similar to value. "
"if approximate is not true it finds the col with an exact equivilance. "
"if approximate is true, then the values must be sorted in order of ascending value for "
"correct function; in this case it finds the col with value less than value. "
"it returns the value in the col found at a 1 based offset in row rows into the range."
"The HLOOKUP function finds the col in range that has a first "
"row cell similar to value. If approximate is not true it finds "
"the col with an exact equivilance. If approximate is true, "
"then the values must be sorted in order of ascending value for "
"correct function; in this case it finds the col with value less "
"than value it returns the value in the col found at a 1 based "
"offset in row rows into the range."
"\n"
"Returns #NUM! if row < 0."
"Returns #REF! if row falls outside range."
......@@ -234,7 +362,8 @@ static char *help_hlookup = {
};
static Value *
gnumeric_hlookup (struct FunctionDefinition *i, Value *argv [], char **error_string)
gnumeric_hlookup (struct FunctionDefinition *i,
Value *argv [], char **error_string)
{
const Value *next_largest = NULL;
int height, lp, approx, row_idx, next_largest_col = 0;
......@@ -289,7 +418,8 @@ gnumeric_hlookup (struct FunctionDefinition *i, Value *argv [], char **error_str
if (approx && next_largest){
const Value *v;
v = value_area_get_at_x_y (argv [1], next_largest_col, row_idx-1);
v = value_area_get_at_x_y (argv [1],
next_largest_col, row_idx-1);
g_return_val_if_fail (v != NULL, NULL);
return value_duplicate (v);
......@@ -305,13 +435,14 @@ static char *help_lookup = {
"@SYNTAX=LOOKUP(value,vector1,vector2)\n"
"@DESCRIPTION="
"The LOOKUP function finds the row index of 'value' in vector1 and returns "
"the contents of value2 at that row index."
"If the area is longer than it is wide then the sense of the search is rotated. "
"Alternatively a single array can be used."
"The LOOKUP function finds the row index of 'value' in vector1 "
"and returns the contents of value2 at that row index. "
"If the area is longer than it is wide then the sense of the "
"search is rotated. Alternatively a single array can be used."
"\n"
"If LOOKUP can't find value it uses the next largest value less than value."
"The data must be sorted"
"If LOOKUP can't find value it uses the next largest value less "