1、打开文档
微信小程序文档:https://developers.weixin.qq.com/miniprogram/dev/api/file/wx.openDocument.html
wx.downloadFile({
url: 'http://list.xls',
success: (res) => {
wx.openDocument({
filePath: res.tempFilePath,
success: function (res) {
console.log('打开文档成功', res)
}
})
}
})
2、对打开的文档标题乱码处理
https://developers.weixin.qq.com/miniprogram/dev/api/network/download/wx.downloadFile.html
let val = res.url; // 获取取得url
//获取最后一个.的位置
var index= val.lastIndexOf(".");
//获取后缀
var ext = val.substr(index+1);
let filesPath = wx.env.USER_DATA_PATH + '/速查手册.'+ext
console.log('filesPath', filesPath)
wx.downloadFile({
url: val,
filePath: filesPath, // 自定义下载后的临时文件路径
success: (res) => {
wx.openDocument({
filePath: res.filePath,
success: function (res) {
console.log('打开文档成功', res)
}
})
}
})
3、本地浏览没问题,但线上预览错误
在小程序开发配置中,一定要填写dowload域名