office web api从octetstream创建blob并从中创建新工作簿(javascript)(ms excel)
我正在尝试基于服务器RESTAPI响应(八位字节流)创建工作簿,但创建失败 以下是“创建工作簿”函数的代码段:office web api从octetstream创建blob并从中创建新工作簿(javascript)(ms excel),excel,office-js,office-addins,excel-addins,Excel,Office Js,Office Addins,Excel Addins,我正在尝试基于服务器RESTAPI响应(八位字节流)创建工作簿,但创建失败 以下是“创建工作簿”函数的代码段: async function createWorkbookFromExisting(myBlob) { OfficeExtension.config.extendedErrorLogging = true; const reader = new FileReader(); reader.onload = (event) => { Excel.run((con
async function createWorkbookFromExisting(myBlob) {
OfficeExtension.config.extendedErrorLogging = true;
const reader = new FileReader();
reader.onload = (event) => {
Excel.run((context) => {
// strip off the metadata before the base64-encoded string
const startIndex = reader.result.toString().indexOf("base64,");
console.log(startIndex);
const mybase64 = reader.result.toString().substr(startIndex + 7);
//console.log(mybase64);
Excel.createWorkbook(mybase64);
return context.sync();
});
};
下面是我的blob创建片段:
xmlHttpRequest.onreadystatechange = function() {
//var a;
if (xmlHttpRequest.readyState === 4 && xmlHttpRequest.status === 200) {
console.log(xmlHttpRequest.response);
var respObj = new Object(xmlHttpRequest.response);
//xmlHttpRequest.re
console.log(respObj);
var resp = new Blob([xmlHttpRequest.response], { type: 'application/ vnd.openxmlformats - officedocument.spreadsheetml.sheet;'});
createWorkbookFromExisting(resp);
}
};
xmlHttpRequest.open("GET", _url);
//xmlHttpRequest.setRequestHeader("Content-Type","application/octet-stream");
xmlHttpRequest.responseType = 'blob';
xmlHttpRequest.send();
我有一个错误:
{
“说明”:“参数无效或缺少,或格式不正确。”,
“消息”:“参数无效或丢失或格式不正确。”,
“堆栈”:“InvalidArgument:参数无效或丢失,或格式不正确。\n在匿名函数()\n在o()\n在匿名函数()\n在u()”,
“名称”:“RichApi.Error”,
“代码”:“无效辩论”,
“跟踪消息”:[],
“innerError”:空,
“调试信息”:{
“代码”:“无效辩论”,
“消息”:“参数无效或丢失或格式不正确。”,
“errorLocation”:“Application.create工作簿”,
“语句”:“var createWorkbook=application.createWorkbook(…);”,
“周边声明”:[
“var workbook=context.workbook;”,
“var application=workbook.application;”,
"// >>>>>",
“var createWorkbook=application.createWorkbook(…);”,
“//我可以知道您是如何运行这些代码的吗?您可以共享代码中提到的resp示例以帮助重新编程吗?您好@MandytMSFT,我使用ScriptLab运行了它。是否可以共享您的resp示例以集中精力确定API错误的原因?