微信小程序中下载xlsx文件

var storeSessionKey = uni.getStorageSync("storeSessionKey");

var that = this;

uni.request({

url: that.$api + '/openapi/storeAdmin/exportSalesData?activityId=' + that.params

.activityId, // 替换为服务器端的文件下载接口地址

method: 'GET',

header: {

"X-Token": storeSessionKey, //自定义请求头信息

},

responseType: 'arraybuffer', // 设置响应类型为字节流

success: function(rest) {

console.log(rest, '圣诞节发货');

if (rest.statusCode === 200) {

const fs = wx.getFileSystemManager(); //获取全局唯一的文件管理器

fs.writeFile({ // 写文件

filePath: wx.env.USER_DATA_PATH +

`/${that.avtName}.xlsx`, // wx.env.USER_DATA_PATH 指定临时文件存入的路径,后面字符串自定义

data: rest.data,

encoding: "binary", //二进制流文件必须是 binary

success(res) {

wx.openDocument({ // 新开页面打开文档

filePath: wx.env.USER_DATA_PATH +

`/${that.avtName}.xlsx`, //拿上面存入的文件路径

showMenu: true, // 允许出现分享功能

success: function(res) {

uni.showToast({

title: "打开成功,请自行发送给好友保存",

icon: "none"

})

setTimeout(() => {

uni.hideLoading()

}, 500)

}

})

},

fail() {

uni.hideLoading()

uni.showToast({

title: "文件走丢了~",

icon: "none"

})

}

});

}

},

fail: function(err) {

console.log('请求失败', err);

}

});

相关推荐
内存不泄露2 小时前
二手物品交易平台
spring boot·小程序·django
说私域4 小时前
基于AI智能名片链动2+1模式预约服务商城小程序的数据管理与系统集成研究
大数据·人工智能·小程序
说私域6 小时前
用户感知断裂与商业模式颠覆:AI智能名片链动2+1模式S2B2C商城小程序的破局之道
大数据·人工智能·小程序
peachSoda76 小时前
uniapp开发小程序 使用scroll-view时左右滑动切换无法回到最左边的bug解决方案
小程序·uni-app
游戏开发爱好者87 小时前
如何在 Windows 环境下测试 iOS App,实时日志,CPU监控
android·ios·小程序·https·uni-app·iphone·webview
计算机毕设指导67 小时前
基于微信小程序的社区医疗服务管理系统【源码文末联系】
java·spring boot·微信小程序·小程序·tomcat·maven·intellij-idea
fengGer的bugs7 小时前
微信小程序版「死了么APP」,它来了
微信小程序·小程序·死了么·死了么app
我的86呢!7 小时前
微信小程序蓝牙配网
微信小程序·小程序
花卷HJ7 小时前
【微信小程序】open-type=“contact“ 客服按钮样式无法设置?隐藏 button + label 触发完美解决
微信小程序·小程序·notepad++
康小庄7 小时前
通过NGINX实现将小程序HTTPS请求转为内部HTTP请求
java·spring boot·nginx·spring·http·小程序