请选择 进入手机版 | 继续访问电脑版
 找回密码
 立即注册

QQ登录

只需一步,快速开始

helxsz

注册会员

4

主题

5

帖子

23

积分

注册会员

积分
23
  • 95

    金币

  • 4

    主题

  • 5

    帖子

helxsz
注册会员   /  发表于:2022-4-2 03:41  /   查看:1711  /  回复:1
1金币

我使用vue和axios分装的request去导入一个远程链接下的excel文件,文件数据能够通过resp获取到,
console.log 打印是一堆这样的excel数据

�N�@Exl/PK
�N�@        bxl/_rels/PK�N�@���� �xl/_rels/workbook.xml.relsPK�N�@�A�/�W �xl/sharedStrings.xmlPK�N�@%Y=�
VM
 Q
xl/styles.xmlPK
�N�@        xl/theme/PK�N�@L���  Exl/theme/theme1.xmlPK�N�@v��&� �xl/workbook.xmlPK
�N�@fxl/worksheets/PK�N�@���LVV �xl/worksheets/sheet1.xmlPKF


后面我使用excelIo.open 去 加载这个数据,但是报了的错误
TypeError: Failed to execute 'readAsArrayBuffer' on 'FileReader': parameter 1 is not of type 'Blob'.    at e.loadFile (gc.spread.excelio.min.js?8e91:26:1)    at e.open (gc.spread.excelio.min.js?8e91:22:1)             


不知道使用哪里出了问题



        getXlsx: function(webpath) {
            const excelIo = new IO();
            request({ url: webpath , method: 'get',  headers: { cache: false,"Content-Type": "application/x-www-form-urlencoded",  "Access-Control-Allow-Origin": "*", 'X-Requested-With': 'XMLHttpRequest', crossDomain: true} })
            .then(resp => {
                console.log('get excel', resp);
                excelIo.open(resp, json => {
                  console.log('excel json',json);
                  this.spread.fromJSON(json);
                });
            }).catch(error => {
              console.log(error);
            });
        }




最佳答案

查看完整内容

从上面的报错来看,传的json不是一个blob。我们的open方法是将blob转成json。可以参考一下这篇文章的导入excel方法 https://gcdn.grapecity.com.cn/forum.php?mod=viewthread&tid=37389&extra=page%3D1

1 个回复

倒序浏览
最佳答案
最佳答案
Derrick.Jiao讲师达人认证 悬赏达人认证 SpreadJS 开发认证
论坛元老   /  发表于:2022-4-2 03:41:35
来自 2#
从上面的报错来看,传的json不是一个blob。我们的open方法是将blob转成json。可以参考一下这篇文章的导入excel方法
https://gcdn.grapecity.com.cn/fo ... &extra=page%3D1
回复 使用道具 举报
您需要登录后才可以回帖 登录 | 立即注册
返回顶部