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

}

});

相关推荐
Emma歌小白1 天前
如何首次运行小程序后端
微信小程序
赣州云智科技的技术铺子1 天前
【一步步开发AI运动APP】十二、自定义扩展新运动项目1
微信小程序·小程序·云开发·智能小程序
2501_915918411 天前
iOS 上架全流程指南 iOS 应用发布步骤、App Store 上架流程、uni-app 打包上传 ipa 与审核实战经验分享
android·ios·小程序·uni-app·cocoa·iphone·webview
00后程序员张1 天前
iOS App 混淆与加固对比 源码混淆与ipa文件混淆的区别、iOS代码保护与应用安全场景最佳实践
android·安全·ios·小程序·uni-app·iphone·webview
破无差2 天前
《赛事报名系统小程序》
小程序·html·uniapp
00后程序员张2 天前
详细解析苹果iOS应用上架到App Store的完整步骤与指南
android·ios·小程序·https·uni-app·iphone·webview
海绵宝宝不喜欢侬2 天前
uniapp-微信小程序分享功能-onShareAppMessage
微信小程序·小程序·uni-app
2501_915106322 天前
Xcode 上传 ipa 全流程详解 App Store 上架流程、uni-app 生成 ipa 文件上传与审核指南
android·macos·ios·小程序·uni-app·iphone·xcode
亮子AI2 天前
【小程序】微信小程序隐私协议
微信小程序·小程序
weixin_177297220692 天前
短剧小程序系统开发:打造个性化娱乐新平台
小程序·娱乐·短剧