上下文 (邮箱预览要求集)

Office.context

Office.context 提供所有 Office 应用中的加载项使用的共享接口。 此列表仅记录 Outlook 加载项使用的那些接口。有关 Office.context 命名空间的完整列表,请参阅 通用 API 中的 Office.context 参考

要求
要求
最低版本的邮箱要求集 1.1
适用的 Outlook 模式 撰写或阅读

属性

属性 模式 返回类型 最小值
要求集
认证 撰写
阅读
Auth IdentityAPI 1.3
contentLanguage 撰写
阅读
String 1.1
诊断 撰写
阅读
ContextInformation 1.5
displayLanguage 撰写
阅读
String 1.1
主机 撰写
阅读
HostType 1.5
mailbox 撰写
阅读
Mailbox 1.1
officeTheme 撰写
阅读
OfficeTheme 预览
平台 撰写
阅读
PlatformType 1.5
要求 撰写
阅读
RequirementSetSupport 1.1
roamingSettings 撰写
阅读
RoamingSettings 1.1
sensitivityLabelsCatalog 撰写 SensitivityLabelsCatalog 1.13
ui 撰写
阅读
UI 1.1
Url 撰写
阅读
Urls 预览

属性详细信息

auth: Auth

通过提供允许 Office 应用程序获取加载项 Web 应用程序的访问令牌的方法,支持 单一登录 (SSO) 。 这也使加载项能够间接访问已登录用户的 Microsoft Graph 数据,而不需要用户第二次登录。

类型
要求
要求
最低版本的邮箱要求集 预览
适用的 Outlook 模式 撰写或阅读
示例
Office.context.auth.getAccessTokenAsync(function(result) {
    if (result.status === "succeeded") {
        const token = result.value;
        // ...
    } else {
        console.log("Error obtaining token", result.error);
    }
});



contentLanguage:String

获取用户指定用于编辑项的区域设置 (语言) 。

该值contentLanguage反映 Office 客户端应用程序中使用文件>选项>语言指定的当前编辑语言设置。

类型
  • String
要求
要求
最低版本的邮箱要求集 1.1
适用的 Outlook 模式 撰写或阅读
示例
function sayHelloWithContentLanguage() {
  const myContentLanguage = Office.context.contentLanguage;
  switch (myContentLanguage) {
    case 'en-US':
      write('Hello!');
      break;
    case 'en-NZ':
      write('G\'day mate!');
      break;
  }
}

// Function that writes to a div with id='message' on the page.
function write(message){
  document.getElementById('message').innerText += message;
}



诊断:ContextInformation

获取有关运行加载项的环境的信息。

注意

对于所有邮箱要求集,还可以使用 Office.context.mailbox.诊断 属性获取类似信息。

类型
要求
要求
最低版本的邮箱要求集 1.5
适用的 Outlook 模式 撰写或阅读
示例
const contextInfo = Office.context.diagnostics;
console.log("Office application: " + contextInfo.host);
console.log("Office version: " + contextInfo.version);
console.log("Platform: " + contextInfo.platform);



displayLanguage:String

获取用户为 Office 客户端应用程序的 UI 指定的区域设置 (语言) RFC 1766 Language 标记格式。

该值displayLanguage反映 Office 客户端应用程序中的“文件选项语言”>>指定的当前“显示语言”设置。

类型
  • String
要求
要求
最低版本的邮箱要求集 1.1
适用的 Outlook 模式 撰写或阅读
示例
function sayHelloWithDisplayLanguage() {
  const myDisplayLanguage = Office.context.displayLanguage;
  switch (myDisplayLanguage) {
    case 'en-US':
      write('Hello!');
      break;
    case 'en-NZ':
      write('G\'day mate!');
      break;
  }
}

// Function that writes to a div with id='message' on the page.
function write(message){
  document.getElementById('message').innerText += message;
}



host: HostType

获取承载加载项的 Office 应用程序。

注意

或者,可以使用 Office.context.诊断 属性获取主机。 对于所有邮箱要求集,还可以使用 Office.context.mailbox.诊断 属性获取类似信息。

类型
要求
要求
最低版本的邮箱要求集 1.5
适用的 Outlook 模式 撰写或阅读
示例
console.log(JSON.stringify(Office.context.host));



officeTheme: OfficeTheme

提供了访问 Office 主题颜色的属性。

注意

此成员仅在 Outlook on Windows 中受支持。

使用 Office 主题颜色,可以使用 文件 > Office 帐户 > Office 主题 UI(应用于所有 Office 客户端应用程序)的用户选择的当前 Office 主题来协调加载项的配色方案。 使用 Office 主题颜色适用于邮件和任务窗格外接程序。

类型
属性
名称 类型 说明
bodyBackgroundColor String 获取十六进制三原色形式的 Office 主题正文背景色。
bodyForegroundColor String 获取十六进制三原色形式的 Office 主题正文前景色。
controlBackgroundColor 字符串 获取十六进制三原色形式的 Office 主题控制背景色。
controlForegroundColor 字符串 获取十六进制三原色形式的 Office 主题正文控制颜色。
要求
要求
最低版本的邮箱要求集 预览
适用的 Outlook 模式 撰写或阅读
示例
function applyOfficeTheme(){
  // Get office theme colors.
  const bodyBackgroundColor = Office.context.officeTheme.bodyBackgroundColor;
  const bodyForegroundColor = Office.context.officeTheme.bodyForegroundColor;
  const controlBackgroundColor = Office.context.officeTheme.controlBackgroundColor
  const controlForegroundColor = Office.context.officeTheme.controlForegroundColor;

  // Apply body background color to a CSS class.
  $('.body').css('background-color', bodyBackgroundColor);
}



平台: PlatformType

提供运行加载项的平台。

注意

或者,可以使用 Office.context.诊断 属性获取平台。 对于所有邮箱要求集,还可以使用 Office.context.mailbox.诊断 属性获取类似信息。

类型
要求
要求
最低版本的邮箱要求集 1.5
适用的 Outlook 模式 撰写或阅读
示例
console.log(JSON.stringify(Office.context.platform));



要求: RequirementSetSupport

提供用于确定当前应用程序和平台支持哪些要求集的方法。

类型
要求
要求
最低版本的邮箱要求集 1.1
适用的 Outlook 模式 撰写或阅读
示例
console.log(JSON.stringify(Office.context.requirements.isSetSupported("mailbox", "1.1")));



roamingSettings: RoamingSettings

获取一个对象,它表示保存到用户邮箱的邮件外接程序的自定义设置或状态。

对象 RoamingSettings 允许您存储和访问存储在用户邮箱中的邮件加载项的数据,以便从用于访问该邮箱的任何 Outlook 客户端运行时,该加载项可用于该加载项。

类型
Requirements
要求
最低版本的邮箱要求集 1.1
最低权限级别 限制
适用的 Outlook 模式 撰写或阅读



sensitivityLabelsCatalog: SensitivityLabelsCatalog

获取要检查 Outlook 中敏感度标签目录的状态的 对象,并在启用目录时检索所有可用的敏感度标签。

类型
要求
要求
最低版本的邮箱要求集 1.13
最低权限级别 读/写项
适用的 Outlook 模式 撰写



ui: UI

提供可用于在 Office 外接程序中创建和操作 UI 组件(如对话框)的对象和方法。

类型
要求
要求
最低版本的邮箱要求集 1.1
适用的 Outlook 模式 撰写或阅读



urls: Urls

获取用于检索外接程序的运行时 URL 的 对象。

类型
要求
要求
最低版本的邮箱要求集 预览
适用的 Outlook 模式 撰写或阅读