Office Web API从octetstream创建blob并从中创建新工作簿javascriptms excel

问题描述

我试图基于服务器REST API响应(八位字节流)创建工作簿,但是我无法创建工作簿。

以下是我的创建工作簿功能的代码段:

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();

我遇到此错误:

{ “ description”:“参数无效,丢失或格式不正确。”, “ message”:“参数无效,丢失或格式错误。”, “ stack”:“ InvalidArgument:参数无效或丢失或格式不正确。\ n在匿名函数(https://appsforoffice.microsoft.com/lib/1/hosted/excel-win32-16.01.js:26:287669)\ n在o(https://script-lab-runner.azureedge.net/static/js/1.0f9cfae3.chunk.js:1:2779072)\ n在匿名函数({{ 3}})\ n在u(https://script-lab-runner.azureedge.net/static/js/1.0f9cfae3.chunk.js:1:2779219)“, “ name”:“ RichApi.Error”, “ code”:“ InvalidArgument”, “ traceMessages”:[], “ innerError”:null, “调试信息”: { “ code”:“ InvalidArgument”, “ message”:“参数无效,丢失或格式错误。”, “ errorLocation”:“ Application.createWorkbook”, “ statement”:“ var createWorkbook = application.createWorkbook(...);”, “ surroundingStatements”:[ “ var workbook = context.workbook;”, “ var application = workbook.application;”, “ // >>>>>”, “ var createWorkbook = application.createWorkbook(...);”, “ //

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...