office.context.document 在 angular 文件中未定义
office.context.document is undefined in angular file
我无法在 angular 中获取 office.context.document file.What 我正在做的是单击功能区按钮 我将重定向到一个 html 页面,其功能是写在 angular js.The html 页面中包含一个输入框和一个 button.Onclick 按钮 我正在调用一个具有 office.context.document.getfileasync 的函数,但错误是即将到来 office.context.document.getfileasync undefined.
(function() {
'use strict';
var count = 0;
var INSERTION_TYPE_PLAIN_TEXT = "PLAIN_TEXT";
var INSERTION_TYPE_RICH_TEXT = "RICH_TEXT";
var INSERTION_TYPE_LIVE_WIT = "WIT_CONTENT";
var VAR_META_SEPERATOR = "::";
angular.module('wpoffice')
.directive('wittyWordCommandExec', function() {
return {
restrict: 'E',
templateUrl: 'witty-save-document-from-ribbon-pop-up.html',
bindToController: true,
controller: 'WordCommandController',
controllerAs: 'WordCommandCtrl'
};
})
.controller('WordCommandController', WordCommandController);
/** @ngInject */
function WordCommandController($scope, $q, ngNotify, $uibModal, witService, $timeout,$http,appData,attachmentService,officeWordService,userProfileService) {
console.log('WordVariableController init');
var vm = this;
vm.init = init;
vm.createWit = createWit;
$scope.WitName = "";
console.log(Office.context.document);
console.log($scope.WitName);
var fileurl = displayDocumentUrl();
console.log(fileurl+"hi");
if(fileurl){
var filename = fileurl.substr(fileurl.lastIndexOf('/')+1,fileurl.length);
}
function createWit()
{
console.log(Office.context);
console.log($scope.WitName);
console.log("test function executed");
console.log(appData);
userProfileService.getUserProfileData().then(function(response){
console.log(response.defaultFolderId);
//console.log(filename);
saveDocument(appData, witService,attachmentService,response.defaultFolderId,$q,filename).then(function(){
console.log("Document saved to witty parrot");
});
},function(error){
console.log(error);
});
}
function init()
{
console.log("test init fucntion");
}
// Get all of the content from a PowerPoint or Word document in 100-KB chunks of text.
function saveDocument(appData, witService,attachmentService,defaultFolderId,$q,filename,witname)
{
var deferred = $q.defer();
appData.isContentLoaded = false;
console.log("inside sendfile");
console.log(Office.context.document);
Office.context.document.getFileAsync("compressed",
{ sliceSize: 100000},
function (result) {
console.log(result);
if (result.status == Office.AsyncResultStatus.Succeeded) {
var myFile = result.value;
var sliceCount = myFile.sliceCount;
var slicesReceived = 0, gotAllSlices = true, docdataSlices = [];
console.log("File size:" + myFile.size + " #Slices: " + sliceCount);
getSliceAsync(myFile, 0, sliceCount, gotAllSlices, docdataSlices, slicesReceived,appData, witService,attachmentService,defaultFolderId,$q,filename,witname).then(function(){
console.log('inside getSliceAsync');
deferred.resolve();
});
}
else {
deferred.resolve();
console.log(result.status);
}
});
return deferred.promise;
}
<div class="flex-rem layout-column pad-box-10" ng-controller="WordCommandController as WordCommandCtrl">
<div class="layout-column flex-rem witty-text-input-container">
<input autofocus type="text" ng-model="WitName" placeholder="Enter wit name" class="flex flex-rem">
</div>
<button ng-click="WordCommandCtrl.createWit()" class="ms-Button ms-Button--primary">
<span class="ms-Button-label">CREATE WIT</span>
</button>
</div>
您需要连接 Office.initialize 事件才能访问 Office API。
有多个 Angular 个样本 here。
我无法在 angular 中获取 office.context.document file.What 我正在做的是单击功能区按钮 我将重定向到一个 html 页面,其功能是写在 angular js.The html 页面中包含一个输入框和一个 button.Onclick 按钮 我正在调用一个具有 office.context.document.getfileasync 的函数,但错误是即将到来 office.context.document.getfileasync undefined.
(function() {
'use strict';
var count = 0;
var INSERTION_TYPE_PLAIN_TEXT = "PLAIN_TEXT";
var INSERTION_TYPE_RICH_TEXT = "RICH_TEXT";
var INSERTION_TYPE_LIVE_WIT = "WIT_CONTENT";
var VAR_META_SEPERATOR = "::";
angular.module('wpoffice')
.directive('wittyWordCommandExec', function() {
return {
restrict: 'E',
templateUrl: 'witty-save-document-from-ribbon-pop-up.html',
bindToController: true,
controller: 'WordCommandController',
controllerAs: 'WordCommandCtrl'
};
})
.controller('WordCommandController', WordCommandController);
/** @ngInject */
function WordCommandController($scope, $q, ngNotify, $uibModal, witService, $timeout,$http,appData,attachmentService,officeWordService,userProfileService) {
console.log('WordVariableController init');
var vm = this;
vm.init = init;
vm.createWit = createWit;
$scope.WitName = "";
console.log(Office.context.document);
console.log($scope.WitName);
var fileurl = displayDocumentUrl();
console.log(fileurl+"hi");
if(fileurl){
var filename = fileurl.substr(fileurl.lastIndexOf('/')+1,fileurl.length);
}
function createWit()
{
console.log(Office.context);
console.log($scope.WitName);
console.log("test function executed");
console.log(appData);
userProfileService.getUserProfileData().then(function(response){
console.log(response.defaultFolderId);
//console.log(filename);
saveDocument(appData, witService,attachmentService,response.defaultFolderId,$q,filename).then(function(){
console.log("Document saved to witty parrot");
});
},function(error){
console.log(error);
});
}
function init()
{
console.log("test init fucntion");
}
// Get all of the content from a PowerPoint or Word document in 100-KB chunks of text.
function saveDocument(appData, witService,attachmentService,defaultFolderId,$q,filename,witname)
{
var deferred = $q.defer();
appData.isContentLoaded = false;
console.log("inside sendfile");
console.log(Office.context.document);
Office.context.document.getFileAsync("compressed",
{ sliceSize: 100000},
function (result) {
console.log(result);
if (result.status == Office.AsyncResultStatus.Succeeded) {
var myFile = result.value;
var sliceCount = myFile.sliceCount;
var slicesReceived = 0, gotAllSlices = true, docdataSlices = [];
console.log("File size:" + myFile.size + " #Slices: " + sliceCount);
getSliceAsync(myFile, 0, sliceCount, gotAllSlices, docdataSlices, slicesReceived,appData, witService,attachmentService,defaultFolderId,$q,filename,witname).then(function(){
console.log('inside getSliceAsync');
deferred.resolve();
});
}
else {
deferred.resolve();
console.log(result.status);
}
});
return deferred.promise;
}
<div class="flex-rem layout-column pad-box-10" ng-controller="WordCommandController as WordCommandCtrl">
<div class="layout-column flex-rem witty-text-input-container">
<input autofocus type="text" ng-model="WitName" placeholder="Enter wit name" class="flex flex-rem">
</div>
<button ng-click="WordCommandCtrl.createWit()" class="ms-Button ms-Button--primary">
<span class="ms-Button-label">CREATE WIT</span>
</button>
</div>
您需要连接 Office.initialize 事件才能访问 Office API。
有多个 Angular 个样本 here。