1、云函数下安装好依赖,开发云函数功能
2、部署云端云函数成功后,
3、体验版或者正式版需要连接云端云函数,连接本地无法使用

云函数逻辑:

// 云函数入口文件
const cloud = require('wx-server-sdk')
cloud.init()//操作excel用的类库
const xlsx = require('node-xlsx');// 云函数入口函数
exports.main = async(event, context) => {try {let { userdata } = eventconsole.log(userdata)//1,定义excel表格名let dataCVS = new Date().getTime() + '.xlsx'//2,定义存储数据的let alldata = [];//  '维修金额',let row = ['vin','车辆类型', '出险时间','理赔项类型','理赔名称','理赔金额']; //表属性alldata.push(row);function singleTypeFilter(val) {let str = "";switch (val) {case "1":str = "更换";break;case "2":str = " 维修";break;case "3":str = "材料";break;}return str;}function  regFenToYuan(a) {var num = Number(a);if (!num) {//等于0return num + ".00";} else {//不等于0num = Math.round(num * 100) / 10000;num = num.toFixed(2);num += ""; //转成字符串var reg =num.indexOf(".") > -1? /(\d{1,3})(?=(?:\d{3})+\.)/g: /(\d{1,3})(?=(?:\d{3})+$)/g; //千分符的正则console.log(num.indexOf(".") > -1);return num.replace(reg, "$1,"); //千分位格式化}}let records =userdata? userdata.records || []:[]records.forEach((item,index)=>{item.resultInfo.forEach((j,i)=>{let arr = [];arr.push(item.vin);arr.push(item.vehicleType);arr.push(item.dangerDate);arr.push(singleTypeFilter(j.dangerSingleType));arr.push(j.dangerSingleName);arr.push(regFenToYuan(j.dangerSingleMoney));alldata.push(arr)})})//3,把数据保存到excel里var buffer = await xlsx.build([{name: "(请保存)出险记录明细",data: alldata}]);//4,把excel文件保存到云存储里return await cloud.uploadFile({cloudPath: dataCVS,fileContent: buffer, //excel二进制文件})} catch (e) {console.error(e)return e}
}

小程序端逻辑

serviceInfo数据结构

serviceInfo: {serviceSumCount: "5",serviceSumMoney: "1838148",records: [{dangerDate: "2016-11",resultInfo: [{dangerSingleType: "2",dangerSingleName: "前保险杠(全喷)",dangerSingleMoney: "40000",},{dangerSingleType: "2",dangerSingleName: "右前叶子板(全喷)",dangerSingleMoney: "40000",},],vin: "LG29384",vehicleType: "长城CC7150FM01轿车",serviceMoney: "80000",},],},
//获取云存储文件下载地址,这个地址有效期一天getFileUrl(fileID) {let that = this;uniCloud.getTempFileURL({fileList: [fileID],success: (res) => {// get temp file URLconsole.log("文件下载链接", res.fileList[0].tempFileURL);uni.downloadFile({url: res.fileList[0].tempFileURL,fail: function (err) {console.log(err);},success: function (res) {console.log(res);var filePath = res.tempFilePath;uni.openDocument({filePath: filePath,showMenu: true,success: function (res) {uni.hideLoading();console.log("打开文档成功");},});// 云函数删除云存储文件uniCloud.deleteFile({fileList: [fileID],}).then((res) => {console.log(res, "yyy");}).catch((err) => {console.log(err, "yyy2");});},});},fail: (err) => {// handle error},});},export() {uni.showLoading({title: "加载中...",});// details_demouniCloud.callFunction({name: "getExcelInfo",data: { userdata: this.serviceInfo },}).then((res) => {console.log(res.result);this.getFileUrl(res.result.fileID);});// this.$message.info("查询成功,请注意查收结果");console.log(this.serviceInfo);},

效果:

uniapp使用云开发做excel数据导出的坑相关推荐

  1. 微信小程序云开发:使用excel-export导出excel

    微信小程序云开发:使用excel-export导出excel 前言 关于小程序的excel导出,我也走过了不少坑.之前看了很多人要不使用其他云作为excel的导出工具,要不压根就只是nodejs,而不 ...

  2. 开发指南专题十五 JEECG微云快速开发平台EXCEL导入导出

    分享一下我老师大神的人工智能教程!零基础,通俗易懂!http://blog.csdn.net/jiangjunshow 也欢迎大家转载本篇文章.分享知识,造福人民,实现我们中华民族伟大复兴!  开 ...

  3. c# cad二次开发通过获取excel数据 在CAD绘图,将CAD属性导出到excel

    c# cad二次开发通过获取excel数据 在CAD绘图,将CAD属性导出到excel using Autodesk.AutoCAD.ApplicationServices; using Autode ...

  4. 【系】微信小程序云开发实战坚果商城-云开发之首页数据实现

    第 3-6 课:云开发之首页数据实现 目录 开篇 [系]微信小程序云开发实战坚果商城-开篇 基础篇 [系]微信小程序云开发实战坚果商城-弹性盒子 [系]微信小程序云开发实战坚果商城-ES6 简单入门 ...

  5. 小程序——云开发数据库的数据读取出来显示到页面

    最近在做小程序,遇到一个小问题,要将云开发数据库的数据读取出来显示到页面 JS页面: 1.数据库初始化 const db = wx.cloud.database() 2.定义一个变量,将this赋给它 ...

  6. UNI-APP使用云开发跨全端开发实战讲解

    UNI-APP 是一个使用 Vue.js 开发所有前端应用的框架,开发者编写一套代码,可发布到iOS.Android.Web(响应式).以及各种小程序(微信/支付宝/百度/头条/QQ/钉钉/淘宝).快 ...

  7. uniapp 微信云开发静态网站和云函数跳转小程序

    uniapp 微信云开发静态网站和云函数跳转小程序 云开发静态网站的创建 云函数及copy-webpack-plugin 安装copy-webpack-plugin可能遇到的问题 静态网站和云函数的搭 ...

  8. uniapp 阿里云开发微信小程序一键登录

    1.插件市场导入uni-id公用模块 插件市场 uni-id : https://ext.dcloud.net.cn/plugin?id=2116 导入成功后会在项目云文件夹下自动生成common目录 ...

  9. 关于微信小程序云开发数据库中有数据查询不到的问题

    最近在学习过程中遇到一个微信小程序云开发数据库中有数据查询不到的问题 集合查询代码如下: Page({/* 采用了ES6的写法 */onLoad() {wx.cloud.database().coll ...

最新文章

  1. vantui框架_vue移动端优秀框架收集
  2. js 提交form表单,js更改form表单的action属性
  3. osfmount 命令加载虚拟光驱_OSFMount挂载虚拟磁盘工具下载
  4. 解决pip更新问题。 You are using pip version 19.0.3, however version 19.1 is available.
  5. 一起开心集训队第一周训练赛2021/3/14
  6. vue图片点击超链接_10秒钟,告别ppt中难看的超链接
  7. View、Text、Button的drawableLeft左侧图片自定义大小
  8. 【C++ STL学习之一】容器的共通能力和共通操作总结
  9. [解题报告]1005 - Number Sequence
  10. oracle socct用户,oracle 19c 添加 scott用户与表
  11. Redmi K50系列三款新机全部入网:三款旗舰芯片都很能打
  12. 从拨号到 5G :互联网登录完全指南
  13. 使用数据库DEAP来分析基于EEG信号的情绪论文调研汇总
  14. 机器学习教程 - 分步指南
  15. 电压和电流的有效值、瞬时值、平均值、最大值及其关系
  16. 彩扩机项目--两个状态指示灯,巧妙的使用二极管的特性,以及物理按键的滤波...
  17. 如何使用Visual Studio查看源代码
  18. 基于Jquery实现登录功能的前端页面
  19. 漫谈 | 从52个思考题来看《Linux内核设计的艺术》
  20. 内蒙古邮政计算机考试题目,内蒙古银行考试_邮政储蓄银行考试计算机笔试题...

热门文章

  1. 用VB设计控制上网时间程序Java教程
  2. idea提示cannot download sources 解决办法
  3. Linux C/TCP多线程网络聊天室
  4. uniapp tabBar 事件屏蔽 点击屏蔽
  5. Scratch3.0少儿编程——专栏解读——节约时间的巧妙方法
  6. R语言 mac X11 library is missing: install XQuartz from xquartz.macosforge.org
  7. 房地产销售管理系统商业项目视频课程-赖国荣-专题视频课程
  8. MGRE网络的chap认证--ppp认证--tunnel 隧道综合实验
  9. 如何搭建“网络课堂”
  10. 无敌均线操作法(一)