uniapp小程序下载excel
<button @click="exportFilledFun">导出excel</button>
exportFilledFun() {
uni.request({
url: `http://test.yunsign.net/file.php`,
method: 'GET',
responseType: 'arraybuffer',
success: (res) => {
const fileManagerObj = uni.getFileSystemManager()
console.log(fileManagerObj);
const filePath = `${wx.env.USER_DATA_PATH}/${new Date().getTime()}.xlsx`
fileManagerObj.writeFile({
data: res.data,
filePath: filePath,
encoding: 'binary',
success: (res) => {
console.log(res)
this.viewDoc(filePath)
}
})
},
fail: (err) => {
console.log(err)
}
})
},
viewDoc(filePath) {
uni.openDocument({
filePath: filePath,
fileType: 'xlsx',
showMenu: true,
success: (res) => {
console.log('打开文档成功')
}
})
},