V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
FlowerChen
V2EX  ›  问与答

javascript 导出 excel 文件的问题

  •  
  •   FlowerChen · Jun 30, 2017 · 3132 views
    This topic created in 3228 days ago, the information mentioned may be changed or developed.

    写了一个导出 excel 的函数,主要代码如下:

    this.$http.get('/api/v1/export',{
               params:params
           }).then(function(data){
               var binaryData = [];
               binaryData.push(data.data);
               var a = document.createElement('a');
               var url =  window.URL.createObjectURL(new Blob(binaryData, {encoding:"UTF-8",type: "application/vnd.ms-excel"}))
               a.href = url;
               a.download = "export.xls"
               a.click();
               window.URL.revokeObjectURL(url);
           },function(err){
           	   console.log("出错了")
           }
    

    这段代码是导出一个后缀为 xls 的文件,在本地跑是没有问题的,但是推到线上,就会提示文件无法打开,“ export .xls ”的文件格式和扩展名不匹配。文件可能已损坏或不安全 如何解决呀 跪求大神呀

    1 replies    2017-06-30 17:56:41 +08:00
    cxbig
        1
    cxbig  
       Jun 30, 2017
    建议由那个 API 在服务器端生成 xls 文件,然后下载该文件。
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   2438 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 28ms · UTC 09:33 · PVG 17:33 · LAX 02:33 · JFK 05:33
    ♥ Do have faith in what you're doing.