【微信小程序】导出Excel文件

javascript 复制代码
// 导出
doOutExcel() {
  let fileName = '考勤列表'
  wx.request({
    url: 'XXX',
    method: 'POST',
    header: {
      "content-type": "application/json",
      "Authorization": "token " + wx.getStorageSync('userInfo').token
    },
    data: {}, // 请求参数
    responseType: "arraybuffer", 
    success: res => {
      console.log("res导出",res);
      const fs = wx.getFileSystemManager(); //获取全局唯一的文件管理器 
      fs.writeFile({ //写文件
        filePath: wx.env.USER_DATA_PATH + `/${fileName}.xlsx`,
        data: res.data,  // res.data就是获取到的二进制文件流
        encoding: "binary", //二进制流文件必须是 binary
        success(e) { 
          wx.openDocument({ // 打开文档
            filePath: wx.env.USER_DATA_PATH + `/${fileName}.xlsx`, //拿上面存入的文件路径
            showMenu: true, // 显示右上角菜单
            success: function(res) {
              console.log("打开文件",res); 
            },
          })
        }
      })
    }
  }) 
}

在安卓机上能正常预览文件,ios上出现"OfficeImportErrorDomain"错误912。此时文件已经保存到了手机,点击右上角三个点用其他方式打开就能看到正常的文件内容,在ios上预览出现了问题。

相关推荐
计算机毕设指导64 小时前
基于微信小程序的社区医疗服务管理系统【源码文末联系】
java·spring boot·微信小程序·小程序·tomcat·maven·intellij-idea
fengGer的bugs5 小时前
微信小程序版「死了么APP」,它来了
微信小程序·小程序·死了么·死了么app
我的86呢!5 小时前
微信小程序蓝牙配网
微信小程序·小程序
花卷HJ5 小时前
【微信小程序】open-type=“contact“ 客服按钮样式无法设置?隐藏 button + label 触发完美解决
微信小程序·小程序·notepad++
qq_12498707536 小时前
基于springboot的文化旅游小程序(源码+论文+部署+安装)
java·spring boot·后端·微信小程序·小程序·毕业设计·旅游
计算机毕设指导61 天前
基于微信小程序民宿预订管理系统【源码文末联系】
java·spring boot·mysql·微信小程序·小程序·tomcat·maven
P7Dreamer1 天前
微信小程序处理Range分片视频播放问题:前端调试全记录
前端·微信小程序
苦夏木禾1 天前
在微信小程序中,同样的宽度100%,textarea和其他标签的实际宽度不一样
微信小程序·小程序
计算机毕设指导61 天前
基于微信小程序的驾校预约管理系统【源码文末联系】
java·spring boot·微信小程序·小程序·tomcat·maven·intellij-idea
毕设源码-邱学长1 天前
【开题答辩全过程】以 养老服务微信小程序为例,包含答辩的问题和答案
微信小程序·小程序