微信小程序 下载文档并预览 ppt excel word

 
下载按钮如上
 
downloadFile: function (e) {
console.log(e);
let type = e.currentTarget.dataset.type;
let url = e.currentTarget.dataset.url;
switch (type) {
case "pdf":
url += 'pdf';
break;
case "word":
url += 'docx';
break;
case "excel":
url += 'xlsx';
break;
default:
url += 'pptx';
break;
}
wx.downloadFile({
url: url,
header: {
"productCode": 'wgs-wechat',
"token": wx.getStorageSync('token'),
},
success: function (res) {
console.log(res)
var filePath = res.tempFilePath;
console.log(filePath);
wx.openDocument({
fileType: 'xlsx',
filePath: filePath,
success: function (res) {
console.log('打开文档成功')
},
fail: function (res) {
console.log(res);
},
complete: function (res) {
console.log(res);
}
})
},
fail: function (res) {
console.log('文件下载失败');
},
complete: function (res) { },
})
},
 
注意  fileType: 'xlsx',  必须要写 不然会找不到类型  此例子是 下载 表格

转载于:https://www.cnblogs.com/xulongyang/p/10402419.html

你可能感兴趣的:(微信小程序 下载文档并预览 ppt excel word)