Access the “Locale” for Google Sheets

2019-07-21 11:04发布

问题:

How can I access the "Locale" set in File > Spreadsheet Settings > Locale?

Session.getActiveUserLocale() does not match the value chosen in File > Spreadsheet Settings > Locale.

- Extra Info -

Reproduce: In Spreadsheet Settings, you can choose "Italy" for your Locale. Session.getActiveUserLocale() will return "en" instead of "it".

My use case: I am trying to know when a function should be written with ";" or "," separating its parameters. Google Sheets switches to ";" or "," automatically when File > Spreadsheet Settings > Locale is changed. So I want to know what property it is watching to make this change.

回答1:

I think the Session method will get the locale associated with the Google Apps Script. To get the locale of the spreadsheet itself, use the Spreadsheet getSpreadsheetLocale() method.