[gnumeric] Improve date & time export to ODF.
- From: Andreas J. Guelzow <guelzow src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnumeric] Improve date & time export to ODF.
- Date: Thu, 29 Apr 2010 21:39:29 +0000 (UTC)
commit 0eb5ae17f189d3a4f53e8607cd59ddd7099cc9d7
Author: Andreas J. Guelzow <aguelzow pyrshep ca>
Date: Thu Apr 29 15:39:02 2010 -0600
Improve date & time export to ODF.
2010-04-29 Andreas J. Guelzow <aguelzow pyrshep ca>
* openoffice-write.c (odf_write_cell): write times and dates as
time-value or date-value
(openoffice_file_save_real): initialize and dispose of time_fmt
and date_fmt
NEWS | 1 +
plugins/openoffice/ChangeLog | 7 +++++
plugins/openoffice/openoffice-write.c | 43 +++++++++++++++++++++++++-------
3 files changed, 41 insertions(+), 10 deletions(-)
---
diff --git a/NEWS b/NEWS
index 71c4e7e..b3e6251 100644
--- a/NEWS
+++ b/NEWS
@@ -4,6 +4,7 @@ Andreas:
* Fix CHITEST for rectangular ranges. [#615920]
* Fix printing and preview of graph only sheets. [#616475]
* Make even active sheets invisible. [#616474]
+ * Improve date & time export to ODF.
Jean:
* Implement graph only sheets. [#158170]
diff --git a/plugins/openoffice/ChangeLog b/plugins/openoffice/ChangeLog
index c6a5825..581db4c 100644
--- a/plugins/openoffice/ChangeLog
+++ b/plugins/openoffice/ChangeLog
@@ -1,3 +1,10 @@
+2010-04-29 Andreas J. Guelzow <aguelzow pyrshep ca>
+
+ * openoffice-write.c (odf_write_cell): write times and dates as
+ time-value or date-value
+ (openoffice_file_save_real): initialize and dispose of time_fmt
+ and date_fmt
+
2010-04-16 Morten Welinder <terra gnome org>
* Release 1.10.2
diff --git a/plugins/openoffice/openoffice-write.c b/plugins/openoffice/openoffice-write.c
index fea02eb..32f138c 100644
--- a/plugins/openoffice/openoffice-write.c
+++ b/plugins/openoffice/openoffice-write.c
@@ -115,6 +115,8 @@ typedef struct {
ColRowInfo const *column_default;
GHashTable *objects;
gboolean with_extension;
+ GOFormat const *time_fmt;
+ GOFormat const *date_fmt;
} GnmOOExport;
typedef struct {
@@ -2394,16 +2396,32 @@ odf_write_cell (GnmOOExport *state, GnmCell *cell, GnmRange const *merge_range,
odf_add_bool (state->xml, OFFICE "boolean-value",
value_get_as_bool (cell->value, NULL));
break;
- case VALUE_FLOAT: {
- GString *str = g_string_new (NULL);
-
- gsf_xml_out_add_cstr_unchecked (state->xml,
- OFFICE "value-type", "float");
- value_get_as_gstring (cell->value, str, state->conv);
- gsf_xml_out_add_cstr (state->xml, OFFICE "value", str->str);
-
- g_string_free (str, TRUE);
- }
+ case VALUE_FLOAT: if (go_format_is_date (gnm_cell_get_format (cell))
+ || go_format_is_time (gnm_cell_get_format (cell)))
+ {
+ char *str;
+ if (value_get_as_float (cell->value) == (float) value_get_as_int (cell->value)) {
+ gsf_xml_out_add_cstr_unchecked (state->xml,
+ OFFICE "value-type", "date");
+ str = format_value (state->date_fmt, cell->value, NULL, -1, workbook_date_conv (state->wb));
+ gsf_xml_out_add_cstr (state->xml, OFFICE "date-value", str);
+ } else {
+ gsf_xml_out_add_cstr_unchecked (state->xml,
+ OFFICE "value-type", "time");
+ str = format_value (state->time_fmt, cell->value, NULL, -1, workbook_date_conv (state->wb));
+ gsf_xml_out_add_cstr (state->xml, OFFICE "time-value", str);
+ }
+ g_free (str);
+ } else {
+ GString *str = g_string_new (NULL);
+
+ gsf_xml_out_add_cstr_unchecked (state->xml,
+ OFFICE "value-type", "float");
+ value_get_as_gstring (cell->value, str, state->conv);
+ gsf_xml_out_add_cstr (state->xml, OFFICE "value", str->str);
+
+ g_string_free (str, TRUE);
+ }
break;
case VALUE_ERROR:
if (NULL == cell->base.texpr) {
@@ -3949,6 +3967,9 @@ openoffice_file_save_real (GOFileSaver const *fs, GOIOContext *ioc,
state.col_styles = NULL;
state.row_styles = NULL;
+ state.time_fmt = go_format_new_from_XL ("yyyy-mm-ddThh:mm:ss");
+ state.date_fmt = go_format_new_from_XL ("yyyy-mm-dd");
+
/* ODF dos not have defaults per table, so we use our first table for defaults only.*/
sheet = workbook_sheet_by_index (state.wb, 0);
@@ -3997,6 +4018,8 @@ openoffice_file_save_real (GOFileSaver const *fs, GOIOContext *ioc,
g_slist_free (state.col_styles);
g_slist_free (state.row_styles);
gnm_style_unref (state.default_style);
+ go_format_unref (state.time_fmt);
+ go_format_unref (state.date_fmt);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]