Locale support
XLSX.SSF formats numbers and dates for a locale. Use IETF language tags such as de-DE.
Set the locale before you read files, so that the formatted text (w) is produced with it.
const XLSX = require("@agent-sheet/wasm");XLSX.SSF.setlocale("de-DE");console.log(XLSX.SSF.getlocale(), XLSX.SSF.format("dddd d mmmm yyyy", 45000));console.log(XLSX.SSF.format("#,##0", 1234567), XLSX.SSF.format(14, 45000));XLSX.SSF.setlocale("sv-SE");console.log(XLSX.SSF.format("mmmm", 45000), XLSX.SSF.format(14, 45000));XLSX.SSF.setlocale("en-US");de-DE Mittwoch 15 März 20231.234.567 15.3.2023mars 2023-03-15A locale change affects:
- thousands and decimal separators;
- day and month names (
ddd,dddd,mmm,mmmm,mmmmm); - the default date format (code 14);
- the locale-specific formats for
zh-CN,zh-TW,ja-JP,ko-KRandth-TH.
The tables come from the Intl object of the runtime. The setting is global for the JavaScript realm
(the main thread, a worker or a vm context). A worker_threads worker does not inherit the setting of the main thread.
Currency symbol
Section titled “Currency symbol”The currency symbol is independent of the locale. You choose it by ISO 4217 code.
Call setlocale once first. The currency lookup uses the locale tables. On a fresh load, setcurrency alone throws
Incorrect locale information provided.
const XLSX = require("@agent-sheet/wasm");XLSX.SSF.setlocale("en-US");XLSX.SSF.setcurrency("EUR");console.log(XLSX.SSF.getcurrency(), XLSX.SSF.format("$#,##0.00", 5));XLSX.SSF.setcurrency("USD");EUR €5.00Normalize localized format codes
Section titled “Normalize localized format codes”Excel shows format codes in the user’s language but stores them in the US form. SSF.normalize converts a
localized custom format back to the stored form for the current locale.
const XLSX = require("@agent-sheet/wasm");XLSX.SSF.setlocale("de-DE");console.log(XLSX.SSF.normalize("jjjj-mm-tt"), XLSX.SSF.normalize("#.##0,00"));XLSX.SSF.setlocale("en-US");yyyy-mm-dd #,##0.00