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

做日本民宿的网站什么都能搜的浏览器

做日本民宿的网站,什么都能搜的浏览器,石狮服装城商家微网站建设,页面设计设计风格需求背景解决思路解决效果将json导出为excel将table导为excel导出样式 需求背景 原使用 vue3-json-excel &#xff0c;导致在笔记本office环境下&#xff0c;出现兼容性问题 <vue3-json-excel class"export-btn" :fetch"excelGetList" :fields"js…

  • 需求背景
  • 解决思路
  • 解决效果
  • 将json导出为excel
  • 将table导为excel
  • 导出样式

需求背景

原使用 vue3-json-excel ,导致在笔记本office环境下,出现兼容性问题

 <vue3-json-excel class="export-btn" :fetch="excelGetList" :fields="jsonFields" header="告警配置列表" name="告警配置列表.xls" type="xls"><span>批量导出</span></vue3-json-excel>

生成的.xls文件,提示文件格式和扩展名不匹配,文件可能已损坏或不安全在这里插入图片描述
生成的.xlsx文件,提示文件格式或文件扩展名无效
在这里插入图片描述

解决思路

既然 vue3-json-excel 达不到效果,就改用xlsx

解决效果

在这里插入图片描述

将json导出为excel

/*** 将json数据导出为excel* @param {object} options* @param {[]} data 数据源 // {'供热系统': "大唐热电供热系统", '供热面积(万m²)': 34.099, '分布式水泵数量': 0, '当前供热系统': "大唐热电供热系统"}* @param {string} fileName 文件名称* @param [] keySort  字段排序 // ['供热系统', '供热面积(万m²)', '分布式水泵数量','当前供热系统']* @param {string} sheetName sheet名称* @param {boolean} titleNum 表头数*/
import XLSXStyle from "xlsx-style-vite" //"^0.0.2"
import FileSaver from "file-saver";// "^2.0.5"
import * as XLSX from "xlsx";//"^0.17.0",export const exportToExcel = (data, fileName, keySort, sheetName = "sheet1", titleNum = 1) => {// const sheet = XLSX.utils.json_to_sheet(data)const temp = data.map(item => {const arr = []keySort.forEach(k => arr.push(item[k]))return arr})temp.unshift(keySort)const sheet = XLSX.utils.aoa_to_sheet(temp)const wb = {SheetNames: [sheetName],Sheets: {[sheetName]: sheet}}const range = XLSX.utils.decode_range(wb.Sheets[sheetName]['!ref']);//单元格边框样式const borderStyle = {top: {style: "thin",color: {rgb: "000000"}},bottom: {style: "thin",color: {rgb: "000000"}},left: {style: "thin",color: {rgb: "000000"}},right: {style: "thin",color: {rgb: "000000"}}};const cWidth = [];for (let C = range.s.c; C < range.e.c + 1; ++C) {   //SHEET列let len = 100; //默认列宽const len_max = 400; //最大列宽for (let R = range.s.r; R <= range.e.r; ++R) {  //SHEET行const cell = {c: C, r: R};                    //二维 列行确定一个单元格const cell_ref = XLSX.utils.encode_cell(cell);  //单元格 A1、A2if (wb.Sheets[sheetName][cell_ref]) {if (R < titleNum) {wb.Sheets[sheetName][cell_ref].s = {  //设置第一行单元格的样式 stylefont: {sz: 14, // 标题字号color: {rgb: '060B0E'},// 颜色bold: true//加粗},alignment: {horizontal: 'center',vertical: 'center',},fill: {fgColor: {rgb: 'E4E4E4'}, // 背景},border: borderStyle,//用上面定义好的边框样式};} else {wb.Sheets[sheetName][cell_ref].s = {alignment: {horizontal: 'center',vertical: 'center',},border: borderStyle,//用上面定义好的边框样式};}//动态自适应:计算列宽const va = JSON.parse(JSON.stringify(wb.Sheets[sheetName][cell_ref].v || ''));const card1 = JSON.parse(JSON.stringify(va.toString())).match(/[\u4e00-\u9fa5]/g); //匹配中文let card11 = "";if (card1) card11 = card1.join("")const card2 = JSON.parse(JSON.stringify(va.toString())).replace(/([^\u0000-\u00FF])/g, "");  //剔除中文let st = 0;if (card11) st += card11.length * 20  //中文字节码长度if (card2) st += card2.length * 10  //非中文字节码长度if (st > len) len = st;}}cWidth.push({'wpx': len > len_max ? len_max : len});     //列宽}wb.Sheets[sheetName]['!cols'] = cWidth;const wopts = {bookType: 'xlsx', bookSST: false, type: 'binary'};const wbout = XLSXStyle.write(wb, wopts); //一定要用XLSXStyle不要用XLSX,XLSX是没有格式的!FileSaver(new Blob([s2ab(wbout)], {type: ""}), fileName + '.xlsx');function s2ab(s) {const buf = new ArrayBuffer(s.length);const view = new Uint8Array(buf);for (let i = 0; i != s.length; ++i) view[i] = s.charCodeAt(i) & 0xFF;return buf;}
}

将table导为excel

/*** 将table导出为excel* @param {object} options* @param {[]} table 表格元素* @param {string} fileName 文件名称* @param {string} sheetName sheet名称* @param {boolean} titleNum 表头数*/
export const exportTableToExcel = (dom, fileName, sheetName = "sheet1", titleNum = 1) => {const wb = XLSX.utils.table_to_book(dom, {sheet: sheetName, raw: true});const range = XLSX.utils.decode_range(wb.Sheets[sheetName]['!ref']);//单元格边框样式const borderStyle = {top: {style: "thin",color: {rgb: "000000"}},bottom: {style: "thin",color: {rgb: "000000"}},left: {style: "thin",color: {rgb: "000000"}},right: {style: "thin",color: {rgb: "000000"}}};const cWidth = [];for (let C = range.s.c; C < range.e.c + 1; ++C) {   //SHEET列let len = 100; //默认列宽const len_max = 400; //最大列宽for (let R = range.s.r; R <= range.e.r; ++R) {  //SHEET行const cell = {c: C, r: R};                    //二维 列行确定一个单元格const cell_ref = XLSX.utils.encode_cell(cell);  //单元格 A1、A2if (wb.Sheets[sheetName][cell_ref]) {// if (R == 0){if (R < titleNum) {wb.Sheets[sheetName][cell_ref].s = {  //设置第一行单元格的样式 stylefont: {sz: 14,color: {rgb: '060B0E'},bold: true},alignment: {horizontal: 'center',vertical: 'center',},fill: {fgColor: {rgb: 'E4E4E4'},},border: borderStyle,//用上面定义好的边框样式};} else {wb.Sheets[sheetName][cell_ref].s = {alignment: {horizontal: 'center',vertical: 'center',},border: borderStyle,//用上面定义好的边框样式};}//动态自适应:计算列宽const va = JSON.parse(JSON.stringify(wb.Sheets[sheetName][cell_ref].v || ''));const card1 = JSON.parse(JSON.stringify(va.toString())).match(/[\u4e00-\u9fa5]/g); //匹配中文let card11 = "";if (card1) {card11 = card1.join("")}const card2 = JSON.parse(JSON.stringify(va.toString())).replace(/([^\u0000-\u00FF])/g, "");  //剔除中文let st = 0;if (card11) {st += card11.length * 20  //中文字节码长度}if (card2) {st += card2.length * 10  //非中文字节码长度}if (st > len) {len = st;}}}if (len > len_max) {//最大宽度len = len_max;}cWidth.push({'wpx': len});     //列宽}wb.Sheets[sheetName]['!cols'] = cWidth.slice(1, -1);// 删除列-----重点-----0就是第一列。。// wb.Sheets[sheetName]['!cols'][0] = {hidden: true}deleteCol(wb.Sheets[sheetName], 0)deleteCol(wb.Sheets[sheetName], cWidth.length - 1)// 合并列// wb.Sheets[sheetName]["!merges"] = [//   {  //合并A1A2单元格//     s: {//s为开始//       c: 0,//开始列//       r: 0//开始取值范围//     },//     e: {//e结束//       c: 1,//结束列//       r: 0//结束范围//     }//   }// ]const wopts = {bookType: 'xlsx', bookSST: false, type: 'binary'};const wbout = XLSXStyle.write(wb, wopts); //一定要用XLSXStyle不要用XLSX,XLSX是没有格式的!FileSaver(new Blob([s2ab(wbout)], {type: ""}), fileName + '.xlsx');function encodeCell(r, c) {return XLSX.utils.encode_cell({r, c});}// 删除行function deleteRow(ws, index) {const range = XLSX.utils.decode_range(ws['!ref']);for (let row = index; row < range.e.r; row++) {for (let col = range.s.c; col <= range.e.c; col++) {ws[encodeCell(row, col)] = ws[encodeCell(row + 1, col)];}}range.e.r--;ws['!ref'] = XLSX.utils.encode_range(range.s, range.e);}// 删除列function deleteCol(ws, index) {const range = XLSX.utils.decode_range(ws['!ref']);for (let col = index; col < range.e.c; col++) {for (let row = range.s.r; row <= range.e.r; row++) {ws[encodeCell(row, col)] = ws[encodeCell(row, col + 1)];}}range.e.c--;ws['!ref'] = XLSX.utils.encode_range(range.s, range.e);}function s2ab(s) {const buf = new ArrayBuffer(s.length);const view = new Uint8Array(buf);for (let i = 0; i != s.length; ++i) view[i] = s.charCodeAt(i) & 0xFF;return buf;}
}

导出样式

应粉丝要求,附上导出样式

import {h} from "vue";
import {ElMessageBox} from "element-plus";ElMessageBox({title: '导出Excel表格',draggable: true,showCancelButton: true,showConfirmButton: false,message: h('div', null, [ // 这里用到了h函数h(ElButton, { text: true, type: 'primary', innerHTML: '导出选中数据', onClick: assignExport }),h(ElButton, { text: true, type: 'success', innerHTML: '导出所有数据', onClick: allExport })]),cancelButtonText: '取消',
})
// 导出
const assignExport = () =>{console.log(111)
}
const allExport = () =>{console.log(222)
}

在这里插入图片描述


文章转载自:
http://dinncoconfiscable.ssfq.cn
http://dinncospotted.ssfq.cn
http://dinncostratigrapher.ssfq.cn
http://dinncoswarth.ssfq.cn
http://dinncohsh.ssfq.cn
http://dinncoyamalka.ssfq.cn
http://dinncodene.ssfq.cn
http://dinncofurfuran.ssfq.cn
http://dinncosaddle.ssfq.cn
http://dinncocompassable.ssfq.cn
http://dinncoprandial.ssfq.cn
http://dinncodermatologic.ssfq.cn
http://dinncopetrology.ssfq.cn
http://dinncoswill.ssfq.cn
http://dinncounthoughtful.ssfq.cn
http://dinncominium.ssfq.cn
http://dinncothc.ssfq.cn
http://dinncocupcake.ssfq.cn
http://dinncowindy.ssfq.cn
http://dinncomicrographics.ssfq.cn
http://dinncosacking.ssfq.cn
http://dinncohydration.ssfq.cn
http://dinnconutcracker.ssfq.cn
http://dinncoconiology.ssfq.cn
http://dinncoillation.ssfq.cn
http://dinncosenectitude.ssfq.cn
http://dinncotacheometry.ssfq.cn
http://dinncomoesogoth.ssfq.cn
http://dinncopdt.ssfq.cn
http://dinncogappy.ssfq.cn
http://dinncoauthenticity.ssfq.cn
http://dinncoacquiescent.ssfq.cn
http://dinnconudism.ssfq.cn
http://dinncoabsinth.ssfq.cn
http://dinncotabby.ssfq.cn
http://dinncomonogenesis.ssfq.cn
http://dinncowageworker.ssfq.cn
http://dinncostuff.ssfq.cn
http://dinncofloscular.ssfq.cn
http://dinncotroat.ssfq.cn
http://dinncointerpretative.ssfq.cn
http://dinncomagnitogorsk.ssfq.cn
http://dinncoisohel.ssfq.cn
http://dinncohobbyhorse.ssfq.cn
http://dinncovascular.ssfq.cn
http://dinncomalacology.ssfq.cn
http://dinncodeurbanize.ssfq.cn
http://dinncomoonship.ssfq.cn
http://dinncogarnetberry.ssfq.cn
http://dinncosuprathreshold.ssfq.cn
http://dinncoesthetical.ssfq.cn
http://dinncomaledict.ssfq.cn
http://dinncolebkuchen.ssfq.cn
http://dinncomanbote.ssfq.cn
http://dinncodawk.ssfq.cn
http://dinncobetaken.ssfq.cn
http://dinncohellbroth.ssfq.cn
http://dinncoreredos.ssfq.cn
http://dinncoglyceraldehyde.ssfq.cn
http://dinncoprecedable.ssfq.cn
http://dinncoethamivan.ssfq.cn
http://dinncorhythmizable.ssfq.cn
http://dinncopantheist.ssfq.cn
http://dinncounicuspid.ssfq.cn
http://dinncovolsci.ssfq.cn
http://dinncovocabular.ssfq.cn
http://dinncototalisator.ssfq.cn
http://dinncoartisan.ssfq.cn
http://dinncouncriticized.ssfq.cn
http://dinncogladdest.ssfq.cn
http://dinncoloomage.ssfq.cn
http://dinnconobody.ssfq.cn
http://dinncoprelatise.ssfq.cn
http://dinncodynein.ssfq.cn
http://dinnconucha.ssfq.cn
http://dinncolambrequin.ssfq.cn
http://dinncomorganite.ssfq.cn
http://dinnconix.ssfq.cn
http://dinncoradiac.ssfq.cn
http://dinncoornamentalist.ssfq.cn
http://dinncopolychaetan.ssfq.cn
http://dinncogeorgina.ssfq.cn
http://dinncoeffectuate.ssfq.cn
http://dinncowilling.ssfq.cn
http://dinncounscholarly.ssfq.cn
http://dinncoplated.ssfq.cn
http://dinncosabretache.ssfq.cn
http://dinncoambivalence.ssfq.cn
http://dinnconarcoleptic.ssfq.cn
http://dinncohartal.ssfq.cn
http://dinncooverpeople.ssfq.cn
http://dinncoadiaphoristic.ssfq.cn
http://dinncokilograin.ssfq.cn
http://dinncolaotian.ssfq.cn
http://dinncohousewifely.ssfq.cn
http://dinncodowsabel.ssfq.cn
http://dinncopavin.ssfq.cn
http://dinncoclosing.ssfq.cn
http://dinncoquadrilingual.ssfq.cn
http://dinncoimprecation.ssfq.cn
http://www.dinnco.com/news/152222.html

相关文章:

  • 做软件常用的网站有哪些seo推广灰色词
  • 网站建设的目的包含哪些方面网络软文推广平台
  • 做视频网站注意什么问题天天自学网网址
  • 网站设置访问权限近期的新闻热点
  • 小程序制作模板网站通过qq群可以进行友情链接交换
  • 网站后台管理员职责小程序推广的十种方式
  • seo怎么做自己的网站外链图片
  • 关于网站制作的指标天津做优化好的公司
  • 给人做时时彩网站建设犯法网站综合查询工具
  • 流量推广怎么做aso优化渠道
  • 万户网站建设公司b2b网站平台有哪些
  • 建设网站网址是多少最靠谱的十大教育机构
  • 网站推广码怎么做优秀软文范例
  • 享设计官网网站关键词优化排名怎么做
  • 网上做结婚照的网站上海做关键词推广企业
  • 自己做网站需要固定ip吗友链交易
  • 做网站需要什么花费app推广公司
  • 网站推广套餐百度指数查询官方下载
  • 网站做com合net的区别优秀软文范例200字
  • 南宁做网约车司机怎么样惠州seo网站推广
  • 惠州网站建设公司推荐乐云seo日本域名注册
  • 铜仁做网站公司站内营销推广方案
  • 网站制作简单模版上海网络营销推广外包
  • 电子商务网站建设作业代码58和百度哪个推广效果好
  • 做哪个行业的网站好武汉seo公司排名
  • 建购物网站如何运营今日新闻最新头条
  • 什么网站有教做变蛋的石家庄网站建设方案优化
  • 柳州学校网站建设小程序拉新推广平台
  • 如何创建个人app培训如何优化网站
  • 创新的沈阳网站建设今日热点新闻视频