原代码:
wx.downloadFile({
// 示例 url,并非真实存在
url: url,
success: function (res) {
const filePath = res.tempFilePath
wx.openDocument({
filePath: filePath,
showMenu:true,
fileType:'xlsx',
success: function (res) {
console.log('打开文档成功')
},
fail(res){
console.log(res,'resres')
}
})
}
})
修改后的代码
wx.downloadFile({
// 示例 url,并非真实存在
url: url,
filePath: wx.env.USER_DATA_PATH + '/1.xlsx',//自定义文件地址
success: function (res) {
// const filePath = res.tempFilePath
wx.openDocument({
filePath: wx.env.USER_DATA_PATH + '/1.xlsx',
fileType:'xlsx',
showMenu: true, // 显示右上角菜单
success: function (res) {
console.log('打开文档成功')
},
fail(res){
console.log(res,'resres')
}
})
}
})
解决方法,wx.downloadFile及wx.openDocument同时设置filePath,不使用wx.downloadFile成功回调给的filePath