[gnumeric] xlsx: fix export of properties.



commit d7a0ca5c5478b7b9ab10d1fceef982cc9af7b35f
Author: Morten Welinder <terra gnome org>
Date:   Tue Dec 16 14:34:56 2014 -0500

    xlsx: fix export of properties.

 NEWS                                |    1 +
 plugins/excel/ChangeLog             |    6 ++++++
 plugins/excel/xlsx-write-docprops.c |   32 ++++++++++++++++++++++----------
 plugins/excel/xlsx-write.c          |    6 ++++++
 4 files changed, 35 insertions(+), 10 deletions(-)
---
diff --git a/NEWS b/NEWS
index 8a87274..e01df92 100644
--- a/NEWS
+++ b/NEWS
@@ -14,6 +14,7 @@ Morten:
        * Fix crash on closing a graph sheet.
        * Fix undo crash with conditional formatting and insert row.  [#741197]
        * Fix xlsx export of HYPGEOMDIST.
+       * Fix xlsx export of document properties.
 
 Thomas Kluyver:
        * Fix import of extended floats from wk4 files.  [#739697]
diff --git a/plugins/excel/ChangeLog b/plugins/excel/ChangeLog
index 2aef374..d7bf419 100644
--- a/plugins/excel/ChangeLog
+++ b/plugins/excel/ChangeLog
@@ -1,5 +1,11 @@
 2014-12-16  Morten Welinder  <terra gnome org>
 
+       * xlsx-write-docprops.c (xlsx_meta_write_props_custom_type):
+       Booleans should be saved as "true" or "false", not "t" and "f".
+       Excel refuses to understand the latter.
+       (xlsx_meta_write_props_custom): Don't reuse prop ids.  Excel does
+       not like that.
+
        * xlsx-utils.c (xlsx_func_hypgeomdist_output_handler): New handler
        for HYPGEOMDIST.
 
diff --git a/plugins/excel/xlsx-write-docprops.c b/plugins/excel/xlsx-write-docprops.c
index d66229d..930bc41 100644
--- a/plugins/excel/xlsx-write-docprops.c
+++ b/plugins/excel/xlsx-write-docprops.c
@@ -443,35 +443,46 @@ xlsx_meta_write_props_custom_type (char const *prop_name, GValue const *val, Gsf
        }
        gsf_xml_out_add_cstr (xml, "name", prop_name);
        gsf_xml_out_start_element (xml, type);
-       if (NULL != val)
-               gsf_xml_out_add_gvalue (xml, NULL, val);
+       if (NULL != val) {
+               switch (G_VALUE_TYPE (val)) {
+               case G_TYPE_BOOLEAN:
+                       gsf_xml_out_add_cstr (xml, NULL,
+                                             g_value_get_boolean (val) ? "true" : "false");
+                       break;
+               default:
+                       gsf_xml_out_add_gvalue (xml, NULL, val);
+                       break;
+               }
+       }
        gsf_xml_out_end_element (xml);
        gsf_xml_out_end_element (xml); /* </property> */
 }
 
 static void
-xlsx_meta_write_props_custom (char const *prop_name, GsfDocProp *prop, GsfXMLOut *output)
+xlsx_meta_write_props_custom (char const *prop_name, GsfDocProp *prop, XLSXClosure *info)
 {
-       int custom_pid = 29;
+       GsfXMLOut *output = info->xml;
+       XLSXWriteState *state = info->state;
+
        if ((0 != strcmp (GSF_META_NAME_GENERATOR, prop_name)) && (NULL == xlsx_map_prop_name (prop_name))
            &&  (NULL == xlsx_map_prop_name_extended (prop_name))) {
                GValue const *val = gsf_doc_prop_get_val (prop);
                if (VAL_IS_GSF_TIMESTAMP(val))
-                       xlsx_meta_write_props_custom_type (prop_name, val, output, "vt:date", &custom_pid);
+                       xlsx_meta_write_props_custom_type (prop_name, val, output, "vt:date", 
&state->custom_prop_id);
                else switch (G_VALUE_TYPE(val)) {
                        case G_TYPE_BOOLEAN:
-                               xlsx_meta_write_props_custom_type (prop_name, val, output, "vt:bool", 
&custom_pid);
+                               xlsx_meta_write_props_custom_type (prop_name, val, output, "vt:bool", 
&state->custom_prop_id);
                                break;
                        case G_TYPE_INT:
                        case G_TYPE_LONG:
-                               xlsx_meta_write_props_custom_type (prop_name, val, output, "vt:i4", 
&custom_pid);
+                               xlsx_meta_write_props_custom_type (prop_name, val, output, "vt:i4", 
&state->custom_prop_id);
                                break;
                        case G_TYPE_FLOAT:
                        case G_TYPE_DOUBLE:
-                               xlsx_meta_write_props_custom_type (prop_name, val, output, "vt:decimal", 
&custom_pid);
+                               xlsx_meta_write_props_custom_type (prop_name, val, output, "vt:decimal", 
&state->custom_prop_id);
                        break;
                        case G_TYPE_STRING:
-                               xlsx_meta_write_props_custom_type (prop_name, val, output, "vt:lpwstr", 
&custom_pid);
+                               xlsx_meta_write_props_custom_type (prop_name, val, output, "vt:lpwstr", 
&state->custom_prop_id);
                                break;
                        default:
                                break;
@@ -489,12 +500,13 @@ xlsx_write_docprops_custom (XLSXWriteState *state, GsfOutfile *root_part, GsfOut
                 "http://schemas.openxmlformats.org/officeDocument/2006/relationships/custom-properties";);
        GsfXMLOut *xml = gsf_xml_out_new (part);
        GsfDocMetaData *meta = go_doc_get_meta_data (GO_DOC (state->base.wb));
+       XLSXClosure info = { state, xml };
 
        gsf_xml_out_start_element (xml, "Properties");
        gsf_xml_out_add_cstr_unchecked (xml, "xmlns", ns_docprops_custom);
        gsf_xml_out_add_cstr_unchecked (xml, "xmlns:vt", ns_docprops_extended_vt);
 
-       gsf_doc_meta_data_foreach (meta, (GHFunc) xlsx_meta_write_props_custom, xml);
+       gsf_doc_meta_data_foreach (meta, (GHFunc) xlsx_meta_write_props_custom, &info);
 
        gsf_xml_out_end_element (xml); /* </Properties> */
 
diff --git a/plugins/excel/xlsx-write.c b/plugins/excel/xlsx-write.c
index c3d4a9c..8ecb732 100644
--- a/plugins/excel/xlsx-write.c
+++ b/plugins/excel/xlsx-write.c
@@ -119,6 +119,8 @@ typedef struct {
        } chart, drawing, pivotCache, pivotTable;
        unsigned comment;
        GOFormat *date_fmt;
+
+       int custom_prop_id;
 } XLSXWriteState;
 
 typedef struct {
@@ -3040,6 +3042,8 @@ xlsx_file_save (G_GNUC_UNUSED GOFileSaver const *fs, GOIOContext *io_context,
        state.io_context        = io_context;
        state.base.wb           = wb_view_get_workbook (wb_view);
        state.comment           = 0;
+       state.custom_prop_id    = 29;
+
        root_part = gsf_outfile_open_pkg_new (
                gsf_outfile_zip_new (output, NULL));
 
@@ -3066,6 +3070,8 @@ xlsx2_file_save (G_GNUC_UNUSED GOFileSaver const *fs, GOIOContext *io_context,
        state.io_context        = io_context;
        state.base.wb           = wb_view_get_workbook (wb_view);
        state.comment           = 0;
+       state.custom_prop_id    = 29;
+
        root_part = gsf_outfile_open_pkg_new (
                gsf_outfile_zip_new (output, NULL));
 


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