我正在创建一个办公室插件,可以在Excel和Word应用程序中使用,并根据所在的宿主(Word或Excel)执行不同的逻辑。我正在使用office.js来创建Office插件。
例如:
let say type="Excel" // after some logic executed
if(type=="Excel")
{
//run code for excel applications
}
else
{
//run code for word applications
}
我尝试使用以下方法:-
if (Office.context.requirements.isSetSupported('ExcelApi', '1.1')) {
alert("yes it is excel");
}
但是当我在Excel中运行它时,它无法正常工作。
我已经在清单文件中发送了主机信息。
<Hosts>
<Host Name="Document" />
<Host Name="Workbook" />
</Hosts>
我在进行大量搜索后发现以下代码,但它对我没有起作用。
function getHostInfo() {
var _requirements = Office.context.requirements;
var types = ['Excel', 'Word'];
var minVersions = ['1.1', '1.0']; // Start with the highest version
// Loop through types and minVersions
for (var type in types) {
for (var minVersion in minVersions) {
// Append "Api" to the type for set name, i.e. "ExcelApi" or "WordApi"
if (_requirements.isSetSupported(types[type] + 'Api', minVersions[minVersion])) {
return {
type: types[type],
apiVersion: minVersions[minVersion]
}
}
}
}
};
谢谢你。
感谢您
<SourceLocation DefaultValue="http://localhost:12345/" /> </DefaultSettings> 这实际上是一个 MVC 应用程序的地址,其中包含所有逻辑,并且我正在将此 MVC 应用程序托管在插件中。该 MVC 应用程序正在使用 office.js,而且一切正常。但是,在需要确定主机的情况下,它却无法正常工作。今天,我创建了一个 Word 插件作为演示,并替换了演示插件清单中的上述代码,但条件仍然为 false :( - Pradeep Gaba