[gnumeric] xls: fix export of headers and footers.



commit 98eb61d0fb2529f77600b36e6675d24d30004de6
Author: Morten Welinder <terra gnome org>
Date:   Sun Feb 23 22:09:56 2014 -0500

    xls: fix export of headers and footers.

 NEWS                           |    1 +
 plugins/excel/ChangeLog        |    7 ++++
 plugins/excel/ms-excel-util.c  |   62 ++++++++++++++++++++++++++++++++++++++++
 plugins/excel/ms-excel-util.h  |    5 +++
 plugins/excel/ms-excel-write.c |   19 ++----------
 plugins/excel/xlsx-write.c     |   57 ++----------------------------------
 6 files changed, 81 insertions(+), 70 deletions(-)
---
diff --git a/NEWS b/NEWS
index 484ccd0..c4ba718 100644
--- a/NEWS
+++ b/NEWS
@@ -30,6 +30,7 @@ Morten:
        * Fix xls export of long strings in various places.
        * Fix BIFF7 export of comments.
        * Improve style handling when expanding sheets. 
+       * Fix xls export of headers and footers.  [Part of #724516]
 
 --------------------------------------------------------------------------
 Gnumeric 1.12.11
diff --git a/plugins/excel/ChangeLog b/plugins/excel/ChangeLog
index 1eed73c..3df029d 100644
--- a/plugins/excel/ChangeLog
+++ b/plugins/excel/ChangeLog
@@ -1,5 +1,12 @@
 2014-02-23  Morten Welinder  <terra gnome org>
 
+       * ms-excel-util.c (xls_header_footer_export): New function
+       extracted from...
+       * xlsx-write.c (xlsx_write_print_info_hf): ...here
+
+       * ms-excel-write.c (excel_write_HEADER_FOOTER): Properly translate
+       magic codes.
+
        * xlsx-read.c (xlsx_CT_header_footer): Read headerfooter info.
 
        * xlsx-write.c (xlsx_write_print_info): headerFooter before page
diff --git a/plugins/excel/ms-excel-util.c b/plugins/excel/ms-excel-util.c
index ca91698..a0681e0 100644
--- a/plugins/excel/ms-excel-util.c
+++ b/plugins/excel/ms-excel-util.c
@@ -16,6 +16,7 @@
 #include "style.h"
 #include "ms-excel-util.h"
 #include <goffice/goffice.h>
+#include <glib/gi18n-lib.h>
 
 #include <string.h>
 
@@ -683,3 +684,64 @@ xls_paper_size (GtkPaperSize *ps, gboolean rotated)
 
        return 0;
 }
+
+
+static void
+xls_header_footer_export1 (GString *res, const char *s, const char *section)
+{
+       static const struct {
+               const char *name;
+               const char *xls_code;
+       } codes[] = {
+               { N_("TAB"),   "&A"},
+               { N_("PAGE"),  "&P"},
+               { N_("PAGES"), "&N"},
+               { N_("DATE"),  "&D"},
+               { N_("TIME"),  "&T"},
+               { N_("FILE"),  "&F"},
+               { N_("PATH"),  "&Z"},
+#if 0
+               { N_("CELL"),  "" /* ??? */},
+               { N_("TITLE"), "" /* ??? */}
+#endif
+       };
+
+       if (!s || *s == 0)
+               return;
+
+       g_string_append (res, section);
+       while (*s) {
+               const char *end;
+
+               if (*s == '&' && s[1] == '[' && (end = strchr (s + 2, ']'))) {
+                       size_t l = end - (s + 2);
+                       unsigned ui;
+
+                       for (ui = 0; ui < G_N_ELEMENTS (codes); ui++) {
+                               const char *tname = _(codes[ui].name);
+                               if (l == strlen (tname) &&
+                                   g_ascii_strncasecmp (tname, s + 2, l) == 0) {
+                                       g_string_append (res, codes[ui].xls_code);
+                                       break;
+                               }
+                       }
+                       s = end + 1;
+                       continue;
+               }
+
+               g_string_append_c (res, *s++);
+       }
+}
+
+
+char *
+xls_header_footer_export (const PrintHF *hf)
+{
+       GString *res = g_string_new (NULL);
+
+       xls_header_footer_export1 (res, hf->left_format, "&L");
+       xls_header_footer_export1 (res, hf->middle_format, "&C");
+       xls_header_footer_export1 (res, hf->right_format, "&R");
+
+       return g_string_free (res, FALSE);
+}
diff --git a/plugins/excel/ms-excel-util.h b/plugins/excel/ms-excel-util.h
index 534af8a..78adb01 100644
--- a/plugins/excel/ms-excel-util.h
+++ b/plugins/excel/ms-excel-util.h
@@ -12,6 +12,7 @@
 
 #include <glib.h>
 #include <stdlib.h>
+#include <print-info.h>
 
 /*
  * Check a condition relating to whether the file being read is ok.
@@ -101,5 +102,9 @@ unsigned xls_paper_size (GtkPaperSize *ps, gboolean rotated);
 
 /*****************************************************************************/
 
+char *xls_header_footer_export (const PrintHF *hf);
+
+/*****************************************************************************/
+
 
 #endif /* GNM_MS_EXCEL_UTIL_H */
diff --git a/plugins/excel/ms-excel-write.c b/plugins/excel/ms-excel-write.c
index 7780e4e..2cc6c80 100644
--- a/plugins/excel/ms-excel-write.c
+++ b/plugins/excel/ms-excel-write.c
@@ -4900,30 +4900,17 @@ excel_write_PAGE_BREAK (BiffPut *bp, GnmPageBreaks const *breaks)
 static void
 excel_write_HEADER_FOOTER (BiffPut *bp, PrintHF const *hf, int id)
 {
-       GString *res = g_string_new (NULL);
-
-       if (hf->left_format != NULL) {
-               g_string_append (res, "&L");
-               g_string_append (res, hf->left_format);
-       }
-       if (hf->middle_format != NULL) {
-               g_string_append (res, "&C");
-               g_string_append (res, hf->middle_format);
-       }
-       if (hf->right_format != NULL) {
-               g_string_append (res, "&R");
-               g_string_append (res, hf->right_format);
-       }
+       char *s = xls_header_footer_export (hf);
 
        ms_biff_put_var_next (bp, id);
        excel_write_string (bp,
                            (bp->version >= MS_BIFF_V8
                             ? STR_TWO_BYTE_LENGTH
                             : STR_ONE_BYTE_LENGTH),
-                           res->str);
+                           s);
        ms_biff_put_commit (bp);
 
-       g_string_free (res, TRUE);
+       g_free (s);
 }
 
 static void
diff --git a/plugins/excel/xlsx-write.c b/plugins/excel/xlsx-write.c
index 8a6e9d0..5c790cb 100644
--- a/plugins/excel/xlsx-write.c
+++ b/plugins/excel/xlsx-write.c
@@ -1970,67 +1970,16 @@ xlsx_find_paper_code (GtkPaperSize *psize)
 }
 
 static void
-xlsx_write_print_info_hf1 (GString *res, const char *s, const char *section)
-{
-       static const struct {
-               const char *name;
-               const char *xlsx_code;
-       } codes[] = {
-               { N_("TAB"),   "&A"},
-               { N_("PAGE"),  "&P"},
-               { N_("PAGES"), "&N"},
-               { N_("DATE"),  "&D"},
-               { N_("TIME"),  "&T"},
-               { N_("FILE"),  "&F"},
-               { N_("PATH"),  "&Z"},
-#if 0
-               { N_("CELL"),  "" /* ??? */},
-               { N_("TITLE"), "" /* ??? */}
-#endif
-       };
-
-       if (!s || *s == 0)
-               return;
-
-       g_string_append (res, section);
-       while (*s) {
-               const char *end;
-
-               if (*s == '&' && s[1] == '[' && (end = strchr (s + 2, ']'))) {
-                       size_t l = end - (s + 2);
-                       unsigned ui;
-
-                       for (ui = 0; ui < G_N_ELEMENTS (codes); ui++) {
-                               const char *tname = _(codes[ui].name);
-                               if (l == strlen (tname) &&
-                                   g_ascii_strncasecmp (tname, s + 2, l) == 0) {
-                                       g_string_append (res, codes[ui].xlsx_code);
-                                       break;
-                               }
-                       }                       
-                       s = end + 1;
-                       continue;
-               }
-
-               g_string_append_c (res, *s++);
-       }
-}
-
-static void
 xlsx_write_print_info_hf (XLSXWriteState *state, GsfXMLOut *xml,
                          const PrintHF *hf, const char *hftext)
 {
-       GString *res = g_string_new (NULL);
-
-       xlsx_write_print_info_hf1 (res, hf->left_format, "&L");
-       xlsx_write_print_info_hf1 (res, hf->middle_format, "&C");
-       xlsx_write_print_info_hf1 (res, hf->right_format, "&R");
+       char *s = xls_header_footer_export (hf);
 
        gsf_xml_out_start_element (xml, hftext);
-       gsf_xml_out_add_cstr (xml, NULL, res->str);
+       gsf_xml_out_add_cstr (xml, NULL, s);
        gsf_xml_out_end_element (xml); /* hftext */
 
-       g_string_free (res, TRUE);
+       g_free (s);
 }
 
 static void


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