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

  • 相关阅读:
    PostgreSQL 数据类型详细说明
    解决Qt报错:Android deploy settings file not found, not building an APK.
    [Android]打开应用时导航栏闪烁问题分析
    网卡收发包过程
    BUG:阿里巴巴图标库引入链接后,icon有时候会不显示的话svg下载到本地使用
    『PyQt5-Qt Designer篇』| 09 Qt Designer中分割线和间隔如何使用?
    SQLite 3.4.60 版本发布,带来优化器和函数增强!
    Ubuntu22.04 交叉编译GCC13.2.0 for Rv1126
    linux下PHP 环境搭建
    上线就破100W!京东面试官的Spring高级源码手抄本,真不能再细了
  • 原文地址:https://blog.csdn.net/qq_51538602/article/details/133387332