Excel.CultureInfo class

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

扩展

属性

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;

返回