WeChat applet to export binary Excel table file

 As shown in the figure: the export of excel binary files is realized in the applet

 The main code is as follows js:

wx.request({
    url:"导出接口地址",
    method: 'GET',
        header: {
      "content-type": "application/json",
      "token": token ? token : ""
    },
    responseType: "arraybuffer", //注意必须保留该属性
    success: res => {
      console.error("res导出",res);
    const fs = wx.getFileSystemManager(); //获取全局唯一的文件管理器 
    fs.writeFile({ //写文件
      filePath: wx.env.USER_DATA_PATH + "/志愿报表.xlsx",
      data: res.data,  // res.data就是获取到的二进制文件流
      encoding: "binary", //二进制流文件必须是 binary
      success(e) { 
        wx.openDocument({ // 打开文档
          filePath: wx.env.USER_DATA_PATH + "/志愿报表.xlsx", //拿上面存入的文件路径
          showMenu: true, // 显示右上角菜单
          success: function(res) {
            console.log("打开文件",res); 
          },
        })
      }
    })
    }
  }) 

Guess you like

Origin blog.csdn.net/qq_35695041/article/details/130318604