[gnumeric] xlsx: fix conditions formatting export/import for "starts with" and friends



commit 72249987ef156fd86ee905f84eb3a206cc4056cb
Author: Morten Welinder <terra gnome org>
Date:   Fri Mar 21 11:04:04 2014 -0400

    xlsx: fix conditions formatting export/import for "starts with" and friends
    
    The full formula is written, not just what we search for.

 plugins/excel/ChangeLog    |    6 ++++++
 plugins/excel/xlsx-read.c  |   37 +++++++++++++++++++------------------
 plugins/excel/xlsx-write.c |   26 ++++++++++++++++++++------
 3 files changed, 45 insertions(+), 24 deletions(-)
---
diff --git a/plugins/excel/ChangeLog b/plugins/excel/ChangeLog
index 8a1c5b1..e3e8622 100644
--- a/plugins/excel/ChangeLog
+++ b/plugins/excel/ChangeLog
@@ -1,5 +1,11 @@
 2014-03-21  Morten Welinder  <terra gnome org>
 
+       * xlsx-read.c (xlsx_cond_fmt_rule_begin): Match
+       xlsx_write_cond_rule changes.
+
+       * xlsx-write.c (xlsx_write_cond_rule): Write alternate formulas
+       even for "Starts with" and friends.
+
        * xlsx-read.c (xlsx_cond_fmt_formula_end): Don't throw critical if
        we fail to parse the expression.
 
diff --git a/plugins/excel/xlsx-read.c b/plugins/excel/xlsx-read.c
index e6cf57c..de2d440 100644
--- a/plugins/excel/xlsx-read.c
+++ b/plugins/excel/xlsx-read.c
@@ -2492,14 +2492,14 @@ typedef enum {
        XLSX_CF_TYPE_TOP10,
        XLSX_CF_TYPE_UNIQUE_VALUES,
        XLSX_CF_TYPE_DUPLICATE_VALUES,
-       XLSX_CF_TYPE_CONTAINS_STR               = GNM_STYLE_COND_CONTAINS_STR,
-       XLSX_CF_TYPE_NOT_CONTAINS_STR           = GNM_STYLE_COND_NOT_CONTAINS_STR,
-       XLSX_CF_TYPE_BEGINS_WITH                = GNM_STYLE_COND_BEGINS_WITH_STR,
-       XLSX_CF_TYPE_ENDS_WITH                  = GNM_STYLE_COND_ENDS_WITH_STR,
-       XLSX_CF_TYPE_CONTAINS_BLANKS            = GNM_STYLE_COND_CONTAINS_BLANKS,
-       XLSX_CF_TYPE_NOT_CONTAINS_BLANKS        = GNM_STYLE_COND_NOT_CONTAINS_BLANKS,
-       XLSX_CF_TYPE_CONTAINS_ERRORS            = GNM_STYLE_COND_CONTAINS_ERR,
-       XLSX_CF_TYPE_NOT_CONTAINS_ERRORS        = GNM_STYLE_COND_NOT_CONTAINS_ERR,
+       XLSX_CF_TYPE_CONTAINS_STR,
+       XLSX_CF_TYPE_NOT_CONTAINS_STR,
+       XLSX_CF_TYPE_BEGINS_WITH,
+       XLSX_CF_TYPE_ENDS_WITH,
+       XLSX_CF_TYPE_CONTAINS_BLANKS,
+       XLSX_CF_TYPE_NOT_CONTAINS_BLANKS,
+       XLSX_CF_TYPE_CONTAINS_ERRORS,
+       XLSX_CF_TYPE_NOT_CONTAINS_ERRORS,
        XLSX_CF_TYPE_COMPARE_COLUMNS,
        XLSX_CF_TYPE_TIME_PERIOD,
        XLSX_CF_TYPE_ABOVE_AVERAGE
@@ -2595,16 +2595,17 @@ xlsx_cond_fmt_rule_begin (GsfXMLIn *xin, xmlChar const **attrs)
        case XLSX_CF_TYPE_CELL_IS :
                /* Nothing */
                break;
-       case XLSX_CF_TYPE_CONTAINS_STR :
-       case XLSX_CF_TYPE_NOT_CONTAINS_STR :
-       case XLSX_CF_TYPE_BEGINS_WITH :
-       case XLSX_CF_TYPE_ENDS_WITH :
-       case XLSX_CF_TYPE_CONTAINS_BLANKS :
-       case XLSX_CF_TYPE_NOT_CONTAINS_BLANKS :
-       case XLSX_CF_TYPE_CONTAINS_ERRORS :
-       case XLSX_CF_TYPE_NOT_CONTAINS_ERRORS :
-               /* GnmStyleCondOp and XlsxCFTypes share these. */
-               op = (GnmStyleCondOp)type;
+       case XLSX_CF_TYPE_CONTAINS_STR:
+       case XLSX_CF_TYPE_NOT_CONTAINS_STR:
+       case XLSX_CF_TYPE_BEGINS_WITH:
+       case XLSX_CF_TYPE_ENDS_WITH:
+       case XLSX_CF_TYPE_CONTAINS_BLANKS:
+       case XLSX_CF_TYPE_NOT_CONTAINS_BLANKS:
+       case XLSX_CF_TYPE_CONTAINS_ERRORS:
+       case XLSX_CF_TYPE_NOT_CONTAINS_ERRORS:
+               /* The expressions stored for these are the full
+                  expressions, not just what we search for. */
+               op = GNM_STYLE_COND_CUSTOM;
                break;
 
        case XLSX_CF_TYPE_EXPRESSION:
diff --git a/plugins/excel/xlsx-write.c b/plugins/excel/xlsx-write.c
index e2e55a3..211b37d 100644
--- a/plugins/excel/xlsx-write.c
+++ b/plugins/excel/xlsx-write.c
@@ -1562,7 +1562,8 @@ xlsx_write_cond_rule (XLSXWriteState *state, GsfXMLOut *xml,
        int i, n;
        const char *type = NULL;
        const char *operator = NULL;
-       GnmExprTop const *alt_texpr = NULL;
+       GnmExprTop const *alt_texpr;
+       gboolean needs_alt_texpr = FALSE;
 
        gsf_xml_out_start_element (xml, "cfRule");
        switch (cond->op) {
@@ -1591,42 +1592,55 @@ xlsx_write_cond_rule (XLSXWriteState *state, GsfXMLOut *xml,
                n = 1; operator = "lessThanOrEqual";
                break;
        case GNM_STYLE_COND_CONTAINS_BLANKS:
-               n = 0; type = "containsBlanks";
+               needs_alt_texpr = TRUE;
+               n = 1; type = "containsBlanks";
                break;
        case GNM_STYLE_COND_NOT_CONTAINS_BLANKS:
-               n = 0; type = "notContainsBlanks";
+               needs_alt_texpr = TRUE;
+               n = 1; type = "notContainsBlanks";
                break;
        case GNM_STYLE_COND_CONTAINS_ERR:
-               n = 0; type = "containsErrors";
+               needs_alt_texpr = TRUE;
+               n = 1; type = "containsErrors";
                break;
        case GNM_STYLE_COND_NOT_CONTAINS_ERR:
-               n = 0; type = "notContainsErrors";
+               needs_alt_texpr = TRUE;
+               n = 1; type = "notContainsErrors";
                break;
        case GNM_STYLE_COND_CUSTOM:
                n = 1; type = "expression";
                break;
        case GNM_STYLE_COND_CONTAINS_STR:
+               needs_alt_texpr = TRUE;
                n = 1; type = "containsText";
                break;
        case GNM_STYLE_COND_NOT_CONTAINS_STR:
+               needs_alt_texpr = TRUE;
                n = 1; type = "notContainsText";
                break;
        case GNM_STYLE_COND_BEGINS_WITH_STR:
+               needs_alt_texpr = TRUE;
                n = 1; type = "beginsWith";
                break;
        case GNM_STYLE_COND_ENDS_WITH_STR:
+               needs_alt_texpr = TRUE;
                n = 1; type = "endsWith";
                break;
 
        case GNM_STYLE_COND_NOT_BEGINS_WITH_STR:
        case GNM_STYLE_COND_NOT_ENDS_WITH_STR:
-               alt_texpr = gnm_style_cond_get_alternate_expr (cond);
+               needs_alt_texpr = TRUE;
                n = 1; type = "expression";
                break;
 
        default:
                g_assert_not_reached ();
        }
+
+       alt_texpr = needs_alt_texpr
+               ? gnm_style_cond_get_alternate_expr (cond)
+               : NULL;
+
        gsf_xml_out_add_cstr_unchecked (xml, "type", type ? type : "cellIs");
        gsf_xml_out_add_int (xml, "dxfId",
                             xlsx_get_cond_style_id (state, cond->overlay));


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