[gnumeric] xlsx: fix reading/writing of number format 14.
- From: Morten Welinder <mortenw src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnumeric] xlsx: fix reading/writing of number format 14.
- Date: Sun, 22 May 2022 15:38:59 +0000 (UTC)
commit 952d524670f96a28cc80828375a9db8ffc7c1998
Author: Morten Welinder <terra gnome org>
Date: Sun May 22 11:37:56 2022 -0400
xlsx: fix reading/writing of number format 14.
It's locale dependent, despite what the spec says. That's a dumb idea,
but it is not our dumb idea.
NEWS | 1 +
plugins/excel/ChangeLog | 5 +++++
plugins/excel/xlsx-read.c | 15 +++++++++++----
plugins/excel/xlsx-write.c | 10 +++++++++-
4 files changed, 26 insertions(+), 5 deletions(-)
---
diff --git a/NEWS b/NEWS
index 86b4c3b48..d02529067 100644
--- a/NEWS
+++ b/NEWS
@@ -3,6 +3,7 @@ Gnumeric 1.12.53
Morten:
* Fix xlsx import of T.INV.
* Fix inter-process array paste problem. [#634]
+ * Fix problem with xlsx number format 14.
--------------------------------------------------------------------------
Gnumeric 1.12.52
diff --git a/plugins/excel/ChangeLog b/plugins/excel/ChangeLog
index b1dea31be..e16f68aa2 100644
--- a/plugins/excel/ChangeLog
+++ b/plugins/excel/ChangeLog
@@ -1,3 +1,8 @@
+2022-05-22 Morten Welinder <terra gnome org>
+
+ * xlsx-read.c (xlsx_get_num_fmt): Format 14 is locale dependent.
+ * xlsx-write.c (xlsx_load_buildin_num_formats): Ditto.
+
2022-04-18 Morten Welinder <terra gnome org>
* Release 1.12.52
diff --git a/plugins/excel/xlsx-read.c b/plugins/excel/xlsx-read.c
index 439625441..21014a3b9 100644
--- a/plugins/excel/xlsx-read.c
+++ b/plugins/excel/xlsx-read.c
@@ -1059,7 +1059,7 @@ xlsx_get_num_fmt (GsfXMLIn *xin, char const *id)
/* 11 */ "0.00E+00",
/* 12 */ "# ?/?",
/* 13 */ "# ?""?/?""?", /* silly trick to avoid using a trigraph */
- /* 14 */ "mm-dd-yy",
+ /* 14 */ NULL, // Locale version of "mm-dd-yy"
/* 15 */ "d-mmm-yy",
/* 16 */ "d-mmm",
/* 17 */ "mmm-yy",
@@ -1172,13 +1172,20 @@ xlsx_get_num_fmt (GsfXMLIn *xin, char const *id)
/* builtins */
i = strtol (id, &end, 10);
- if (end != id && *end == '\0' &&
- i >= 0 && i < (int) G_N_ELEMENTS (std_builtins) &&
- std_builtins[i] != NULL) {
+ if (end == id || *end != 0 || i < 0 || i >= (int) G_N_ELEMENTS (std_builtins))
+ i = -1;
+
+ if (i >= 0 && std_builtins[i] != NULL) {
res = go_format_new_from_XL (std_builtins[i]);
g_hash_table_replace (state->num_fmts, g_strdup (id), res);
+ } else if (i == 14) {
+ // Format 14 is locale dependent. ms-excel-read.c suggests that maybe
+ // 15 should be too, but I cannot verify that anywhere.
+ res = go_format_new_magic (GO_FORMAT_MAGIC_SHORT_DATE);
+ g_hash_table_replace (state->num_fmts, g_strdup (id), res);
} else
xlsx_warning (xin, _("Undefined number format id '%s'"), id);
+
return res;
}
diff --git a/plugins/excel/xlsx-write.c b/plugins/excel/xlsx-write.c
index 351793a45..d1b9d6b9d 100644
--- a/plugins/excel/xlsx-write.c
+++ b/plugins/excel/xlsx-write.c
@@ -548,7 +548,7 @@ xlsx_load_buildin_num_formats (GHashTable *hash)
/* 11 */ "0.00E+00",
/* 12 */ "# ?/?",
/* 13 */ "# ?""?/?""?", /* silly trick to avoid using a trigraph */
- /* 14 */ "mm-dd-yy",
+ /* 14 */ NULL, // Locale version of "mm-dd-yy"
/* 15 */ "d-mmm-yy",
/* 16 */ "d-mmm",
/* 17 */ "mmm-yy",
@@ -586,12 +586,20 @@ xlsx_load_buildin_num_formats (GHashTable *hash)
/* 49 */ "@"
};
unsigned int i;
+ GOFormat const *fmt;
g_return_if_fail (NUM_FORMAT_BASE > (int) G_N_ELEMENTS (std_builtins));
for (i = 1; i < G_N_ELEMENTS (std_builtins); i++)
if (std_builtins[i] != NULL)
g_hash_table_insert (hash, g_strdup (std_builtins[i]), GUINT_TO_POINTER (i));
+
+ // Format 14 is locale dependent. ms-excel-read.c suggests that maybe
+ // 15 should be too, but I cannot verify that anywhere.
+ fmt = go_format_new_magic (GO_FORMAT_MAGIC_SHORT_DATE);
+ g_hash_table_insert (hash, g_strdup (go_format_as_XL (fmt)),
+ GUINT_TO_POINTER (14));
+ go_format_unref (fmt);
}
static void
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]