Office.ContextInformation interface
提供有关运行加载项的环境的信息。
属性详细信息
host
获取运行加载项的 Office 应用程序。
host: Office.HostType;
属性值
示例
const contextInfo = Office.context.diagnostics;
console.log("Office application: " + contextInfo.host);
platform
获取运行加载项的平台。
platform: Office.PlatformType;
属性值
注解
重要提示:在 Outlook 中,OfficeOnline如果加载项在 Outlook 网页版 或 Windows 上的新 Outlook 中运行,则返回 。
示例
const contextInfo = Office.context.diagnostics;
console.log("Platform: " + contextInfo.platform);
version
获取运行加载项的 Office 版本。
version: string;
属性值
string
注解
在 Windows 上的 Office 中,属性返回version的值使用格式 16.0。<build>。<revision>。 若要将显示为 Version xxxx (Build xxxxx.xxxxx) 的版本与version值进行比较,请使用生成 (< 的完整内部>版本号。<revision>) 。 例如,在版本 2603 (内部版本 19822.20000) 中,使用 19822.20000 进行比较。
示例
// Checks whether the Office on Windows version meets a feature's minimum requirements.
const clientVersion = Office.context.diagnostics.version;
// In Office on Windows, the version property is in the format "16.0.<build>.<revision>".
// In this example, Version 2603 (Build 19822.20000) is the minimum version required for the feature.
// 19822 is the build number and 20000 is the revision number.
const minBuildRevision = "19822.20000";
const [, , clientBuild, clientRevision] = clientVersion.split(".");
const [minBuild, minRevision] = minBuildRevision.split(".");
const clientBuildNumber = parseInt(clientBuild, 10);
const clientRevisionNumber = parseInt(clientRevision, 10);
const minBuildNumber = parseInt(minBuild, 10);
const minRevisionNumber = parseInt(minRevision, 10);
if (
clientBuildNumber > minBuildNumber ||
(clientBuildNumber === minBuildNumber && clientRevisionNumber >= minRevisionNumber)
) {
console.log("Office version meets the minimum requirements.");
// Implement the feature-specific actions here.
} else {
console.log("Office version doesn't meet the minimum requirements.");
}