Get the locale (regional settings)
This article explains how to get the locale (regional settings) of a specific spreadsheet.
Method to use
Section titled “Method to use”Spreadsheet.getSpreadsheetLocale();Use getSpreadsheetLocale(), which is provided by the Spreadsheet class.
What you get is the locale specified under “Locale” in the spreadsheet’s “File” > “Settings”. This setting affects how dates, numbers, and currencies are formatted, and it’s separate from the display language of the user viewing the spreadsheet.
The return value is a string that joins a language code and a country or region code with an _ (underscore), such as ja_JP (sometimes it’s just a language code). For background on how locale identifiers work, Unicode UTS #35 is also a useful reference.
Because the script accesses the spreadsheet, you may need to authorize it the first time you run it.
Sample code
Section titled “Sample code”/** * ID of the target spreadsheet * The xxx part of https://docs.google.com/spreadsheets/d/xxx/edit */const SPREAD_SHEET_ID = '_______________';
/** * Returns the locale (regional settings) of the spreadsheet */const getSheetLocale = () => { /** Target spreadsheet */ const ss = SpreadsheetApp.openById(SPREAD_SHEET_ID);
/** Locale information */ const locale = ss.getSpreadsheetLocale();
console.log(locale); return locale;};When you run it, the spreadsheet’s locale (regional settings) is returned.
If the locale is set to “Japan”, you get "ja_JP".