Javascript使用SheetJS读取服务器上的Excel文件 [英] Javascript Read Excel file on server with SheetJS

查看:119
本文介绍了Javascript使用SheetJS读取服务器上的Excel文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用一个名为 SheetJS 的库,我想阅读一个不使用nodejs而仅使用纯javascript驻留在服务器上的excel工作表.这可能吗?

I am using a library called SheetJS and I want to read an excel sheet that resides on the server without using nodejs, only pure javascript. Is this possible?

文档中有一条消息,内容为"readFile仅在服务器环境中可用.浏览器没有用于读取给定路径的任意文件的API,因此必须使用另一种策略"

There is a message in the documentation that says "readFile is only available in server environments. Browsers have no API for reading arbitrary files given a path, so another strategy must be used"

使用以上消息,我认为作者是指文件位于客户端的情况.

With the above message, I assume the author is referring to a situation where the file is residing on the client side.

这是我到目前为止所做的

This is what I have done so far

var wb = XLSX.readFile("myFile.xlsx"); //my file is in same directory on server

我收到错误消息" xlsx.full.min.js:22未捕获的TypeError:无法读取未定义的属性'readFileSync'"

推荐答案

这对我有用

   /* set up async GET request */
    var req = new XMLHttpRequest();
    req.open("GET", url, true);
    req.responseType = "arraybuffer";

    req.onload = function(e) {
      var data = new Uint8Array(req.response);
      var workbook = XLSX.read(data, {type:"array"});

      /* DO SOMETHING WITH workbook HERE */
    }

    req.send();

这篇关于Javascript使用SheetJS读取服务器上的Excel文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆