当前位置: 首页 > news >正文

银川专业做网站公司企业网站模板

银川专业做网站,公司企业网站模板,江门模板建站源码,从化专业做网站实现目标 将所有订单信息导出到excel表格中 思路 1、在页面中bindtap绑定一个导出点击事件daochu() 2、先获取所有订单信息,并将数据添加到List数组中 3、传入以List数组作为参数,调用get_excel云函数 4、get_excel云函数利用node-xlsx第三方库&#…

实现目标

将所有订单信息导出到excel表格中

 思路

1、在页面中bindtap绑定一个导出点击事件daochu()

2、先获取所有订单信息,并将数据添加到List数组中

3、传入以List数组作为参数,调用get_excel云函数

4、get_excel云函数利用node-xlsx第三方库,在云函数所在目录npm install安装node-xlsx

5、在云函数导入const xlsx = require('node-xlsx'),并设置表格第一行的列数据

6、循环List数组将数据依次添加到第二行、第三行、第四行等等。

7、云函数返回生成excel的临时地址

8、在页面js获取到该临时地址并预览excel表格

完整代码

saveexcel.js

const app = getApp()
Page({/*** 页面的初始数据*/data: {},daochu() {var that = thiswx.showLoading({title: '正在加载',})var List = []wx.cloud.database().collection('yxb_nmkq_order').count().then(async function name(res) {console.log(res.total)var batchTimes = Math.ceil(res.total / 20)for (let index = 0; index < batchTimes; index++) {console.log("第" + index + "次循环");//异步转同步var itemlist = await that.getitemlist(index)List = List.concat(itemlist)}that.setData({List: List})console.log("处理完毕", List);wx.cloud.callFunction({// 要调用的云函数名称name: 'nmkq_get_excel',// 传递给云函数的event参数data: {List: that.data.List}}).then(res => {console.log("云函数结束");console.log(res);that.saveExcel(res.result.fileID)}).catch(err => {// handle errorwx.hideLoading({success: (res) => {wx.showToast({title: '下载失败!',icon: 'none'})},})})})},getitemlist(index) {return new Promise((rev, rej) => {wx.cloud.database().collection('yxb_nmkq_order').skip(index * 20).limit(20).get({success: function (res) {// res.data 包含该记录的数据console.log(res.data)rev(res.data)}})})},saveExcel(fileID) {var that = thiswx.cloud.getTempFileURL({fileList: [fileID],success: res => {that.setData({fileUrl: res.fileList[0].tempFileURL})console.log("最后的地址" + that.data.fileUrl);wx.downloadFile({url: that.data.fileUrl,success: (res) => {that.setData({httpfile: res.tempFilePath})console.log("找不到这个地址?" + that.data.httpfile);//预览文件wx.openDocument({filePath: that.data.httpfile,showMenu: true,success: res => {console.log("预览成功");wx.hideLoading({success: (res) => {},})},fail: err => {console.log(err);}})},fail: (err) => {console.log('读取失败', err)wx.showToast({title: '读取失败!',})}})},fail: err => {console.log(err);wx.showToast({title: '下载失败2!',icon: 'none'})}})},})

 saveexcel.json

{"usingComponents": {},"navigationBarTitleText": "数据导出excel"
}

  saveexcel.wxml


<view style="width: 100%;display: flex;justify-content: center;">
<button style="width: 80%;margin: 20rpx 0;" bindtap="daochu">导出</button>
</view>

云函数写法:

云函数目录/index.js

// 云函数入口文件
const cloud = require('wx-server-sdk')
const xlsx = require('node-xlsx')cloud.init()// 云函数入口函数
exports.main = async (event, context) => {console.log(event);try {let List = event.List//2,定义存储数据的let alldata = [];let row = ['记录号', '订单号', '用户id', '商品名称', '付款价格', '手机号', '姓名', '数量', '备注', '创建时间', '状态值']; //表属性alldata.push(row);for (var i = 0; i < List.length; i++) {let arr = [];arr.push(List[i]._id);arr.push(List[i].orderId);arr.push(List[i].user._id);arr.push(List[i].shop.title);arr.push(List[i].fkprice);arr.push(List[i].phone);arr.push(List[i].username);arr.push(List[i].number);arr.push(List[i].bz);arr.push(List[i].time));arr.push(List[i].status);alldata.push(arr)}console.log(alldata);//3,把数据保存到excel里var buffer = await xlsx.build([{name: "mySheetName",data: alldata}]);console.log(buffer);//4,把excel文件保存到云存储里return await cloud.uploadFile({cloudPath: Date.now() + 'shuju.xlsx',fileContent: buffer, //excel二进制文件})} catch (e) {console.error(e)return e}
}

如果这篇文章对您有所帮助,给个小赞赞吧🌹

http://www.yidumall.com/news/70948.html

相关文章:

  • 企业准备做网站的准备工作百度seo简爱
  • 音速企业名录搜索软件东莞seo技术
  • 寻找做网站的合作伙伴北京软文范例
  • 2017网站风格互联网推广方式
  • 哪个网站可以做行程攻略杭州seo价格
  • 免费企业网站建设免费网站软件推荐
  • 哪些网站可以做h5互联网100个创业项目
  • 网站做微信小程序号码公司网站怎么建立
  • 学网站建设维护浏览器下载安装
  • wordpress的站点地址(url)百度手游app下载
  • 高校校园网站建设培训班培训心得模板
  • 互联网上市公司排名qq群排名优化软件购买
  • 真人与狗做网站网络营销的内容
  • 南通做百度网站的公司网站站长工具seo综合查询分析
  • 如何用网站设计制作杭州百度seo代理
  • 云南营造建设有限公司网站太原百度快速排名提升
  • 网站维护服务公司百度云搜索引擎入口 百度网盘
  • 十堰微网站建设多少钱谷歌seo软件
  • .net 网站地图seo数据分析哪些方面
  • 政府网站建设新华网网站统计哪个好用
  • wordpress解析播放器插件石家庄百度seo
  • java实战网站开发事件营销的案例有哪些
  • 网站开发 图标第三方推广平台
  • 焦作北京网站建设推广专员是做什么的
  • 可以写代码的网站有哪些问题吗最简单的营销方案
  • 上海360网站建设搜索引擎优化的对比
  • 南京 企业网站建设快速优化seo软件推广方法
  • 网站怎么收录关于营销的最新的新闻
  • wordpress文章标题字体大小东莞百度搜索优化
  • wordpress外贸网站模板销售管理怎么带团队