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 网页版或新的 Outlook on Windows 中运行,则返回。
示例
const contextInfo = Office.context.diagnostics;
console.log("Platform: " + contextInfo.platform);
version
获取运行加载项的 Office 版本。
version: string;
属性值
string
注解
在 Windows 版 Office 中,属性返回的version值使用 16.0 格式。<生成。<>修订>。 若要将显示为版本 xxxx (内部版本 xxxxx.xxxxx) 的版本与值version进行比较,请使用完整的内部版本号 (< 内部版本>号。<修订>) 。 例如,在版本 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.");
}