[gnumeric] Conditional formats: fix export/import of number format.



commit 2186a40aae8be91be30b353c5cfb4eb7801fb48b
Author: Morten Welinder <terra gnome org>
Date:   Mon Mar 17 11:11:34 2014 -0400

    Conditional formats: fix export/import of number format.
    
    Excel now understands what we write.

 plugins/excel/ms-excel-read.c  |   18 ++++++++----------
 plugins/excel/ms-excel-write.c |   12 ++++--------
 2 files changed, 12 insertions(+), 18 deletions(-)
---
diff --git a/plugins/excel/ms-excel-read.c b/plugins/excel/ms-excel-read.c
index 522919a..f78fee7 100644
--- a/plugins/excel/ms-excel-read.c
+++ b/plugins/excel/ms-excel-read.c
@@ -5250,20 +5250,18 @@ excel_read_CF (BiffQuery *q, ExcelReadSheet *esheet, GnmStyleConditions *sc,
        if (flags & 0x02000000) { /* number format */
                XL_CHECK_CONDITION (q->length >= offset + 2);
 
-               /*
-                * This is documented in MS-XLS and Excel does read it, i.e.,
-                * it accounts for the size of the field when reading.  Excel
-                * does not appear to act on it, though.
-                */
+               gboolean ignore = (flags & 0x00080000) != 0;
 
                if (flags2 & 1) {
                        /* Format as string */
                        guint bytes = GSF_LE_GET_GUINT16 (q->data + offset);
-                       char *xlfmt = excel_biff_text_2 (importer, q, offset + 2);
-                       GOFormat *fmt = go_format_new_from_XL (xlfmt);
-                       gnm_style_set_format (overlay, fmt);
-                       go_format_unref (fmt);
-                       g_free (xlfmt);
+                       if (!ignore) {
+                               char *xlfmt = excel_biff_text_2 (importer, q, offset + 2);
+                               GOFormat *fmt = go_format_new_from_XL (xlfmt);
+                               gnm_style_set_format (overlay, fmt);
+                               go_format_unref (fmt);
+                               g_free (xlfmt);
+                       }
                        offset += bytes;
                } else {
                        /* Format as index */
diff --git a/plugins/excel/ms-excel-write.c b/plugins/excel/ms-excel-write.c
index ecd8b4c..01aa158 100644
--- a/plugins/excel/ms-excel-write.c
+++ b/plugins/excel/ms-excel-write.c
@@ -1107,18 +1107,13 @@ cb_write_condition (GnmStyleConditions const *sc, CondDetails *cd,
                GnmStyleCond const *cond = g_ptr_array_index (details, i);
                GnmStyle const *s = cond->overlay;
                GnmExprTop const *alt_texpr;
-               guint32 flags = 0x0038C380; /* these are always true */
+               guint32 flags = 0x0030C380; /* these are always true */
                guint16 flags2 = 0x02; /* these are always true */
 
                ms_biff_put_var_next (bp, BIFF_CF);
                header_pos = bp->curpos;
                ms_biff_put_var_seekto (bp, header_pos+12);
 
-               /*
-                * This is documented in MS-XLS and Excel does read it, i.e.,
-                * it accounts for the size of the field when reading.  Excel
-                * does not appear to act on it, though.
-                */
                if (gnm_style_is_element_set (s, MSTYLE_FORMAT)) {
                        GOFormat const *fmt = gnm_style_get_format (s);
                        const char *xlfmt = go_format_as_XL (fmt);
@@ -1136,9 +1131,10 @@ cb_write_condition (GnmStyleConditions const *sc, CondDetails *cd,
                        ms_biff_put_var_write (bp, buf, 2);
                        ms_biff_put_var_seekto (bp, afterpos);
 
-                       flags |= 0x02000000;
+                       flags |= 0x02000000; /* has dxfnum record */
                        flags2 |= 0x1;
-               }
+               } else
+                       flags |= 0x00080000; /* ignore number format */
 
                if (gnm_style_is_element_set (s, MSTYLE_FONT_COLOR) ||
                    gnm_style_is_element_set (s, MSTYLE_FONT_NAME) ||


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