Excel.CultureInfo class

Provides information based on current system culture settings. This includes the culture names, number formatting, and other culturally dependent settings.

Extends

Remarks

[ API set: ExcelApi 1.11 ]

Properties

context

The request context associated with the object. This connects the add-in's process to the Office host application's process.

datetimeFormat

Defines the culturally appropriate format of displaying date and time. This is based on current system culture settings.

name

Gets the culture name in the format languagecode2-country/regioncode2 (e.g., "zh-cn" or "en-us"). This is based on current system settings.

numberFormat

Defines the culturally appropriate format of displaying numbers. This is based on current system culture settings.

Methods

load(options)

Queues up a command to load the specified properties of the object. You must call context.sync() before reading the properties.

load(propertyNames)

Queues up a command to load the specified properties of the object. You must call context.sync() before reading the properties.

load(propertyNamesAndPaths)

Queues up a command to load the specified properties of the object. You must call context.sync() before reading the properties.

toJSON()

Overrides the JavaScript toJSON() method in order to provide more useful output when an API object is passed to JSON.stringify(). (JSON.stringify, in turn, calls the toJSON method of the object that is passed to it.) Whereas the original Excel.CultureInfo object is an API object, the toJSON method returns a plain JavaScript object (typed as Excel.Interfaces.CultureInfoData) that contains shallow copies of any loaded child properties from the original object.

Property Details

context

The request context associated with the object. This connects the add-in's process to the Office host application's process.

context: RequestContext;

Property Value

datetimeFormat

Defines the culturally appropriate format of displaying date and time. This is based on current system culture settings.

readonly datetimeFormat: Excel.DatetimeFormatInfo;

Property Value

Remarks

[ API set: ExcelApi 1.12 ]

Examples

// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/excel/50-workbook/culture-info-date-time.yaml

await Excel.run(async (context) => {
  context.application.cultureInfo.datetimeFormat.load([
    "longDatePattern",
    "shortDatePattern",
    "dateSeparator",
    "longTimePattern",
    "timeSeparator"
  ]);
  await context.sync();

  // Use the cultural settings API to retrieve the user's system date and time settings.
  const systemLongDatePattern = context.application.cultureInfo.datetimeFormat.longDatePattern;
  const systemShortDatePattern = context.application.cultureInfo.datetimeFormat.shortDatePattern;
  const systemDateSeparator = context.application.cultureInfo.datetimeFormat.dateSeparator;
  const systemLongTimePattern = context.application.cultureInfo.datetimeFormat.longTimePattern;
  const systemTimeSeparator = context.application.cultureInfo.datetimeFormat.timeSeparator;

  // Write the date and time settings in your table. 
  const sheet = context.workbook.worksheets.getActiveWorksheet();
  const dateTimeData = sheet.getRange("A2:B6");
  dateTimeData.values = [
    ["Long date", systemLongDatePattern], 
    ["Short date", systemShortDatePattern], 
    ["Date separator", systemDateSeparator], 
    ["Long time format", systemLongTimePattern],
    ["Time separator", systemTimeSeparator]
  ];

  sheet.tables
    .getItemAt(0)
    .getRange()
    .format.autofitColumns();

  await context.sync();
});

name

Gets the culture name in the format languagecode2-country/regioncode2 (e.g., "zh-cn" or "en-us"). This is based on current system settings.

readonly name: string;

Property Value

string

Remarks

[ API set: ExcelApi 1.11 ]

numberFormat

Defines the culturally appropriate format of displaying numbers. This is based on current system culture settings.

readonly numberFormat: Excel.NumberFormatInfo;

Property Value

Remarks

[ API set: ExcelApi 1.11 ]

Method Details

load(options)

Queues up a command to load the specified properties of the object. You must call context.sync() before reading the properties.

load(options?: Excel.Interfaces.CultureInfoLoadOptions): Excel.CultureInfo;

Parameters

options
Excel.Interfaces.CultureInfoLoadOptions

Provides options for which properties of the object to load.

Returns

load(propertyNames)

Queues up a command to load the specified properties of the object. You must call context.sync() before reading the properties.

load(propertyNames?: string | string[]): Excel.CultureInfo;

Parameters

propertyNames

string | string[]

A comma-delimited string or an array of strings that specify the properties to load.

Returns

load(propertyNamesAndPaths)

Queues up a command to load the specified properties of the object. You must call context.sync() before reading the properties.

load(propertyNamesAndPaths?: {
            select?: string;
            expand?: string;
        }): Excel.CultureInfo;

Parameters

propertyNamesAndPaths

{ select?: string; expand?: string; }

propertyNamesAndPaths.select is a comma-delimited string that specifies the properties to load, and propertyNamesAndPaths.expand is a comma-delimited string that specifies the navigation properties to load.

Returns

toJSON()

Overrides the JavaScript toJSON() method in order to provide more useful output when an API object is passed to JSON.stringify(). (JSON.stringify, in turn, calls the toJSON method of the object that is passed to it.) Whereas the original Excel.CultureInfo object is an API object, the toJSON method returns a plain JavaScript object (typed as Excel.Interfaces.CultureInfoData) that contains shallow copies of any loaded child properties from the original object.

toJSON(): Excel.Interfaces.CultureInfoData;

Returns