[gnumeric] Add ODF compatibility function SHEET.



commit ed3f36e8eb6bf7da7d6488f0cc91eb6cf8ec8df3
Author: Andreas J. Guelzow <aguelzow pyrshep ca>
Date:   Sun Oct 25 12:33:25 2009 -0600

    Add ODF compatibility function SHEET.
    
    2009-10-25  Andreas J. Guelzow <aguelzow pyrshep ca>
    
    	* openoffice-read.c (oo_func_map_in): we now have SHEET
    	* openoffice-write.c (odf_expr_func_handler): ditto
    
    2009-10-25  Andreas J. Guelzow <aguelzow pyrshep ca>
    
    	* functions.c (help_sheet): new
    	(gnumeric_sheet): new
    	(lookup_functions): add SHEET
    	* plugin.xml.in: add SHEET

 NEWS                                  |    4 +-
 plugins/fn-lookup/ChangeLog           |    7 ++++
 plugins/fn-lookup/functions.c         |   54 +++++++++++++++++++++++++++++++++
 plugins/fn-lookup/plugin.xml.in       |    1 +
 plugins/openoffice/ChangeLog          |    5 +++
 plugins/openoffice/openoffice-read.c  |    1 -
 plugins/openoffice/openoffice-write.c |    2 +-
 7 files changed, 70 insertions(+), 4 deletions(-)
---
diff --git a/NEWS b/NEWS
index 08e9aae..427f592 100644
--- a/NEWS
+++ b/NEWS
@@ -5,8 +5,8 @@ Andreas:
 	* Add R.PSNORM, R.DSNORM and R.DST.
 	* Fix small sort dialog problem. [#599091]
 	* A few functions from the christian liturgical calendar.
-	* Add ODF compatibility functions DAYS, ISFORMULA, IFNA, SHEETS 
-	  and NUMBERVALUE.
+	* Add ODF compatibility functions DAYS, ISFORMULA, IFNA, SHEETS, 
+	  SHEET and NUMBERVALUE.
 	* Work around OpenOffice.org saving function names in lowercase.
 	* Add BINOM.DIST.RANGE (equivalent to the ODF function B).
 
diff --git a/plugins/fn-lookup/ChangeLog b/plugins/fn-lookup/ChangeLog
index 4a90c30..f69ed1b 100644
--- a/plugins/fn-lookup/ChangeLog
+++ b/plugins/fn-lookup/ChangeLog
@@ -1,3 +1,10 @@
+2009-10-25  Andreas J. Guelzow <aguelzow pyrshep ca>
+
+	* functions.c (help_sheet): new
+	(gnumeric_sheet): new
+	(stat_functions): add SHEET
+	* plugin.xml.in: add SHEET
+
 2009-10-24  Andreas J. Guelzow <aguelzow pyrshep ca>
 
 	* functions.c (help_sheets): new
diff --git a/plugins/fn-lookup/functions.c b/plugins/fn-lookup/functions.c
index e8ed35e..4b84b8e 100644
--- a/plugins/fn-lookup/functions.c
+++ b/plugins/fn-lookup/functions.c
@@ -1574,6 +1574,57 @@ gnumeric_sheets (GnmFuncEvalInfo *ei, GnmValue const * const *args)
 }
 
 /***************************************************************************/
+static GnmFuncHelp const help_sheet[] = {
+	{ GNM_FUNC_HELP_NAME, F_("SHEET:sheet number of @{reference}")},
+        { GNM_FUNC_HELP_ARG, F_("reference:reference or literal sheet name, defaults to the current sheet")},
+	{ GNM_FUNC_HELP_NOTE, F_("If @{reference} is neither a reference nor a literal sheet name, "
+				 "SHEETS returns #VALUE!")},
+        { GNM_FUNC_HELP_EXAMPLES, "=SHEET(Sheet2!H7)" },
+        { GNM_FUNC_HELP_EXAMPLES, "=SHEET(Sheet2!H7:Z8)" },
+        { GNM_FUNC_HELP_EXAMPLES, "=SHEET()" },
+        { GNM_FUNC_HELP_EXAMPLES, "=SHEET(\"Sheet1\")" },
+        { GNM_FUNC_HELP_SEEALSO, "SHEETS,ROW,COLUMNNUMBER"},
+        { GNM_FUNC_HELP_END}
+};
+
+static GnmValue *
+gnumeric_sheet (GnmFuncEvalInfo *ei, GnmValue const * const *args)
+{
+	Workbook const *wb = ei->pos->sheet->workbook;
+	GnmValue const *v = args[0];
+
+	if(v) {
+		if (v->type == VALUE_CELLRANGE) {
+			GnmRangeRef const *r = &v->v_range.cell;
+			int a, b;
+
+			a = g_slist_index (workbook_sheets (wb), r->a.sheet);
+			b = g_slist_index (workbook_sheets (wb), r->b.sheet);
+
+			if (a == -1 && b == -1)
+				return value_new_int (1 + g_slist_index 
+						      (workbook_sheets (wb), 
+						       ei->pos->sheet));
+			else if (a == b || (a * b) < 0)
+				return value_new_int (1 + ((a < b) ? b : a));
+			else
+				return value_new_error_NUM (ei->pos);
+		} else if (v->type == VALUE_STRING) {
+			Sheet *sheet = workbook_sheet_by_name 
+				(wb, value_peek_string (v));
+			if (sheet == NULL)
+				return value_new_error_NUM (ei->pos);
+			else
+				return value_new_int 
+					(1 + g_slist_index (workbook_sheets (wb), 
+							    sheet));
+		} else
+			return value_new_error_VALUE (ei->pos);	
+	} else
+		return value_new_int (1 + g_slist_index (workbook_sheets (wb), 
+							 ei->pos->sheet));
+}
+/***************************************************************************/
 
 static GnmFuncHelp const help_hyperlink[] = {
 	{ GNM_FUNC_HELP_NAME, F_("HYPERLINK:second or first arguments")},
@@ -1684,6 +1735,9 @@ GnmFuncDescriptor const lookup_functions[] = {
 	{ "sheets",      "|A",
 	  help_sheets,     gnumeric_sheets, NULL, NULL, NULL, NULL,
 	  GNM_FUNC_SIMPLE, GNM_FUNC_IMPL_STATUS_UNIQUE_TO_GNUMERIC, GNM_FUNC_TEST_STATUS_NO_TESTSUITE },
+	{ "sheet",      "|?",
+	  help_sheet,     gnumeric_sheet, NULL, NULL, NULL, NULL,
+	  GNM_FUNC_SIMPLE, GNM_FUNC_IMPL_STATUS_UNIQUE_TO_GNUMERIC, GNM_FUNC_TEST_STATUS_NO_TESTSUITE },
 	{ "transpose", "A",
 	  help_transpose, gnumeric_transpose, NULL, NULL, NULL, NULL,
 	  GNM_FUNC_RETURNS_NON_SCALAR, GNM_FUNC_IMPL_STATUS_COMPLETE, GNM_FUNC_TEST_STATUS_BASIC },
diff --git a/plugins/fn-lookup/plugin.xml.in b/plugins/fn-lookup/plugin.xml.in
index d210cb7..99e7b62 100644
--- a/plugins/fn-lookup/plugin.xml.in
+++ b/plugins/fn-lookup/plugin.xml.in
@@ -26,6 +26,7 @@
 				<function name="offset"/>
 				<function name="row"/>
 				<function name="rows"/>
+				<function name="sheet"/>
 				<function name="sheets"/>
 				<function name="transpose"/>
 				<function name="vlookup"/>
diff --git a/plugins/openoffice/ChangeLog b/plugins/openoffice/ChangeLog
index ca74979..6c146c4 100644
--- a/plugins/openoffice/ChangeLog
+++ b/plugins/openoffice/ChangeLog
@@ -1,3 +1,8 @@
+2009-10-25  Andreas J. Guelzow <aguelzow pyrshep ca>
+
+	* openoffice-read.c (oo_func_map_in): we now have SHEET
+	* openoffice-write.c (odf_expr_func_handler): ditto
+
 2009-10-24  Andreas J. Guelzow <aguelzow pyrshep ca>
 
 	* openoffice-read.c (oo_func_map_in): we now have SHEETS
diff --git a/plugins/openoffice/openoffice-read.c b/plugins/openoffice/openoffice-read.c
index 34338f5..ab38d7a 100644
--- a/plugins/openoffice/openoffice-read.c
+++ b/plugins/openoffice/openoffice-read.c
@@ -4659,7 +4659,6 @@ oo_func_map_in (GnmConventions const *convs, Workbook *scope,
 		{ "COUNTIFS","ODF.COUNTIFS" },
 		{ "DDE","ODF.DDE" },
 		{ "MULTIPLE.OPERATIONS","ODF.MULTIPLE.OPERATIONS" },
-		{ "SHEET","ODF.SHEET" },
 		{ "SUMIFS","ODF.SUMIFS" },
 
 /* The following is a complete list of the functions defined in ODF OpenFormula draft 20090508 */
diff --git a/plugins/openoffice/openoffice-write.c b/plugins/openoffice/openoffice-write.c
index 947d59e..5aa64c7 100644
--- a/plugins/openoffice/openoffice-write.c
+++ b/plugins/openoffice/openoffice-write.c
@@ -1896,7 +1896,7 @@ odf_expr_func_handler (GnmConventionsOut *out, GnmExprFunction const *func)
 		{ "SECH","SECH" },
 		{ "SECOND","SECOND" },
 		{ "SERIESSUM","SERIESSUM" },
-		/* { "SHEET","SHEET" }, not implemented  */
+		{ "SHEET","SHEET" }, 
 		{ "SHEETS","SHEETS" },  
 		{ "SIGN","SIGN" },
 		{ "SIN","SIN" },



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