(core) Currency from grist column is persistent when exporting to excel

Summary:
- when grist table is exported, currency is check and introduced in cell format in the form of "[currency symbol] [value]" (for example: zł 10000, $ 5000) . It's not what some cultures should display currences, but it's close enought
- when no symbol is defined for the currency, currency 3 letters code is used instead
- when currency is unknown, we are falling back to "$"

Test Plan: - nbrowser test scenario added for that purpose, please check Currences.xlsx to see output format exported.

Reviewers: georgegevoian

Reviewed By: georgegevoian

Differential Revision: https://phab.getgrist.com/D3886
This commit is contained in:
Jakub Serafin
2023-05-05 11:34:12 +02:00
parent 8f34ba5157
commit 37347a79c0
5 changed files with 15 additions and 2 deletions

View File

@@ -1,10 +1,11 @@
import {CellValue} from 'app/common/DocActions';
import * as gutil from 'app/common/gutil';
import * as gristTypes from 'app/common/gristTypes';
import * as gutil from 'app/common/gutil';
import {NumberFormatOptions} from 'app/common/NumberFormat';
import {FormatOptions, formatUnknown, IsRightTypeFunc} from 'app/common/ValueFormatter';
import {GristType} from 'app/plugin/GristData';
import {decodeObject} from 'app/plugin/objtypes';
import getSymbolFromCurrency from 'currency-symbol-map';
import {Style} from 'exceljs';
import moment from 'moment-timezone';
@@ -64,7 +65,13 @@ class BaseFormatter {
// those formats strings are the defaults that LibreOffice Calc is using.
if (this.widgetOptions.numMode) {
if (this.widgetOptions.numMode === 'currency') {
style.numFmt = '[$$-409]#,##0.00';
// If currency name is undefined or null, it should be cast to unknown currency, because
// "getSymbolFromCurrency" expect argument to be string
const currencyName = this.widgetOptions.currency??"";
const currencySymbol = getSymbolFromCurrency(currencyName)
?? this.widgetOptions.currency
?? "$";
style.numFmt = `"${currencySymbol} "#,##0.000`;
} else if (this.widgetOptions.numMode === 'percent') {
style.numFmt = '0.00%';
} else if (this.widgetOptions.numMode === 'decimal') {