Excel.CultureInfo class

提供基于当前系统区域性设置的信息。 这包括区域性名称、数字格式和其他区域性相关设置。

Extends

注解

[ API 集:ExcelApi 1.11 ]

属性

context

与 对象关联的请求上下文。 这会将加载项的进程连接到 Office 主机应用程序的进程。

datetimeFormat

定义显示日期和时间在区域性上合适的格式。 这基于当前的系统区域性设置。

name

获取格式为 languagecode2-country/regioncode2 (的区域性名称,例如“zh-cn”或“en-us”) 。 这基于当前的系统设置。

numberFormat

定义显示数字在区域性上合适的格式。 这基于当前的系统区域性设置。

方法

load(options)

将命令加入队列以加载对象的指定属性。 阅读属性前必须先调用 context.sync()

load(propertyNames)

将命令加入队列以加载对象的指定属性。 阅读属性前必须先调用 context.sync()

load(propertyNamesAndPaths)

将命令加入队列以加载对象的指定属性。 阅读属性前必须先调用 context.sync()

toJSON()

重写 JavaScript toJSON() 方法,以便在将 API 对象传递给 JSON.stringify()时提供更有用的输出。 JSON.stringify (,反过来又调用toJSON传递给它的 对象的 方法。) 而原始 Excel.CultureInfo 对象是 API 对象,toJSON但该方法返回一个纯 JavaScript 对象, (类型为 Excel.Interfaces.CultureInfoData) ,该对象包含原始对象中加载的任何子属性的浅表副本。

属性详细信息

context

与 对象关联的请求上下文。 这会将加载项的进程连接到 Office 主机应用程序的进程。

context: RequestContext;

属性值

datetimeFormat

定义显示日期和时间在区域性上合适的格式。 这基于当前的系统区域性设置。

readonly datetimeFormat: Excel.DatetimeFormatInfo;

属性值

注解

[ API 集:ExcelApi 1.12 ]

示例

// 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

获取格式为 languagecode2-country/regioncode2 (的区域性名称,例如“zh-cn”或“en-us”) 。 这基于当前的系统设置。

readonly name: string;

属性值

string

注解

[ API 集:ExcelApi 1.11 ]

numberFormat

定义显示数字在区域性上合适的格式。 这基于当前的系统区域性设置。

readonly numberFormat: Excel.NumberFormatInfo;

属性值

注解

[ API 集:ExcelApi 1.11 ]

方法详细信息

load(options)

将命令加入队列以加载对象的指定属性。 阅读属性前必须先调用 context.sync()

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

参数

options
Excel.Interfaces.CultureInfoLoadOptions

提供要加载对象的属性的选项。

返回

load(propertyNames)

将命令加入队列以加载对象的指定属性。 阅读属性前必须先调用 context.sync()

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

参数

propertyNames

string | string[]

逗号分隔的字符串或指定要加载的属性的字符串数组。

返回

load(propertyNamesAndPaths)

将命令加入队列以加载对象的指定属性。 阅读属性前必须先调用 context.sync()

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

参数

propertyNamesAndPaths

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

propertyNamesAndPaths.select 是一个逗号分隔的字符串,指定要加载的属性,是 propertyNamesAndPaths.expand 一个逗号分隔的字符串,指定要加载的导航属性。

返回

toJSON()

重写 JavaScript toJSON() 方法,以便在将 API 对象传递给 JSON.stringify()时提供更有用的输出。 JSON.stringify (,反过来又调用toJSON传递给它的 对象的 方法。) 而原始 Excel.CultureInfo 对象是 API 对象,toJSON但该方法返回一个纯 JavaScript 对象, (类型为 Excel.Interfaces.CultureInfoData) ,该对象包含原始对象中加载的任何子属性的浅表副本。

toJSON(): Excel.Interfaces.CultureInfoData;

返回