微信小程序中下载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);

}

});

相关推荐
2501_9159184110 小时前
苹果App Store上架审核卡住原因分析与解决方案指南
android·ios·小程序·https·uni-app·iphone·webview
用户7009807357314 小时前
从零开发一个微信记账小程序,零依赖、附完整源码
微信小程序
焦糖玛奇朵婷18 小时前
盲盒小程序开发|解锁开箱新体验[特殊字符]
大数据·开发语言·程序人生·小程序·软件需求
左师佑图18 小时前
微信小程序组件事件冒泡问题排查与解决方案
微信小程序·小程序
树下水月19 小时前
微信小程序接口,必须使用https的443端口吗?
微信小程序·小程序·https
毕设源码-邱学长19 小时前
【开题答辩全过程】以 灵山水牛奶配送小程序的设计与实现为例,包含答辩的问题和答案
小程序
2501_9159184120 小时前
基于Mach-O文件的动态库与静态库归属方案及API扫描实践
android·ios·小程序·https·uni-app·iphone·webview
2501_9151063220 小时前
iOS 证书无法跨电脑使用?签名迁移方法一文讲透
android·ios·小程序·https·uni-app·iphone·webview
毕设源码-赖学姐20 小时前
【开题答辩全过程】以 基于springboot的酒店预订小程序自动化订制系统为例,包含答辩的问题和答案
运维·小程序·自动化
CHU72903520 小时前
邻里同心,便捷团购——社区团购商城小程序前端功能版块解析
前端·小程序