[gnumeric] Fix ODF export of charts with series consisting of multiple ranges.



commit 94fd6ec5dd4a39d2ff641596bc263cb8020ccb9a
Author: Andreas J Guelzow <aguelzow pyrshep ca>
Date:   Tue Jul 23 15:46:25 2013 -0600

    Fix ODF export of charts with series consisting of multiple ranges.
    
    2013-07-23  Andreas J. Guelzow <aguelzow pyrshep ca>
    
        * openoffice-read.c (odf_write_data_element_range): new
        (odf_write_data_element): use odf_write_data_element_range

 NEWS                                  |    1 +
 plugins/openoffice/ChangeLog          |    5 +++
 plugins/openoffice/openoffice-write.c |   55 +++++++++++++++++++++++++++++++--
 3 files changed, 58 insertions(+), 3 deletions(-)
---
diff --git a/NEWS b/NEWS
index 80ccc74..dae0284 100644
--- a/NEWS
+++ b/NEWS
@@ -11,6 +11,7 @@ Andreas:
        * Fix ODF style import. [#704563]
        * Fix crash on corrupted files. [#704636]
        * Fix ODF import of charts with series consisting of multiple ranges. [#704742]
+       * Fix ODF export of charts with series consisting of multiple ranges.
 
 Jean:
        * Fix text wrap inside sheet objects. [#704417]
diff --git a/plugins/openoffice/ChangeLog b/plugins/openoffice/ChangeLog
index 20446d8..2686469 100644
--- a/plugins/openoffice/ChangeLog
+++ b/plugins/openoffice/ChangeLog
@@ -1,5 +1,10 @@
 2013-07-23  Andreas J. Guelzow <aguelzow pyrshep ca>
 
+       * openoffice-read.c (odf_write_data_element_range): new
+       (odf_write_data_element): use odf_write_data_element_range
+
+2013-07-23  Andreas J. Guelzow <aguelzow pyrshep ca>
+
        * openoffice-read.c (oo_plot_assign_dim): accept a range list rather
        than just a single range
 
diff --git a/plugins/openoffice/openoffice-write.c b/plugins/openoffice/openoffice-write.c
index 33a35fb..1c198f4 100644
--- a/plugins/openoffice/openoffice-write.c
+++ b/plugins/openoffice/openoffice-write.c
@@ -1532,7 +1532,7 @@ odf_strip_brackets (char *string)
 {
        char *closing;
        closing = strrchr(string, ']');
-       if (closing != NULL)
+       if (closing != NULL && *(closing+1) == '\0')
                *closing = '\0';
        return ((*string == '[') ? (string + 1) : string);
 }
@@ -6048,6 +6048,56 @@ odf_write_drop_line (GnmOOExport *state, GogObject const *series, char const *dr
        }
 }
 
+static void
+odf_write_data_element_range (GnmOOExport *state,  GnmParsePos *pp, GnmExprTop const *texpr,
+                             char const *attribute)
+{
+       char *str;
+
+       switch (GNM_EXPR_GET_OPER (texpr->expr)) {
+       case GNM_EXPR_OP_CONSTANT: 
+               if (texpr->expr->constant.value->type == VALUE_CELLRANGE) {
+                       str = gnm_expr_top_as_string (texpr, pp, state->conv);
+                       gsf_xml_out_add_cstr (state->xml, attribute,
+                                             odf_strip_brackets (str));
+                       g_free (str);
+                       return;
+               }
+               break;
+       case GNM_EXPR_OP_SET: {
+               int i;
+               gboolean success = TRUE;
+               GnmExpr const *expr = texpr->expr;
+               GString *gstr = g_string_new (NULL);
+               for (i = 0; i < expr->set.argc; i++) {
+                       GnmExpr const *expr_arg = expr->set.argv[i];
+                       if (GNM_EXPR_GET_OPER (expr_arg) == GNM_EXPR_OP_CONSTANT && 
+                           expr_arg->constant.value->type == VALUE_CELLRANGE) {
+                               char *str = gnm_expr_as_string (expr_arg, pp, state->conv);
+                               if (gstr->len > 0)
+                                       g_string_append_c (gstr, ' ');
+                               g_string_append (gstr, odf_strip_brackets (str));
+                               g_free (str);
+                       } else
+                               success = FALSE;
+               }
+               if (success) {
+                       gsf_xml_out_add_cstr (state->xml, attribute, gstr->str);
+                       g_string_free (gstr, TRUE);
+                       return;
+               }
+               g_string_free (gstr, TRUE);
+               break;
+       }
+       default:
+               break;
+       }
+       
+       /* ODF does not support anything else but we write it anyways */
+       str = gnm_expr_top_as_string (texpr, pp, state->conv);
+       gsf_xml_out_add_cstr (state->xml, attribute, str);
+       g_free (str);
+}
 
 static gboolean
 odf_write_data_element (GnmOOExport *state, GOData const *data, GnmParsePos *pp,
@@ -6058,8 +6108,7 @@ odf_write_data_element (GnmOOExport *state, GOData const *data, GnmParsePos *pp,
        if (NULL != texpr) {
                char *str = gnm_expr_top_as_string (texpr, pp, state->conv);
                gsf_xml_out_start_element (state->xml, element);
-               gsf_xml_out_add_cstr (state->xml, attribute,
-                                     odf_strip_brackets (str));
+               odf_write_data_element_range (state, pp, texpr, attribute);
                g_free (str);
                return TRUE;
        }


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