[gnumeric] xlsx: import and export trend line names



commit 6e2f4b4ec035c0c176843a225b6b8e4d9b0bf41b
Author: Morten Welinder <terra gnome org>
Date:   Sat Jan 24 11:48:40 2015 -0500

    xlsx: import and export trend line names

 NEWS                               |    1 +
 plugins/excel/xlsx-read-drawing.c  |   31 ++++++++++++++++++++++++++-----
 plugins/excel/xlsx-write-drawing.c |    7 ++++++-
 3 files changed, 33 insertions(+), 6 deletions(-)
---
diff --git a/NEWS b/NEWS
index 9b282c0..dd3711a 100644
--- a/NEWS
+++ b/NEWS
@@ -2,6 +2,7 @@ Gnumeric 1.12.20
 
 Morten:
        * xlsx chart import: fix font family name.
+       * xlsx import/export trend line names.
 
 --------------------------------------------------------------------------
 Gnumeric 1.12.19
diff --git a/plugins/excel/xlsx-read-drawing.c b/plugins/excel/xlsx-read-drawing.c
index 1e066a4..59acb1c 100644
--- a/plugins/excel/xlsx-read-drawing.c
+++ b/plugins/excel/xlsx-read-drawing.c
@@ -989,6 +989,15 @@ xlsx_ser_trendline_end (GsfXMLIn *xin, G_GNUC_UNUSED GsfXMLBlob *blob)
 }
 
 static void
+xlsx_ser_trendline_name (GsfXMLIn *xin, G_GNUC_UNUSED GsfXMLBlob *blob)
+{
+       XLSXReadState *state = (XLSXReadState *)xin->user_state;
+       const char *name = xin->content->str;
+       g_free (state->chart_tx);
+       state->chart_tx = g_strdup (name);
+}
+
+static void
 xlsx_ser_trendline_type (GsfXMLIn *xin, G_GNUC_UNUSED  xmlChar const **attrs)
 {
        XLSXReadState *state = (XLSXReadState *)xin->user_state;
@@ -1008,11 +1017,22 @@ xlsx_ser_trendline_type (GsfXMLIn *xin, G_GNUC_UNUSED  xmlChar const **attrs)
 
        if (simple_enum (xin, attrs, styles, &typ)) {
                state->cur_obj = GOG_OBJECT (gog_trend_line_new_by_name (types[typ]));
-               if (state->cur_obj)
-                       gog_object_add_by_name (GOG_OBJECT (state->series),
-                                               "Trend line",
-                                               state->cur_obj);
+               if (state->cur_obj) {
+                       GogObject *trend =
+                               gog_object_add_by_name (GOG_OBJECT (state->series),
+                                                       "Trend line",
+                                                       state->cur_obj);
+                       if (state->chart_tx) {
+                               GOData *dat =
+                                       gnm_go_data_scalar_new_expr (state->sheet,
+                                                                    gnm_expr_top_new_constant 
(value_new_string (state->chart_tx)));
+                               gog_dataset_set_dim (GOG_DATASET (trend), -1, dat, NULL);
+                       }
+               }
        }
+
+       g_free (state->chart_tx);
+       state->chart_tx = NULL;
 }
 
 static GogObject *
@@ -2064,7 +2084,8 @@ GSF_XML_IN_NODE_FULL (START, CHART_SPACE, XL_NS_CHART, "chartSpace", GSF_XML_NO_
 
         GSF_XML_IN_NODE (SCATTER, SERIES, XL_NS_CHART, "ser", GSF_XML_NO_CONTENT, &xlsx_chart_ser_start, 
&xlsx_chart_ser_end),
           GSF_XML_IN_NODE (SERIES, SERIES_TRENDLINE, XL_NS_CHART,      "trendline", GSF_XML_NO_CONTENT, 
&xlsx_ser_trendline_start, &xlsx_ser_trendline_end),
-          GSF_XML_IN_NODE (SERIES_TRENDLINE, SHAPE_PR, XL_NS_CHART, "spPr", GSF_XML_NO_CONTENT, NULL, NULL), 
  /* 2nd Def */
+            GSF_XML_IN_NODE (SERIES_TRENDLINE, SERIES_TRENDLINE_NAME, XL_NS_CHART, "name", GSF_XML_CONTENT, 
NULL, &xlsx_ser_trendline_name),
+            GSF_XML_IN_NODE (SERIES_TRENDLINE, SHAPE_PR, XL_NS_CHART, "spPr", GSF_XML_NO_CONTENT, NULL, 
NULL), /* 2nd Def */
             GSF_XML_IN_NODE (SERIES_TRENDLINE, SERIES_TRENDLINE_TYPE, XL_NS_CHART,     "trendlineType", 
GSF_XML_NO_CONTENT, &xlsx_ser_trendline_type, NULL),
             GSF_XML_IN_NODE (SERIES_TRENDLINE, SERIES_TRENDLINE_RSQR, XL_NS_CHART,     "dispRSqr", 
GSF_XML_NO_CONTENT, &xlsx_ser_trendline_disprsqr, NULL),
             GSF_XML_IN_NODE (SERIES_TRENDLINE, SERIES_TRENDLINE_EQ, XL_NS_CHART,       "dispEq", 
GSF_XML_NO_CONTENT, &xlsx_ser_trendline_dispeq, NULL),
diff --git a/plugins/excel/xlsx-write-drawing.c b/plugins/excel/xlsx-write-drawing.c
index a7b8151..64b2b6b 100644
--- a/plugins/excel/xlsx-write-drawing.c
+++ b/plugins/excel/xlsx-write-drawing.c
@@ -607,6 +607,8 @@ xlsx_write_one_plot (XLSXWriteState *state, GsfXMLOut *xml, GogObject const *cha
                        const char *trend_type_name = G_OBJECT_TYPE_NAME (trend);
                        const char *trend_type;
                        GogObject *eq;
+                       GOData *dat;
+                       char *name;
 
                        if (!GOG_IS_TREND_LINE (trend))
                                continue;
@@ -628,8 +630,11 @@ xlsx_write_one_plot (XLSXWriteState *state, GsfXMLOut *xml, GogObject const *cha
                                g_warning ("Unknown regression mapped to %s\n", trend_type);
                        }
 
-
                        gsf_xml_out_start_element (xml, "c:trendline");
+                       dat = gog_dataset_get_dim (GOG_DATASET (trend), -1);
+                       name = go_data_get_scalar_string (dat);
+                       gsf_xml_out_simple_element (xml, "c:name", name);
+                       g_free (name);
                        xlsx_write_go_style (xml, go_styled_object_get_style (GO_STYLED_OBJECT (trend)));
                        xlsx_write_chart_cstr_unchecked (xml, "c:trendlineType", trend_type);
                        gsf_xml_out_end_element (xml); /* </c:trendline> */


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