我已经使用yo office
创建了一个Microsoft Office加载项React(TypeScript)项目。
我将manifest.xml
更改为包含
<Control xsi:type="Button" id="Contoso.GrabSelectionButton">
<Label resid="Contoso.GrabSelectionButton.Label" />
<Supertip>
<Title resid="Contoso.GrabSelectionButton.Label" />
<Description resid="Contoso.GrabSelectionButton.Tooltip" />
</Supertip>
<Icon>
<bt:Image size="16" resid="Contoso.tpicon_16x16" />
<bt:Image size="32" resid="Contoso.tpicon_32x32" />
<bt:Image size="80" resid="Contoso.tpicon_80x80" />
</Icon>
<Action xsi:type="ExecuteFunction">
<FunctionName>grabSelection</FunctionName>
</Action>
</Control>
<FunctionFile resid="Contoso.DesktopFunctionFile.Url" />
的设置正确-我没有将其更改为默认模板。
我在function-file.ts
中这样添加了方法
(() => {
Office.initialize = () => { console.log("this gets logged..."); };
function grabSelection(event){
console.log("grabSelection invoked! - this does not get logged");
event.completed();
}
})();
我也尝试过这样
(() => {
Office.initialize = () => { console.log("this gets logged..."); };
})();
export function grabSelection(event){
console.log("grabSelection invoked! - this does not get logged");
event.completed();
}
我可以看到它在运行时已编译并包含在内,但该函数未被调用...
为什么不调用该函数? webpack
无法正确导出函数是否存在问题?
答案 0 :(得分:0)
我设法通过将函数附加到全局名称空间来解决此问题:
(() => {
Office.initialize = () => {
console.log("function file loaded...!");
};
})();
function grabSelection(event: any): void {
console.log("i got invoked!!!");
event.completed();
}
const _global = (window /* browser */ || global /* node */) as any;
_global.grabSelection= grabSelection;