Office js office.context.document在文件中未定义

Office js office.context.document在文件中未定义,office-js,Office Js,我无法在angular文件中获取office.context.document。我所做的是单击ribbon按钮,我将重定向到一个html页面,该页面的功能是用angular js编写的。html页面包含一个输入框和一个按钮。单击按钮后,我将调用一个函数have office.context.document.getfileasync,但它是错误的即将到来的office.context.document.getfileasync未定义 (函数(){ "严格使用",; var计数=0; 变量插入\

我无法在angular文件中获取office.context.document。我所做的是单击ribbon按钮,我将重定向到一个html页面,该页面的功能是用angular js编写的。html页面包含一个输入框和一个按钮。单击按钮后,我将调用一个函数have office.context.document.getfileasync,但它是错误的即将到来的office.context.document.getfileasync未定义

(函数(){
"严格使用",;
var计数=0;
变量插入\u类型\u纯文本=“纯文本”;
var插入\类型\富\文本=“富\文本”;
var插入\u类型\u活动\u WIT=“WIT\u内容”;
var var_META_separator=“::”;
角度模块('wpoffice'))
.directive('wittyWordCommandExec',function(){
返回{
限制:'E',
templateUrl:“witty save document from ribbon pop-up.html”,
bindToController:对,
控制器:“WordCommandController”,
controllerAs:'WordCommandCtrl'
};
})
.controller('WordCommandController',WordCommandController);
/**@ngInject*/
函数WordCommandController($scope、$q、ngNotify、$uibModal、witService、$timeout、$http、appData、attachmentService、officeWordService、userProfileService){
log('WordVariableController init');
var vm=这个;
vm.init=init;
vm.createWit=createWit;
$scope.WitName=“”;
日志(Office.context.document);
log($scope.WitName);
var fileurl=displayDocumentUrl();
log(fileurl+“hi”);
如果(文件URL){
var filename=fileurl.substr(fileurl.lastIndexOf('/')+1,fileurl.length);
}
函数createWit()
{
console.log(Office.context);
log($scope.WitName);
log(“已执行测试功能”);
console.log(appData);
userProfileService.getUserProfileData().then(函数(响应){
console.log(response.defaultFolderId);
//log(文件名);
saveDocument(appData、witService、attachmentService、response.defaultFolderId、$q、filename){
log(“保存到witty parrot的文档”);
});
},函数(错误){
console.log(错误);
});
}
函数init()
{
日志(“测试初始化功能”);
}
//以100-KB的文本块获取PowerPoint或Word文档中的所有内容。
函数saveDocument(appData、witService、attachmentService、defaultFolderId、$q、文件名、witname)
{
var deferred=$q.deferred();
appData.isContentLoaded=false;
log(“内部sendfile”);
日志(Office.context.document);
Office.context.document.getFileAsync(“压缩”,
{sliceSize:100000},
功能(结果){
控制台日志(结果);
if(result.status==Office.AsyncResultStatus.successed){
var myFile=result.value;
var sliceCount=myFile.sliceCount;
var slicesReceived=0,gotallsices=true,docdataSlices=[];
log(“文件大小:+myFile.size+”#切片:+sliceCount);
getSliceAsync(myFile、0、sliceCount、gotAllSlices、docdataSlices、slicesReceived、appData、witService、attachmentService、defaultFolderId、$q、filename、witname){
log('insidegetsliceasync');
延迟。解决();
});
}
否则{
延迟。解决();
控制台日志(结果状态);
}
});
回报。承诺;
}

创造智慧
您需要连接事件以访问Office API

有许多角度示例。

您还可以查看,它也是用Office.js+Angular 4构建的,显示了我们使用Office.initialize的模式。