Javascript Office.js Win.js和WinJS.xhr的问题
我尝试在Excel中创建rest插入。 我可以在Chrome中调试它们,一切看起来都很好。 但它不是在办公室里运行的。 公开 我从rest服务处得到了这个信息。 将它们放入标题和行中(在Chrome调试器中我可以看到) 我调用setExcelData什么应该将数据写入Excel !!!但我看不到结果Javascript Office.js Win.js和WinJS.xhr的问题,javascript,xmlhttprequest,winjs,office-js,Javascript,Xmlhttprequest,Winjs,Office Js,我尝试在Excel中创建rest插入。 我可以在Chrome中调试它们,一切看起来都很好。 但它不是在办公室里运行的。 公开 我从rest服务处得到了这个信息。 将它们放入标题和行中(在Chrome调试器中我可以看到) 我调用setExcelData什么应该将数据写入Excel !!!但我看不到结果 <link href="https://cdnjs.cloudflare.com/ajax/libs/winjs/4.4.0/css/ui-light.css" rel="styles
<link href="https://cdnjs.cloudflare.com/ajax/libs/winjs/4.4.0/css/ui-light.css" rel="stylesheet" />
<script src="https://appsforoffice.microsoft.com/lib/1/hosted/Office.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/winjs/4.4.0/js/base.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/winjs/4.4.0/js/ui.js"></script>
function setExcelData(officeTable) {
if (officeTable != null) {
Office.context.document.setSelectedDataAsync(officeTable, { coercionType: Office.CoercionType.Table }, function (asyncResult) {
if (asyncResult.status == Office.AsyncResultStatus.Failed) {
showMessage('Set Selected Data Failed');
}
else {
showMessage('Set Selected Data Success');
}
});
}
}
Office.TableData.prototype.addHeaders = function (obj) {
var h = new Array();
for (var prop in obj) {
if (typeof (obj[prop]) != 'object' &&
prop.trim().length > 0 &&
prop != '__type')
h.push(prop);
}
this.headers = h;
}
Office.TableData.prototype.addRange = function (array) {
for (i = 0; i < array.length; i++) {
var itemsTemp = new Array();
var arr = Object.keys(array[i]).map(function(k) { return array[i][k] });
this.rows.push(arr);
}
}
WinJS.UI.processAll().done(function () {
WinJS.xhr({
url: "http://jsonplaceholder.typicode.com/posts",
responseType: "json"
}).done(
function completed(request) {
var officeTable = new Office.TableData();
officeTable.addHeaders(request.response[0]);
officeTable.addRange(request.response);
setExcelData(officeTable);
Office.context.document.setSelectedDataAsync(officeTable, { coercionType: Office.CoercionType.Table }, function (asyncResult) {
if (asyncResult.status == Office.AsyncResultStatus.Failed) {
showMessage('Set Selected Data Failed');
}
else {
showMessage('Set Selected Data Success');
}
});
},
function error(request) {
},
function progress(request) {
});
});
函数setExcelData(officeTable){
if(offfitable!=null){
Office.context.document.setSelectedDataAsync(officeTable,{矫顽类型:Office.矫顽类型.Table},函数(asyncResult){
if(asyncResult.status==Office.AsyncResultStatus.Failed){
showMessage('设置所选数据失败');
}
否则{
showMessage(“设置所选数据成功”);
}
});
}
}
Office.TableData.prototype.addHeaders=函数(obj){
var h=新数组();
用于(obj中的var prop){
if(typeof(obj[prop])!=“对象”&&
道具修剪()长度>0&&
道具!=“\uuuu类型”)
h、 推(撑);
}
this.headers=h;
}
Office.TableData.prototype.addRange=函数(数组){
对于(i=0;i
Office上下文仅在Word或Office 365中运行时有效。在Word中运行调试时,您是否得到相同的结果?Office上下文仅在Word或Office 365中运行时有效。在Word中运行调试时,您是否得到相同的结果?