[gnumeric] CELL: Improve "format".
- From: Morten Welinder <mortenw src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnumeric] CELL: Improve "format".
- Date: Sat, 24 Apr 2021 23:18:14 +0000 (UTC)
commit d5964a969d4fca15ecd4d68c51360c5325cfba3c
Author: Morten Welinder <terra gnome org>
Date: Sat Apr 24 19:17:14 2021 -0400
CELL: Improve "format".
Use go_format_get_details to inspect the format.
NEWS | 1 +
plugins/fn-info/ChangeLog | 4 ++++
plugins/fn-info/functions.c | 47 +++++++++++++++++++++++++++++++++++++--------
3 files changed, 44 insertions(+), 8 deletions(-)
---
diff --git a/NEWS b/NEWS
index 3b5b48184..5ee5445fc 100644
--- a/NEWS
+++ b/NEWS
@@ -8,6 +8,7 @@ Morten:
* Export file:// links to xlsx. [#569]
* Improve handling of invalid formulae from xlsx. [#574]
* Introspection fixes.
+ * Improve CELL("format",...) [#576]
--------------------------------------------------------------------------
Gnumeric 1.12.49
diff --git a/plugins/fn-info/ChangeLog b/plugins/fn-info/ChangeLog
index b9f0db06a..5e9f4e856 100644
--- a/plugins/fn-info/ChangeLog
+++ b/plugins/fn-info/ChangeLog
@@ -1,3 +1,7 @@
+2021-04-24 Morten Welinder <terra gnome org>
+
+ * functions.c (translate_cell_format): Improve CELL("format",...)
+
2021-03-14 Morten Welinder <terra gnome org>
* Release 1.12.49
diff --git a/plugins/fn-info/functions.c b/plugins/fn-info/functions.c
index cce38e13c..4b7a78d93 100644
--- a/plugins/fn-info/functions.c
+++ b/plugins/fn-info/functions.c
@@ -103,6 +103,7 @@ typedef struct {
char const *output;
} translate_t;
static const translate_t translate_table[] = {
+#if 0
{ "General", "G" },
{ "0", "F0" },
{ "#,##0", ",0" },
@@ -117,6 +118,7 @@ static const translate_t translate_table[] = {
{ "0.00e+00", "S2" },
{ "# ?/?", "G" },
{ "# ?" "?/?" "?", "G" }, /* Don't accidentally use trigraphs here. */
+#endif
{ "m/d/yy", "D4" },
{ "m/d/yy h:mm", "D4" },
{ "mm/dd/yy", "D4" },
@@ -138,9 +140,11 @@ translate_cell_format (GOFormat const *format)
int i;
const char *fmt;
const int translate_table_count = G_N_ELEMENTS (translate_table);
+ gboolean exact;
+ GOFormatDetails details;
if (format == NULL)
- return value_new_string ("G");
+ goto fallback;
fmt = go_format_as_XL (format);
@@ -155,14 +159,41 @@ translate_cell_format (GOFormat const *format)
}
}
-#warning "FIXME: CELL('format',...) isn't right"
- /*
- * 1. The above lookup should be done with respect to just the
- * first of format alternatives.
- * 2. I don't think colour should count.
- * 3. We should add a dash if there are more alternatives.
- */
+ go_format_get_details (format, &details, &exact);
+ if (0 && !exact) {
+ g_printerr ("Inexact for %s\n", fmt);
+ goto fallback;
+ }
+
+ switch (details.family) {
+ case GO_FORMAT_NUMBER:
+ return value_new_string_nocopy
+ (g_strdup_printf
+ ("%c%d",
+ details.thousands_sep ? ',' : 'F',
+ details.num_decimals));
+ case GO_FORMAT_CURRENCY:
+ case GO_FORMAT_ACCOUNTING:
+ return value_new_string_nocopy
+ (g_strdup_printf
+ ("C%d%s",
+ details.num_decimals,
+ details.negative_red ? "-" : ""));
+ case GO_FORMAT_PERCENTAGE:
+ return value_new_string_nocopy
+ (g_strdup_printf
+ ("P%d",
+ details.num_decimals));
+ case GO_FORMAT_SCIENTIFIC:
+ return value_new_string_nocopy
+ (g_strdup_printf
+ ("S%d",
+ details.num_decimals));
+ default:
+ goto fallback;
+ }
+fallback:
return value_new_string ("G");
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]