[gnumeric] xlsx: make export more deterministic.



commit 3a74dd2040bd8972b9de6fd5cf2639ead22b0a7a
Author: Morten Welinder <terra gnome org>
Date:   Wed Apr 15 07:58:16 2015 -0400

    xlsx: make export more deterministic.

 ChangeLog                  |    4 ++++
 plugins/excel/ChangeLog    |    5 +++++
 plugins/excel/xlsx-write.c |   15 ++++++++++++++-
 src/ranges.c               |   22 ++++++++++++++++++++++
 src/ranges.h               |    1 +
 5 files changed, 46 insertions(+), 1 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 3b36c30..b7c6b54 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+2015-04-15  Morten Welinder  <terra gnome org>
+
+       * src/ranges.c (gnm_range_compare): New function.
+
 2015-04-13  Jean Brefort  <jean brefort normalesup org>
 
        * src/wbc-gtk.c (set_entry_contents): format number whenever possible.
diff --git a/plugins/excel/ChangeLog b/plugins/excel/ChangeLog
index eb15700..85ac6cf 100644
--- a/plugins/excel/ChangeLog
+++ b/plugins/excel/ChangeLog
@@ -1,3 +1,8 @@
+2015-04-15  Morten Welinder  <terra gnome org>
+
+       * xlsx-write.c (xlsx_write_validations): Impose an ordering of
+       validation entries.
+
 2015-04-13  Morten Welinder  <terra gnome org>
 
        * xlsx-read-drawing.c (xlsx_chart_pie_angle): Read firstSliceAng.
diff --git a/plugins/excel/xlsx-write.c b/plugins/excel/xlsx-write.c
index 66fcb40..704c57a 100644
--- a/plugins/excel/xlsx-write.c
+++ b/plugins/excel/xlsx-write.c
@@ -2021,6 +2021,16 @@ xlsx_write_validation (XLValInputPair const *vip, G_GNUC_UNUSED gpointer dummy,
        gsf_xml_out_end_element (info->xml); /*  </dataValidation> */
 }
 
+static int
+by_first_range (gpointer vip_a, G_GNUC_UNUSED gpointer val_a,
+               gpointer vip_b, G_GNUC_UNUSED gpointer val_b,
+               G_GNUC_UNUSED gpointer user)
+{
+       const XLValInputPair *a = vip_a;
+       const XLValInputPair *b = vip_b;
+       return gnm_range_compare (a->ranges->data, b->ranges->data);
+}
+
 static void
 xlsx_write_validations (XLSXWriteState *state, GsfXMLOut *xml, G_GNUC_UNUSED GnmRange const *extent)
 {
@@ -2035,7 +2045,10 @@ xlsx_write_validations (XLSXWriteState *state, GsfXMLOut *xml, G_GNUC_UNUSED Gnm
 
                gsf_xml_out_start_element (xml, "dataValidations");
                gsf_xml_out_add_int (xml, "count", g_hash_table_size (group)) ;
-               g_hash_table_foreach (group, (GHFunc) xlsx_write_validation, &info);
+               gnm_hash_table_foreach_ordered
+                       (group, (GHFunc)xlsx_write_validation,
+                        by_first_range,
+                        &info);
                gsf_xml_out_end_element (xml); /*  </dataValidations> */
 
                g_hash_table_destroy (group);
diff --git a/src/ranges.c b/src/ranges.c
index d469b22..d89eebc 100644
--- a/src/ranges.c
+++ b/src/ranges.c
@@ -784,6 +784,28 @@ gnm_range_equal (const GnmRange *a, const GnmRange *b)
        return range_equal (a, b);
 }
 
+/**
+ * gnm_range_compare:
+ * @a: first range
+ * @b: second range
+ *
+ * Returns: a value that is negative if range @a comes before range @b;
+ * zero if the two ranges are equal; positive if range @a comes after
+ * range @b.  The order imposed is lexicographical by starting row,
+ * then column, then ending row, then column.
+ */
+int
+gnm_range_compare (GnmRange const *a, GnmRange const *b)
+{
+       int i = 0;
+       if (!i) i = a->start.row - b->start.row;
+       if (!i) i = a->start.col - b->start.col;
+       if (!i) i = a->end.row - b->end.row;
+       if (!i) i = a->end.col - b->end.col;
+       return i;
+}
+
+
 GnmSheetRange *
 gnm_sheet_range_new (Sheet *sheet, GnmRange const *r)
 {
diff --git a/src/ranges.h b/src/ranges.h
index bb47e35..35bd5be 100644
--- a/src/ranges.h
+++ b/src/ranges.h
@@ -24,6 +24,7 @@ G_BEGIN_DECLS
 GType    gnm_range_get_type (void); /* GBoxedType */
 GnmRange *gnm_range_dup          (GnmRange const *r);
 gboolean  gnm_range_equal (GnmRange const *a, GnmRange const *b);
+int       gnm_range_compare (GnmRange const *a, GnmRange const *b);
 
 /**
  * range_overlap:


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