[gnumeric] ADDRESS: use the right sheet for size queries.



commit 96082b54c9e419e05b6b17d9e7009f64eeae4be9
Author: Morten Welinder <terra gnome org>
Date:   Thu May 12 21:04:01 2011 -0400

    ADDRESS: use the right sheet for size queries.

 NEWS                          |    1 +
 plugins/fn-lookup/ChangeLog   |    5 +++++
 plugins/fn-lookup/functions.c |   19 +++++++++++++++----
 3 files changed, 21 insertions(+), 4 deletions(-)
---
diff --git a/NEWS b/NEWS
index aec7b99..5a82bf4 100644
--- a/NEWS
+++ b/NEWS
@@ -26,6 +26,7 @@ Morten:
 	* Eliminate col/row infos that are identical to the default.  [#155003]
 	* Fix problems reading some Lotus 1-2-3 files.
 	* Fix paste-special repeat.
+	* Fix ADDRESS problem.
 
 Urmas:
 	* Initial support for Works files.  [#647492]
diff --git a/plugins/fn-lookup/ChangeLog b/plugins/fn-lookup/ChangeLog
index db9bbac..bafaa9e 100644
--- a/plugins/fn-lookup/ChangeLog
+++ b/plugins/fn-lookup/ChangeLog
@@ -1,3 +1,8 @@
+2011-05-12  Morten Welinder  <terra gnome org>
+
+	* functions.c (gnumeric_address): Get sheet size from the right
+	sheet.  Fixes #650003.
+
 2011-03-24  Morten Welinder <terra gnome org>
 
 	* Release 1.10.14
diff --git a/plugins/fn-lookup/functions.c b/plugins/fn-lookup/functions.c
index 1cec621..493e0b1 100644
--- a/plugins/fn-lookup/functions.c
+++ b/plugins/fn-lookup/functions.c
@@ -739,6 +739,9 @@ gnumeric_address (GnmFuncEvalInfo *ei, GnmValue const * const *args)
 	GnmParsePos	 pp;
 	gboolean	 err;
 	int		 col, row;
+	Sheet            *sheet;
+	const char       *sheet_name =
+		args[4] ? value_peek_string (args[4]) : NULL;
 
 	switch (args[2] ? value_get_as_int (args[2]) : 1) {
 	case 1: case 5: ref.col_relative = ref.row_relative = FALSE; break;
@@ -756,6 +759,14 @@ gnumeric_address (GnmFuncEvalInfo *ei, GnmValue const * const *args)
 		return value_new_error_VALUE (ei->pos);
 	}
 
+	if (sheet_name) {
+		sheet = workbook_sheet_by_name (ei->pos->sheet->workbook,
+						sheet_name);
+		if (!sheet)
+			return value_new_error_VALUE (ei->pos);
+	} else
+		sheet = ei->pos->sheet;
+
 	ref.sheet = NULL;
 	row = ref.row = value_get_as_int (args[0]) - 1;
 	col = ref.col = value_get_as_int (args[1]) - 1;
@@ -774,17 +785,17 @@ gnumeric_address (GnmFuncEvalInfo *ei, GnmValue const * const *args)
 		if (err)
 		        return value_new_error_VALUE (ei->pos);
 	}
-	if (col < 0 || col >= gnm_sheet_get_max_cols (ei->pos->sheet))
+	if (col < 0 || col >= gnm_sheet_get_max_cols (sheet))
 		return value_new_error_VALUE (ei->pos);
-	if (row < 0 || row >= gnm_sheet_get_max_rows (ei->pos->sheet))
+	if (row < 0 || row >= gnm_sheet_get_max_rows (sheet))
 		return value_new_error_VALUE (ei->pos);
 
 	if (!out.convs->r1c1_addresses)
 		pp.eval.col = pp.eval.row = 0;
 
-	if (NULL != args[4]) {
+	if (sheet_name) {
 		out.accum = gnm_expr_conv_quote (gnm_conventions_default,
-			value_peek_string (args[4]));
+						 sheet_name);
 		g_string_append_c (out.accum, '!');
 	} else
 		out.accum = g_string_new (NULL);



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]