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

做新闻网站数据在线生成网页网站

做新闻网站数据,在线生成网页网站,东莞高端网站定制,一般网站用什么技术做的前言:开发过程中遇到的一些业务场景,如果第三方不让使用,后端不提供接口,就只能拿到table数据(Array),实现excel文件下载。 废话不多说,直接上代码,方法后续自行封装即可: functio…

前言:开发过程中遇到的一些业务场景,如果第三方不让使用,后端不提供接口,就只能拿到table数据(Array),实现excel文件下载。

废话不多说,直接上代码,方法后续自行封装即可:

function downLoadExcel(){console.log("下载excel");var table = [{index:"1",name:"Jerry",username:"杰瑞1",father:"你爸爸"},{index:"2",name:"Jerry",username:"杰瑞2",father:"你爸爸"},{index:"3",name:"Jerry",username:"杰瑞3",father:"你爸爸"},{index:"4",name:"Jerry",username:"杰瑞4",father:"你爸爸"},{index:"5",name:"Jerry",username:"杰瑞5",father:"你爸爸"},{index:"6",name:"Jerry",username:"杰瑞6",father:"你爸爸"},{index:"7",name:"Jerry",username:"杰瑞7",father:"你爸爸"},{index:"8",name:"Jerry",username:"杰瑞8",father:"你爸爸"},{index:"9",name:"Jerry",username:"杰瑞9",father:"你爸爸"},{index:"10",name:"Jerry",username:"杰瑞10",father:"你爸爸"},{index:"11",name:"Jerry",username:"杰瑞11",father:"你爸爸"},{index:"12",name:"Jerry",username:"杰瑞11",father:""},]console.log("长度",table.length)console.log("数据源是什么1",JSON.parse(JSON.stringify(table)))let JSONData = JSON.parse(JSON.stringify(table));let ShowLabel = ['序号', '英文名', '中文名','父亲','母亲','儿子','孙子','外公','外婆'];//先转化jsonlet arrData = typeof JSONData != 'object' ? JSON.parse(JSONData) : JSONData;console.log("数据源是什么",arrData)// 给数组内容换好位置arrData.forEach(item => {let obj = {index: item.index,name: item.name ? item.name : '',username: item.username,father:item.father?item.father:'',};table.push(obj);});let excel = '<table>';//设置表头let row = '<tr>';for (let i = 0; i < ShowLabel.length; i++) {row += '<td>' + ShowLabel[i] + '</td>';}//换行excel += row + '</tr>';//设置数据for (let i = 0; i < (table.length)/2; i++) {console.log("遍历了"+i+"次")let row = '<tr>';for (let index in table[i]) {let value = table[i][index];if (index === 'imei') {// 当数字超过一定长度就科学计数法可以使用style='mso-number-format:"\@"'// 这个属性指定某单元格的数据格式,避免Excel自动转换格式row += `<td style='mso-number-format:\"\\@\"'>${value}</td>`;} else {row += '<td>' + value + '</td>';}}excel += row + '</tr>';}excel += '</table>';let excelFile ="<html xmlns:o='urn:schemas-microsoft-com:office:office' xmlns:x='urn:schemas-microsoft-com:office:excel' xmlns='http://www.w3.org/TR/REC-html40'>";excelFile +='<meta http-equiv="content-type" content="application/vnd.ms-excel; charset=UTF-8">';excelFile += '<meta http-equiv="content-type" content="application/vnd.ms-excel';excelFile += '; charset=UTF-8">';excelFile += '<head>';excelFile += '<!--[if gte mso 9]>';excelFile += '<xml>';excelFile += '<x:ExcelWorkbook>';excelFile += '<x:ExcelWorksheets>';excelFile += '<x:ExcelWorksheet>';excelFile += '<x:Name>';excelFile += '{worksheet}';excelFile += '</x:Name>';excelFile += '<x:WorksheetOptions>';excelFile += '<x:DisplayGridlines/>';excelFile += '</x:WorksheetOptions>';excelFile += '</x:ExcelWorksheet>';excelFile += '</x:ExcelWorksheets>';excelFile += '</x:ExcelWorkbook>';excelFile += '</xml>';excelFile += '<![endif]-->';excelFile += '</head>';excelFile += '<body>';excelFile += excel;excelFile += '</body>';excelFile += '</html>';let uri = 'data:application/vnd.ms-excel;charset=utf-8,' + encodeURIComponent(excelFile);let link = document.createElement('a');link.href = uri;link.style = 'visibility:hidden';link.download = '表格下载.xls';document.body.appendChild(link);link.click();document.body.removeChild(link);console.log("下载成功");}

效果截图:
在这里插入图片描述

http://www.khdw.cn/news/50934.html

相关文章:

  • 如何做好网站推广百度客服转人工
  • 四川高速公路建设开发集团有限公司网站南京seo网站优化
  • 如何快速用手机做网站微信搜一搜seo优化
  • 百度智能门户建站怎么样免费建站平台哪个好
  • wordpress商城多重分类seo超级外链工具免费
  • 网站app服务器租用百度网盘客服人工电话95188
  • 网站logo制作软件seo在线诊断工具
  • 网站权重多少4缅甸今日新闻
  • 外贸b2c网站如何做推广seo的优化技巧和方法
  • 网站视频播放器用什么做的有效的网络推广
  • 怎么做有优惠券的网站代做网页设计平台
  • 电子商务网站建设合同标准范文优化大师卸载不了
  • 如何做切片网站站长工具域名查询
  • 鹤山网站建设网站优化招聘
  • 广点通seo工具下载
  • 上海高端网站建设服务腾讯云服务器
  • wordpress音乐刷新北京云无限优化
  • 杭州哪里做网站好查域名网站
  • 杭州网站建设官方蓝韵网络湛江百度seo公司
  • wordpress视频博客郑州seo培训班
  • 动漫制作专业在广西哪所院校最强seo的研究对象
  • 济南建站公司哪有网络营销推广方案整合
  • 江苏省建设工程信息网官网沈阳seo推广
  • 如何进行网站营销seo包年优化平台
  • 上海网站建设多少娄底seo
  • 太原网站建设加q.479185700网站域名备案信息查询
  • 学多久可以做网站 知乎关键词挖掘爱站网
  • 新乡做网站公司电话吴中seo网站优化软件
  • 做钓鱼网站教程视频教程山西百度推广开户
  • 网站商务通登陆不上网页是怎么制作的