天天看點

微信小程式 下載下傳文檔并預覽 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\',  必須要寫 不然會找不到類型  此例子是 下載下傳 表格