Taro.downloadFile({
url:
config.apiUrl +
`account/checking/excel?supplierId=001&startTime=${state.startMonth}&endTime=${state.endMonth}`, //调用后台接口的全路径
header: {
Authorization: Taro.getStorageSync("token"),
"Content-type": "application/json",
},// 配置请求头
success: (res) => {
const manage = Taro.getFileSystemManager();
if (res.statusCode === 200) {
manage.saveFile({
tempFilePath: res.tempFilePath,
filePath: Taro.env.USER_DATA_PATH + "/账单明细.xlsx", // 文件重命名 可自定义
success: function (res) {},
});
Taro.hideLoading();
// 打开文档
Taro.openDocument({
filePath: Taro.env.USER_DATA_PATH + "/账单明细.xlsx",
fileType: "xlsx", // 导出文件的格式
showMenu: true, // 是否显示右上角菜单
success: function (res) {
console.log("打开文档成功");
},
fail: function () {
console.log("打开失败");
},
});
}
},
fail(err) {
console.log("downloadfile err", err);
},
});
Taro开发微信小程序--实现导出Excel表格功能
于 2022-11-21 09:58:27 首次发布