[gnumeric] xlsx: in the absence of header/footer use blank settings.



commit e1e2cc72b7cf0ce0c31a88a94eb67eabf32e9bd0
Author: Morten Welinder <terra gnome org>
Date:   Tue Feb 7 11:51:49 2017 -0500

    xlsx: in the absence of header/footer use blank settings.

 NEWS                          |    1 +
 plugins/excel/ChangeLog       |    5 +++++
 plugins/excel/ms-excel-util.c |   12 ++++++++----
 plugins/excel/xlsx-read.c     |   21 +++++++++++++++++++--
 4 files changed, 33 insertions(+), 6 deletions(-)
---
diff --git a/NEWS b/NEWS
index 63e1931..1490710 100644
--- a/NEWS
+++ b/NEWS
@@ -2,6 +2,7 @@ Gnumeric 1.12.34
 
 Morten:
        * Doc fixes.
+       * Fix xlsx import with missing header/footer. [#778292]
 
 --------------------------------------------------------------------------
 Gnumeric 1.12.33
diff --git a/plugins/excel/ChangeLog b/plugins/excel/ChangeLog
index 294e791..f69f386 100644
--- a/plugins/excel/ChangeLog
+++ b/plugins/excel/ChangeLog
@@ -1,3 +1,8 @@
+2017-02-07  Morten Welinder  <terra gnome org>
+
+       * xlsx-read.c (wrap_sheet_new): New function to ensure we start
+       with blank header and footer.  Fixes #778292.
+
 2017-01-30  Morten Welinder <terra gnome org>
 
        * Release 1.12.33
diff --git a/plugins/excel/ms-excel-util.c b/plugins/excel/ms-excel-util.c
index 3d88d14..63e78c4 100644
--- a/plugins/excel/ms-excel-util.c
+++ b/plugins/excel/ms-excel-util.c
@@ -758,10 +758,14 @@ xls_header_footer_import (GnmPrintHF **phf, const char *txt)
 
        if (!hf)
                *phf = hf = gnm_print_hf_new ("", "", "");
-
-       g_free (hf->left_format); hf->left_format = g_strdup ("");
-       g_free (hf->middle_format); hf->middle_format = g_strdup ("");
-       g_free (hf->right_format); hf->right_format = g_strdup ("");
+       else {
+               g_free (hf->left_format);
+               hf->left_format = g_strdup ("");
+               g_free (hf->middle_format);
+               hf->middle_format = g_strdup ("");
+               g_free (hf->right_format);
+               hf->right_format = g_strdup ("");
+       }
 
        if (!txt)
                return;
diff --git a/plugins/excel/xlsx-read.c b/plugins/excel/xlsx-read.c
index d93a14f..afc5f7d 100644
--- a/plugins/excel/xlsx-read.c
+++ b/plugins/excel/xlsx-read.c
@@ -319,6 +319,23 @@ typedef struct {
 } XLSXPaperDefs;
 
 
+static Sheet *
+wrap_sheet_new (Workbook *wb, char const *name, int columns, int rows)
+{
+       Sheet *sheet = sheet_new_with_type (wb, name, GNM_SHEET_DATA, columns, rows);
+       GnmPrintInformation *pi = sheet->print_info;
+
+       // Force a load of defaults here.
+       gnm_print_info_load_defaults (pi);
+
+       // We have different defaults for header and footer (namely blank)
+       xls_header_footer_import (&pi->header, NULL);
+       xls_header_footer_import (&pi->footer, NULL);
+
+       return sheet;
+}
+
+
 static void
 maybe_update_progress (GsfXMLIn *xin)
 {
@@ -3648,7 +3665,7 @@ xlsx_sheet_begin (GsfXMLIn *xin, xmlChar const **attrs)
 
        sheet =  workbook_sheet_by_name (state->wb, name);
        if (NULL == sheet) {
-               sheet = sheet_new (state->wb, name, XLSX_MaxCol, XLSX_MaxRow);
+               sheet = wrap_sheet_new (state->wb, name, XLSX_MaxCol, XLSX_MaxRow);
                workbook_sheet_attach (state->wb, sheet);
        }
        g_object_set (sheet, "visibility", viz, NULL);
@@ -3794,7 +3811,7 @@ xlsx_read_external_sheetname (GsfXMLIn *xin, xmlChar const **attrs)
                                workbook_sheet_attach
                                        (state->external_ref,
                                         state->external_ref_sheet =
-                                        sheet_new (state->external_ref, attrs[1], 256, 65536));
+                                        wrap_sheet_new (state->external_ref, attrs[1], 256, 65536));
                }
 }
 static void


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