[gnumeric] Improve xlsx import of new stat function names.



commit 78b18f3ae6de814db7241e0db5d1aec87ea7c61d
Author: Andreas J Guelzow <aguelzow pyrshep ca>
Date:   Fri Jun 21 00:06:22 2013 -0600

    Improve xlsx import of new stat function names.
    
    2013-06-21  Andreas J. Guelzow <aguelzow pyrshep ca>
    
        * xlsx-utils.c (xlsx_func_map_in): new
        (xlsx_conventions_new): connect the above

 NEWS                       |    1 +
 plugins/excel/ChangeLog    |    5 +++
 plugins/excel/xlsx-utils.c |   69 ++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 75 insertions(+), 0 deletions(-)
---
diff --git a/NEWS b/NEWS
index 7623f50..513ddf0 100644
--- a/NEWS
+++ b/NEWS
@@ -30,6 +30,7 @@ Andreas:
        * Fix crash on xlsx import due to external references. [#702407]
        * Fix reading of conditional formats from xls files. [#702612]
        * Fix reading of solid fill conditional formats from xlsx files. [#702615]
+       * Improve xlsx import of new stat function names.
 
 Darrell Tangman:
        * Update documentation for Edit and Insert menus. [#700596]
diff --git a/plugins/excel/ChangeLog b/plugins/excel/ChangeLog
index 2d12a76..b5ebfa2 100644
--- a/plugins/excel/ChangeLog
+++ b/plugins/excel/ChangeLog
@@ -1,3 +1,8 @@
+2013-06-21  Andreas J. Guelzow <aguelzow pyrshep ca>
+
+       * xlsx-utils.c (xlsx_func_map_in): new
+       (xlsx_conventions_new): connect the above
+
 2013-06-20  Andreas J. Guelzow <aguelzow pyrshep ca>
 
        * ms-formula-read.c (xl2010_synonyms): add more functions
diff --git a/plugins/excel/xlsx-utils.c b/plugins/excel/xlsx-utils.c
index 03c4a25..d4882a5 100644
--- a/plugins/excel/xlsx-utils.c
+++ b/plugins/excel/xlsx-utils.c
@@ -36,6 +36,7 @@
 #include <goffice/goffice.h>
 #include <glib-object.h>
 #include <string.h>
+#include <expr.h>
 
 typedef struct {
        GnmConventions base;
@@ -121,6 +122,73 @@ xlsx_conventions_add_extern_ref (GnmConventions *convs, char const *path)
        return res;
 }
 
+static GnmExpr const *
+xlsx_func_map_in (G_GNUC_UNUSED GnmConventions const *convs, 
+                 G_GNUC_UNUSED Workbook *scope,
+                 char const *name, GnmExprList *args)
+{
+       static struct {
+               char const *xlsx_name;
+               char const *gnm_name;
+       } const xlfn_func_renames[] = {
+               { "beta.inv", "betainv" },
+               { "binom.dist", "binomdist" },
+               { "chisq.dist.rt", "chidist" },
+               { "chisq.inv.rt", "chiinv" },
+               { "chisq.test", "chitest" },
+               { "confidence.norm", "confidence" },
+               { "covariance.p", "covar" },
+               { "expon.dist", "expondist" },
+               { "f.dist.rt", "fdist" },
+               { "f.inv.rt", "finv" },
+               { "f.test", "ftest" },
+               { "gamma.dist", "gammadist" },
+               { "gamma.inv", "gammainv" },
+               { "mode.sngl", "mode" },
+               { "percentile.inc", "percentile" },
+               { "percentrank.inc", "percentrank" },
+               { "quartile.inc", "quartile" },
+               { "rank.eq", "rank" },
+               { "stdev.p", "stdevp" },
+               { "stdev.s", "stdev" },
+               { "t.test", "ttest" },
+               { "var.p", "varp" },
+               { "var.s", "var" },
+               { "z.test", "ztest" },
+               { NULL, NULL }
+       };
+
+       static GHashTable *xlfn_map = NULL;
+
+       GnmFunc  *f;
+       char const *new_name;
+       int i;
+
+       if (NULL == xlfn_map) {
+               xlfn_map = g_hash_table_new (go_ascii_strcase_hash,
+                                            go_ascii_strcase_equal);
+               for (i = 0; xlfn_func_renames[i].xlsx_name; i++)
+                       g_hash_table_insert (xlfn_map,
+                               (gchar *) xlfn_func_renames[i].xlsx_name,
+                               (gchar *) xlfn_func_renames[i].gnm_name);
+       }
+       
+       if (0 == g_ascii_strncasecmp (name, "_xlfn.", 6)) {
+               if (NULL != xlfn_map &&
+                   NULL != (new_name = g_hash_table_lookup (xlfn_map, name + 6)))
+                       name = new_name;
+               else
+                       name = name + 6;
+       } else if (0 == g_ascii_strncasecmp (name, "_xlfnodf.", 9))
+               /* This should at most happen for ODF functions incorporated */
+               /* in an xlsx file, we should perform the appropriate translation! */
+               name = name + 9;
+
+       f = gnm_func_lookup_or_add_placeholder (name);
+
+       return gnm_expr_new_funcall (f, args);  
+}
+
 GnmConventions *
 xlsx_conventions_new (void)
 {
@@ -131,6 +199,7 @@ xlsx_conventions_new (void)
        convs->decimal_sep_dot          = TRUE;
        convs->input.range_ref          = rangeref_parse;
        convs->input.external_wb        = xlsx_lookup_external_wb;
+       convs->input.func               = xlsx_func_map_in;
        convs->output.cell_ref          = xlsx_cellref_as_string;
        convs->output.range_ref         = xlsx_rangeref_as_string;
        convs->range_sep_colon          = TRUE;


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