[gnumeric] xlsx: fix export of cell protection



commit 848801ab48fae44a933b515c0d742d21b052fc43
Author: Morten Welinder <terra gnome org>
Date:   Sat Jul 20 14:37:36 2019 -0400

    xlsx: fix export of cell protection

 NEWS                       |  1 +
 plugins/excel/ChangeLog    |  5 +++++
 plugins/excel/xlsx-write.c | 22 ++++++++++++++++++++++
 3 files changed, 28 insertions(+)
---
diff --git a/NEWS b/NEWS
index bd7dc3006..ec713f1df 100644
--- a/NEWS
+++ b/NEWS
@@ -7,6 +7,7 @@ Morten:
        * Fix over-eager guessing of dates in csv.  [#401]
        * Fix Mac build problem.  [#402]
        * Fix inter-process paste crash [#406]
+       * Fix problem saving cell protection to xlsx.  [#409]
 
 --------------------------------------------------------------------------
 Gnumeric 1.12.45
diff --git a/plugins/excel/ChangeLog b/plugins/excel/ChangeLog
index 1bf60440d..071f2f72e 100644
--- a/plugins/excel/ChangeLog
+++ b/plugins/excel/ChangeLog
@@ -1,3 +1,8 @@
+2019-07-20  Morten Welinder  <terra gnome org>
+
+       * xlsx-write.c (xlsx_write_style): Wrote cell protection too.
+       Fixes #409.
+
 2019-05-20  Morten Welinder <terra gnome org>
 
        * Release 1.12.45
diff --git a/plugins/excel/xlsx-write.c b/plugins/excel/xlsx-write.c
index 4a2cfbba7..de3daddfb 100644
--- a/plugins/excel/xlsx-write.c
+++ b/plugins/excel/xlsx-write.c
@@ -1134,6 +1134,13 @@ xlsx_has_alignment_style (GnmStyle const *style)
                || gnm_style_is_element_set (style, MSTYLE_INDENT);
 }
 
+static gboolean
+xlsx_has_protection_style (GnmStyle const *style)
+{
+       return gnm_style_is_element_set (style, MSTYLE_CONTENTS_LOCKED)
+               || gnm_style_is_element_set (style, MSTYLE_CONTENTS_HIDDEN);
+}
+
 static void
 xlsx_write_style_write_alignment (G_GNUC_UNUSED XLSXWriteState *state, GsfXMLOut *xml,
                  GnmStyle const *style)
@@ -1221,6 +1228,18 @@ xlsx_write_style_write_alignment (G_GNUC_UNUSED XLSXWriteState *state, GsfXMLOut
        gsf_xml_out_end_element (xml);
 }
 
+static void
+xlsx_write_style_write_protection (G_GNUC_UNUSED XLSXWriteState *state, GsfXMLOut *xml,
+                 GnmStyle const *style)
+{
+       gsf_xml_out_start_element (xml, "protection");
+       if (gnm_style_is_element_set (style, MSTYLE_CONTENTS_LOCKED))
+               gsf_xml_out_add_bool (xml, "locked", gnm_style_get_contents_locked (style));
+       if (gnm_style_is_element_set (style, MSTYLE_CONTENTS_HIDDEN))
+               gsf_xml_out_add_bool (xml, "hidden", gnm_style_get_contents_hidden (style));
+       gsf_xml_out_end_element (xml);
+}
+
 static void
 xlsx_write_style (XLSXWriteState *state, GsfXMLOut *xml,
                  GnmStyle const *style, GHashTable *fills_hash,
@@ -1228,6 +1247,7 @@ xlsx_write_style (XLSXWriteState *state, GsfXMLOut *xml,
                  GHashTable *border_hash, gint id)
 {
        gboolean alignment = xlsx_has_alignment_style (style);
+       gboolean protection = xlsx_has_protection_style (style);
        gpointer tmp_fill, tmp_font, tmp_border;
        gboolean fill = (NULL != (tmp_fill = g_hash_table_lookup (fills_hash, style)));
        gboolean font = (NULL != (tmp_font = g_hash_table_lookup (fonts_hash, style)));
@@ -1256,6 +1276,8 @@ xlsx_write_style (XLSXWriteState *state, GsfXMLOut *xml,
 
        if (alignment)
                xlsx_write_style_write_alignment (state, xml, style);
+       if (protection)
+               xlsx_write_style_write_protection (state, xml, style);
 }
 
 static void


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