[gnumeric] xlsx: import headers and footers from xlsx
- From: Morten Welinder <mortenw src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnumeric] xlsx: import headers and footers from xlsx
- Date: Sun, 23 Feb 2014 22:22:02 +0000 (UTC)
commit e0721d7d3be1b4c183752270a629905d25082dbe
Author: Morten Welinder <terra gnome org>
Date: Sun Feb 23 17:21:23 2014 -0500
xlsx: import headers and footers from xlsx
NEWS | 1 +
plugins/excel/ChangeLog | 2 +
plugins/excel/xlsx-read.c | 93 +++++++++++++++++++++++++++++++++++++++++++-
plugins/excel/xlsx-write.c | 18 ++++----
src/print-info.c | 18 ++++----
5 files changed, 112 insertions(+), 20 deletions(-)
---
diff --git a/NEWS b/NEWS
index 1109220..4341e84 100644
--- a/NEWS
+++ b/NEWS
@@ -24,6 +24,7 @@ Morten:
* Fix xlsx export of underlines.
* Fix BIFF8 export of diagonal borders.
* Export headers and footers to xlsx. [Part of #724516]
+ * Import headers and footers from xlsx. [Part of #724516]
* Fix xls export of long strings in formulas.
* Fix xls import of cells with long string results.
* Fix xls export of long strings in various places.
diff --git a/plugins/excel/ChangeLog b/plugins/excel/ChangeLog
index 5d5e93a..1eed73c 100644
--- a/plugins/excel/ChangeLog
+++ b/plugins/excel/ChangeLog
@@ -1,5 +1,7 @@
2014-02-23 Morten Welinder <terra gnome org>
+ * xlsx-read.c (xlsx_CT_header_footer): Read headerfooter info.
+
* xlsx-write.c (xlsx_write_print_info): headerFooter before page
breaks. Evidently Excel cares.
diff --git a/plugins/excel/xlsx-read.c b/plugins/excel/xlsx-read.c
index cd47e1e..138eb08 100644
--- a/plugins/excel/xlsx-read.c
+++ b/plugins/excel/xlsx-read.c
@@ -1938,6 +1938,95 @@ xlsx_CT_PageMargins (GsfXMLIn *xin, xmlChar const **attrs)
print_info_set_margin_footer (pi, GO_IN_TO_PT (margin));
}
+
+static void
+xlsx_CT_header_footer (XLSXReadState *state, PrintHF *hf, const char *txt)
+{
+ char section = 'L';
+ GString *accum = g_string_new (NULL);
+
+ 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 ("");
+
+ while (1) {
+ if (txt[0] == 0 ||
+ (txt[0] == '&' && strchr ("LCR", txt[1]))) {
+ char **sp;
+ switch (section) {
+ case 'L': sp = &hf->left_format; break;
+ case 'C': sp = &hf->middle_format; break;
+ case 'R': sp = &hf->right_format; break;
+ default: g_assert_not_reached ();
+ }
+ g_free (*sp);
+ *sp = g_string_free (accum, FALSE);
+
+ if (txt[0] == 0)
+ break;
+
+ accum = g_string_new (NULL);
+ section = txt[1];
+ txt += 2;
+ continue;
+ }
+
+ if (txt[0] != '&') {
+ g_string_append_c (accum, *txt++);
+ continue;
+ }
+
+ txt++;
+ switch (txt[0]) {
+ case 0:
+ continue;
+ case '&':
+ g_string_append_c (accum, *txt);
+ break;
+ case 'A':
+ g_string_append (accum, "&[TAB]");
+ break;
+ case 'P':
+ g_string_append (accum, "&[PAGE]");
+ break;
+ case 'N':
+ g_string_append (accum, "&[PAGES]");
+ break;
+ case 'D':
+ g_string_append (accum, "&[DATE]");
+ break;
+ case 'T':
+ g_string_append (accum, "&[TIME]");
+ break;
+ case 'F':
+ g_string_append (accum, "&[FILE]");
+ break;
+ case 'Z':
+ g_string_append (accum, "&[PATH]");
+ break;
+ default:
+ break;
+ }
+ txt++;
+ }
+}
+
+static void
+xlsx_CT_oddheader_end (GsfXMLIn *xin, G_GNUC_UNUSED GsfXMLBlob *blob)
+{
+ XLSXReadState *state = (XLSXReadState *)xin->user_state;
+ PrintInformation *pi = state->sheet->print_info;
+ xlsx_CT_header_footer (state, pi->header, xin->content->str);
+}
+
+static void
+xlsx_CT_oddfooter_end (GsfXMLIn *xin, G_GNUC_UNUSED GsfXMLBlob *blob)
+{
+ XLSXReadState *state = (XLSXReadState *)xin->user_state;
+ PrintInformation *pi = state->sheet->print_info;
+ xlsx_CT_header_footer (state, pi->footer, xin->content->str);
+}
+
static void
xlsx_CT_PageBreak (GsfXMLIn *xin, xmlChar const **attrs)
{
@@ -3108,8 +3197,8 @@ GSF_XML_IN_NODE (CELL, EXTLST, XL_NS_SS, "extLst", GSF_XML_NO_CONTENT, NULL, NUL
GSF_XML_IN_NODE (SHEET, PRINT_MARGINS, XL_NS_SS, "pageMargins", GSF_XML_NO_CONTENT, &xlsx_CT_PageMargins,
NULL),
GSF_XML_IN_NODE (SHEET, PRINT_SETUP, XL_NS_SS, "pageSetup", GSF_XML_NO_CONTENT, &xlsx_CT_PageSetup, NULL),
GSF_XML_IN_NODE (SHEET, PRINT_HEADER_FOOTER, XL_NS_SS, "headerFooter", GSF_XML_NO_CONTENT, NULL, NULL),
- GSF_XML_IN_NODE (PRINT_HEADER_FOOTER, ODD_HEADER, XL_NS_SS, "oddHeader", GSF_XML_NO_CONTENT, NULL, NULL),
- GSF_XML_IN_NODE (PRINT_HEADER_FOOTER, ODD_FOOTER, XL_NS_SS, "oddFooter", GSF_XML_NO_CONTENT, NULL, NULL),
+ GSF_XML_IN_NODE (PRINT_HEADER_FOOTER, ODD_HEADER, XL_NS_SS, "oddHeader", GSF_XML_CONTENT, NULL,
&xlsx_CT_oddheader_end),
+ GSF_XML_IN_NODE (PRINT_HEADER_FOOTER, ODD_FOOTER, XL_NS_SS, "oddFooter", GSF_XML_CONTENT, NULL,
&xlsx_CT_oddfooter_end),
GSF_XML_IN_NODE_FULL (SHEET, ROW_BREAKS, XL_NS_SS, "rowBreaks", GSF_XML_NO_CONTENT,
FALSE, FALSE, &xlsx_CT_PageBreaks_begin, &xlsx_CT_PageBreaks_end, 1),
diff --git a/plugins/excel/xlsx-write.c b/plugins/excel/xlsx-write.c
index 439f390..8a6e9d0 100644
--- a/plugins/excel/xlsx-write.c
+++ b/plugins/excel/xlsx-write.c
@@ -1976,16 +1976,16 @@ xlsx_write_print_info_hf1 (GString *res, const char *s, const char *section)
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"},
+ { 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"), "" /* ??? */}
+ { N_("CELL"), "" /* ??? */},
+ { N_("TITLE"), "" /* ??? */}
#endif
};
diff --git a/src/print-info.c b/src/print-info.c
index 6d05876..087b9e1 100644
--- a/src/print-info.c
+++ b/src/print-info.c
@@ -667,15 +667,15 @@ static struct {
void (*render)(GString *target, HFRenderInfo *info, char const *args);
char *name_trans;
} render_ops [] = {
- { N_("tab"), render_tab , NULL},
- { N_("page"), render_page , NULL},
- { N_("pages"), render_pages , NULL},
- { N_("date"), render_date , NULL},
- { N_("time"), render_time , NULL},
- { N_("file"), render_file , NULL},
- { N_("path"), render_path , NULL},
- { N_("cell"), render_cell , NULL},
- { N_("title"), render_title , NULL},
+ { N_("TAB"), render_tab , NULL},
+ { N_("PAGE"), render_page , NULL},
+ { N_("PAGES"), render_pages , NULL},
+ { N_("DATE"), render_date , NULL},
+ { N_("TIME"), render_time , NULL},
+ { N_("FILE"), render_file , NULL},
+ { N_("PATH"), render_path , NULL},
+ { N_("CELL"), render_cell , NULL},
+ { N_("TITLE"), render_title , NULL},
{ NULL , NULL, NULL},
};
/*
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]