[gnumeric] xlsx: improve handling of invalid formulae.



commit 346151e2466ab768ff4f101a035f58e3dcb6577d
Author: Morten Welinder <terra gnome org>
Date:   Sun Apr 11 16:30:12 2021 -0400

    xlsx: improve handling of invalid formulae.
    
    Instead of dropping them on the floor, preserve the contents in ERROR("...")

 NEWS                      | 1 +
 plugins/excel/ChangeLog   | 6 ++++++
 plugins/excel/xlsx-read.c | 9 ++++++++-
 3 files changed, 15 insertions(+), 1 deletion(-)
---
diff --git a/NEWS b/NEWS
index 1b62f56c0..78c00c0ad 100644
--- a/NEWS
+++ b/NEWS
@@ -6,6 +6,7 @@ Morten:
        * Use Python's bool type instead of rolling our own.
        * Export file:// links to html.  [#569]
        * Export file:// links to xlsx.  [#569]
+       * Improve handling of invalid formulae from xlsx.  [#574]
 
 --------------------------------------------------------------------------
 Gnumeric 1.12.49
diff --git a/plugins/excel/ChangeLog b/plugins/excel/ChangeLog
index 7a530edb8..a9a978600 100644
--- a/plugins/excel/ChangeLog
+++ b/plugins/excel/ChangeLog
@@ -1,3 +1,9 @@
+2021-04-11  Morten Welinder  <terra gnome org>
+
+       * xlsx-read.c (xlsx_parse_expr): Turn expressons we cannot parse
+       into ERROR("formula") instead of dropping them on the floor.  See
+       #574.
+
 2021-03-29  Morten Welinder  <terra gnome org>
 
        * xlsx-read.c (xlsx_CT_HyperLinks): Also handle file:// links.
diff --git a/plugins/excel/xlsx-read.c b/plugins/excel/xlsx-read.c
index 06c63f86b..6bb8eb52d 100644
--- a/plugins/excel/xlsx-read.c
+++ b/plugins/excel/xlsx-read.c
@@ -55,6 +55,7 @@
 #include <gnm-so-line.h>
 #include <sheet-object-image.h>
 #include <number-match.h>
+#include <func.h>
 #include "dead-kittens.h"
 
 #include <goffice/goffice.h>
@@ -1198,10 +1199,16 @@ xlsx_parse_expr (GsfXMLIn *xin, xmlChar const *expr_str,
        texpr = gnm_expr_parse_str (expr_str, pp,
                GNM_EXPR_PARSE_DEFAULT, state->convs,
                parse_error_init (&err));
-       if (NULL == texpr)
+       if (NULL == texpr) {
                xlsx_warning (xin, "At %s: '%s' %s",
                              parsepos_as_string (pp),
                              expr_str, err.err->message);
+               texpr = gnm_expr_top_new
+                       (gnm_expr_new_funcall1
+                        (gnm_func_lookup_or_add_placeholder ("ERROR"),
+                         gnm_expr_new_constant
+                         (value_new_string (expr_str))));
+       }
        parse_error_free (&err);
 
        return texpr;


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