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


<button class='skblue_bg' data-url="http://172.168.1.153:8030/tax/specialDeduction/specialAdditionalDeductionExport?year=2019" data-type="excel" catchtap='downloadFile'>下载</button>
 
下载按钮如上
 
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',  必须要写 不然会找不到类型  此例子是 下载 表格


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM