[gnumeric] xlsx: first stab a exporting headers and footers.



commit 9a6e9d9728594803474acc359dca3d66ac79f783
Author: Morten Welinder <terra gnome org>
Date:   Thu Feb 20 19:56:04 2014 -0500

    xlsx: first stab a exporting headers and footers.

 NEWS                       |    1 +
 plugins/excel/ChangeLog    |    3 ++
 plugins/excel/xlsx-write.c |   69 ++++++++++++++++++++++++++++++++++++++++++--
 3 files changed, 70 insertions(+), 3 deletions(-)
---
diff --git a/NEWS b/NEWS
index a6a58fb..e34d736 100644
--- a/NEWS
+++ b/NEWS
@@ -21,6 +21,7 @@ Morten:
        * Fix BIFF7 export of font rotation.
        * Fix xlsx export of underlines.
        * Fix BIFF8 export of diagonal borders.
+       * Export headers and footers to xlsx.  [Part of #724516]
 
 --------------------------------------------------------------------------
 Gnumeric 1.12.11
diff --git a/plugins/excel/ChangeLog b/plugins/excel/ChangeLog
index 44b5928..42cdc10 100644
--- a/plugins/excel/ChangeLog
+++ b/plugins/excel/ChangeLog
@@ -1,5 +1,8 @@
 2014-02-20  Morten Welinder  <terra gnome org>
 
+       * xlsx-write.c (xlsx_write_print_info): First stab at exporting
+       headers and footers.
+
        * ms-excel-write.c (excel_write_XF): Fix reversed diagonal border
        bits.
 
diff --git a/plugins/excel/xlsx-write.c b/plugins/excel/xlsx-write.c
index c075650..66fb1c6 100644
--- a/plugins/excel/xlsx-write.c
+++ b/plugins/excel/xlsx-write.c
@@ -1970,6 +1970,70 @@ 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)
+               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");
+
+       gsf_xml_out_start_element (xml, hftext);
+       gsf_xml_out_add_cstr (xml, NULL, res->str);
+       gsf_xml_out_end_element (xml); /* hftext */
+
+       g_string_free (res, TRUE);
+}
+
+static void
 xlsx_write_print_info (XLSXWriteState *state, GsfXMLOut *xml)
 {
        PrintInformation *pi = state->sheet->print_info;
@@ -2092,11 +2156,10 @@ xlsx_write_print_info (XLSXWriteState *state, GsfXMLOut *xml)
        if (NULL != pi->page_breaks.h)
                xlsx_write_breaks (state, xml, pi->page_breaks.h);
 
-#if 0
        gsf_xml_out_start_element (xml, "headerFooter");
+       xlsx_write_print_info_hf (state, xml, pi->header, "oddHeader");
+       xlsx_write_print_info_hf (state, xml, pi->footer, "oddFooter");
        gsf_xml_out_end_element (xml); /* </headerFooter> */
-#endif
-
 }
 
 /**********************************************************************/


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