[gnumeric] Fix date import from ODF
- From: Andreas J. Guelzow <guelzow src gnome org>
- To: svn-commits-list gnome org
- Subject: [gnumeric] Fix date import from ODF
- Date: Mon, 1 Jun 2009 01:12:50 -0400 (EDT)
commit 5129d9bc061ed50ab7a2261503bd4fb8e1811dbf
Author: Andreas J. Guelzow <aguelzow pyrshep ca>
Date: Sun May 31 23:11:28 2009 -0600
Fix date import from ODF
2009-06-01 Andreas J. Guelzow <aguelzow pyrshep ca>
* openoffice-write.c (odf_print_spreadsheet_content_prelude):
give the correct null-date
* openoffice-read.c (oo_date_text_end): we need to use
apostrophes
(oo_date_style): handle magic formats
---
NEWS | 1 +
plugins/openoffice/ChangeLog | 8 ++++++
plugins/openoffice/openoffice-read.c | 39 ++++++++++++++++++++++++++------
plugins/openoffice/openoffice-write.c | 7 ++++-
4 files changed, 45 insertions(+), 10 deletions(-)
diff --git a/NEWS b/NEWS
index 45856c7..c29394d 100644
--- a/NEWS
+++ b/NEWS
@@ -5,6 +5,7 @@ Andreas:
* Fix comment export to ODF
* Remove distinction between label and filled rectangle
* Add superscipt and subscript buttons [#583327]
+ * Improve ODF import.
Morten:
* Add search-for-number.
diff --git a/plugins/openoffice/ChangeLog b/plugins/openoffice/ChangeLog
index 30572ed..9ae63e2 100644
--- a/plugins/openoffice/ChangeLog
+++ b/plugins/openoffice/ChangeLog
@@ -1,3 +1,11 @@
+2009-06-01 Andreas J. Guelzow <aguelzow pyrshep ca>
+
+ * openoffice-write.c (odf_print_spreadsheet_content_prelude):
+ give the correct null-date
+ * openoffice-read.c (oo_date_text_end): we need to use
+ apostrophes
+ (oo_date_style): handle magic formats
+
2009-05-30 Andreas J. Guelzow <aguelzow pyrshep ca>
* openoffice-write.c (xl_find_format): handle all three possible
diff --git a/plugins/openoffice/openoffice-read.c b/plugins/openoffice/openoffice-read.c
index 5f26587..3cd9d29 100644
--- a/plugins/openoffice/openoffice-read.c
+++ b/plugins/openoffice/openoffice-read.c
@@ -225,6 +225,7 @@ typedef struct {
int richtext_len;
GString *accum_fmt;
char *fmt_name;
+ int fmt_magic;
GnmFilter *filter;
GnmConventions *convs[NUM_FORMULAE_SUPPORTED];
@@ -1555,8 +1556,18 @@ oo_date_text_end (GsfXMLIn *xin, G_GNUC_UNUSED GsfXMLBlob *blob)
if (state->accum_fmt == NULL)
return;
-
- g_string_append (state->accum_fmt, xin->content->str);
+
+ if (xin->content->len == 1 &&
+ (*xin->content->str == ' ' ||
+ *xin->content->str == '/' ||
+ *xin->content->str == '-' ||
+ *xin->content->str == ',' ))
+ g_string_append (state->accum_fmt, xin->content->str);
+ else if (xin->content->len >0) {
+ g_string_append_c (state->accum_fmt, '"');
+ g_string_append (state->accum_fmt, xin->content->str);
+ g_string_append_c (state->accum_fmt, '"');
+ }
}
static void
@@ -1564,6 +1575,7 @@ oo_date_style (GsfXMLIn *xin, xmlChar const **attrs)
{
OOParseState *state = (OOParseState *)xin->user_state;
char const *name = NULL;
+ int magic = GO_FORMAT_MAGIC_NONE;
for (; attrs != NULL && attrs[0] && attrs[1] ; attrs += 2)
if (gsf_xml_in_namecmp (xin, CXML2C (attrs[0]), OO_NS_STYLE, "name"))
@@ -1571,11 +1583,15 @@ oo_date_style (GsfXMLIn *xin, xmlChar const **attrs)
else if (gsf_xml_in_namecmp (xin, CXML2C (attrs[0]), OO_NS_STYLE, "family") &&
!attr_eq (attrs[1], "data-style"))
return;
+ else if (gsf_xml_in_namecmp (xin, CXML2C (attrs[0]), OO_GNUM_NS_EXT,
+ "format-magic"))
+ magic = atoi (attrs[1]);
g_return_if_fail (state->accum_fmt == NULL);
g_return_if_fail (name != NULL);
- state->accum_fmt = g_string_new (NULL);
+ state->fmt_magic = magic;
+ state->accum_fmt = (magic == GO_FORMAT_MAGIC_NONE) ? g_string_new (NULL) : NULL;
state->fmt_name = g_strdup (name);
}
@@ -1583,11 +1599,18 @@ static void
oo_date_style_end (GsfXMLIn *xin, G_GNUC_UNUSED GsfXMLBlob *blob)
{
OOParseState *state = (OOParseState *)xin->user_state;
- g_return_if_fail (state->accum_fmt != NULL);
-
- g_hash_table_insert (state->formats, state->fmt_name,
- go_format_new_from_XL (state->accum_fmt->str));
- g_string_free (state->accum_fmt, TRUE);
+
+ if (state->fmt_magic != GO_FORMAT_MAGIC_NONE)
+ g_hash_table_insert (state->formats, state->fmt_name,
+ go_format_new_magic (state->fmt_magic));
+ else {
+ g_return_if_fail (state->accum_fmt != NULL);
+
+ g_hash_table_insert (state->formats, state->fmt_name,
+ go_format_new_from_XL (state->accum_fmt->str));
+ g_print ("oo_date_style_end %s\n", state->accum_fmt->str);
+ g_string_free (state->accum_fmt, TRUE);
+ }
state->accum_fmt = NULL;
state->fmt_name = NULL;
}
diff --git a/plugins/openoffice/openoffice-write.c b/plugins/openoffice/openoffice-write.c
index f39bb78..f66d5ed 100644
--- a/plugins/openoffice/openoffice-write.c
+++ b/plugins/openoffice/openoffice-write.c
@@ -1916,8 +1916,11 @@ odf_print_spreadsheet_content_prelude (GnmOOExport *state)
if (get_gsf_odf_version () > 101)
odf_add_bool (state->xml, TABLE "use-wildcards", FALSE);
gsf_xml_out_start_element (state->xml, TABLE "null-date");
- /* As encouraged by the OpenFormula definition we "compensate" here. */
- gsf_xml_out_add_cstr_unchecked (state->xml, TABLE "date-value", "1899-12-30");
+ if (gnm_date_convention_base (workbook_date_conv (state->wb)) == 1900)
+ /* As encouraged by the OpenFormula definition we "compensate" here. */
+ gsf_xml_out_add_cstr_unchecked (state->xml, TABLE "date-value", "1899-12-30");
+ else
+ gsf_xml_out_add_cstr_unchecked (state->xml, TABLE "date-value", "1904-1-1");
gsf_xml_out_add_cstr_unchecked (state->xml, TABLE "value-type", "date");
gsf_xml_out_end_element (state->xml); /* </table:null-date> */
gsf_xml_out_start_element (state->xml, TABLE "iteration");
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]