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

单位网站等级保护必须做吗搜索引擎大全网站

单位网站等级保护必须做吗,搜索引擎大全网站,网站icp 备案查询,学网站建设怎么样文章目录 功能简介简单代码实现效果参考 功能简介 通过LuckyExcel的transformExcelToLucky方法, 我们可以把一个文件直接转成LuckySheet需要的json字符串, 之后我们就可以用LuckySheet预览excelLuckyExcel只能解析xlsx格式的excel文件,因此对…

文章目录

    • 功能简介
    • 简单代码实现
    • 效果
    • 参考

功能简介

  1. 通过LuckyExcel的transformExcelToLucky方法, 我们可以把一个文件直接转成LuckySheet需要的json字符串, 之后我们就可以用LuckySheet预览excel
  2. LuckyExcel只能解析xlsx格式的excel文件,因此对于xls和csv的格式,我们需要通过XLSX来转化成xlsx格式,但在转化过程中会丢失样式
  3. 对于excel中存在很多的空白行,在显示的时候可能会出现卡顿,所以我们需要将过多的空白行移除

简单代码实现

<!DOCTYPE html>
<html lang="en">
<head><meta charset="UTF-8"><title>Excel File Upload and Preview with Luckysheet</title>
</head>
<body><!-- 文件上传控件 -->
<input type="file" id="fileUpload"/><!-- Luckysheet 的容器 -->
<div id="luckysheet" style="position: relative; width: 100%; height: 500px;"></div>
<script src="https://cdn.jsdelivr.net/npm/xlsx/dist/xlsx.full.min.js"></script><link rel='stylesheet' href='https://cdn.jsdelivr.net/npm/luckysheet@latest/dist/plugins/css/pluginsCss.css'/>
<link rel='stylesheet' href='https://cdn.jsdelivr.net/npm/luckysheet@latest/dist/plugins/plugins.css'/>
<link rel='stylesheet' href='https://cdn.jsdelivr.net/npm/luckysheet@latest/dist/css/luckysheet.css'/>
<link rel='stylesheet' href='https://cdn.jsdelivr.net/npm/luckysheet@latest/dist/assets/iconfont/iconfont.css'/>
<script src="https://cdn.jsdelivr.net/npm/luckysheet@latest/dist/plugins/js/plugin.js"></script>
<script src="https://cdn.jsdelivr.net/npm/luckysheet@latest/dist/luckysheet.umd.js"></script><script src="https://cdn.jsdelivr.net/npm/luckyexcel/dist/luckyexcel.umd.js"></script><script>const _xlsxType = 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet';const  _xlsType = 'application/vnd.ms-excel';const  _csvType = 'text/csv';//如果后端是以流的方式返回,可以调用这个方法const handleExcel = (res, fileName) => {const file = getExcelFile(res, fileName);handleExcelFile(file);}// 获取Excel文件const getExcelFile = (res, fileName) => {// 根据文件后缀名判断文件类型if (fileName.endsWith('.xlsx')) {return new File([res], fileName, {type: _xlsxType});} else if (fileName.endsWith('.xls')) {return new File([res], fileName, {type: _xlsType});} else if (fileName.endsWith('.csv')) {return new File([res], fileName, {type: _csvType});} else {throw new Error("Unsupported file type");}}// 处理Excel文件const handleExcelFile = (file) => {const fileName = file.name;// 根据文件后缀名判断文件类型并进行处理if (fileName.endsWith('.xlsx')) {console.log("handle excel for xlsx type..", fileName);handleExcelForXlsxType(file, fileName);} else if (fileName.endsWith('.xls') || fileName.endsWith('.csv')) {console.log("handle excel for xls or csv type..", fileName);handleExcelForXlsAndCsvType(file, fileName);} else {throw new Error("Unsupported file type");}}// 处理xlsx类型的Excel文件const handleExcelForXlsxType = (file, fileName) => {const reader = new FileReader();reader.onload = function (event) {const data = new Uint8Array(event.target.result);const workbook = XLSX.read(data, {type: 'array'});// 获取Excel文件中的最大行数let maxRowCountFromExcel = getMaxRowCountFromExcel(workbook);// 如果行数大于100000,则处理Excel文件中的空行if (maxRowCountFromExcel > 1000000) {console.log("excel file has too many blank row..", maxRowCountFromExcel);handleBlankRowForExcelWithTooManyBlankRow(workbook);const xlsxFile = toXlsxExcelFile(workbook, fileName);createLuckySheet(xlsxFile);} else {createLuckySheet(file);}};reader.readAsArrayBuffer(file);}// 处理xls和csv类型的Excel文件const handleExcelForXlsAndCsvType = (file, fileName) => {const reader = new FileReader();// 读取文件完成后的回调函数reader.onload = function (event) {const data = new Uint8Array(event.target.result);// 读取Excel文件内容const workbook = XLSX.read(data, {type: 'array'});// 将Excel文件转换为xlsx类型const xlsxFile = toXlsxExcelFile(workbook, fileName);// 处理xlsx类型的Excel文件handleExcelForXlsxType(xlsxFile, fileName);};// 以ArrayBuffer的形式读取文件reader.readAsArrayBuffer(file);}/ 创建Luckysheetconst createLuckySheet = (file) => {// 销毁已存在的Luckysheetwindow.luckysheet.destroy();// 将Excel文件转换为Luckysheet的jsonLuckyExcel.transformExcelToLucky(file, function (exportJson, luckysheetfile) {if (exportJson.sheets == null || exportJson.sheets.length === 0) {throw new Error("Failed to load excel file");}// 创建Luckysheet的配置项const options = {container: 'luckysheet',data: exportJson.sheets, // title: exportJson.info.name,// userInfo: exportJson.info.name.creator,column: 10,row: 10,showinfobar: false,sheetFormulaBar: true,showConfigWindowResize: false};// 创建Luckysheetwindow.luckysheet.create(options);});}// 获取Excel文件中的最大行数const getMaxRowCountFromExcel = (workbook) => {let maxRowCount = 0;if (workbook.SheetNames == null || workbook.SheetNames.length === 0) {return maxRowCount;}// 遍历每个sheet,获取最大行数workbook.SheetNames.forEach(sheetName => {const worksheet = workbook.Sheets[sheetName];if (worksheet['!ref'] === undefined) {return;}const range = XLSX.utils.decode_range(worksheet['!ref']);maxRowCount = maxRowCount + range.e.r;});console.log("max:", maxRowCount)return maxRowCount;}const reduceBlankRow = (row, range, worksheet) => {// 从给定的行开始,向上遍历到工作表的起始行while (row > range.s.r) {// 假设当前行是空的let allEmpty = true;// 遍历当前行的所有列for (let col = range.s.c; col <= range.e.c; col++) {// 获取当前单元格的引用const cell_ref = XLSX.utils.encode_cell({c: col, r: row});// 如果当前单元格不为空,则将allEmpty设置为false并跳出循环if (worksheet[cell_ref]) {allEmpty = false;break;}}// 如果当前行是空的,则将行数减一,否则跳出循环if (allEmpty) {row--;} else {break;}}// 更新工作表范围的结束行range.e.r = row;// 更新工作表的范围引用worksheet['!ref'] = XLSX.utils.encode_range(range.s, range.e);}// 处理Excel文件中的空行const handleBlankRowForExcelWithTooManyBlankRow = (workbook) => {if (workbook.SheetNames == null || workbook.SheetNames.length === 0) {return;}// 遍历每个sheet,处理空行workbook.SheetNames.forEach(sheetName => {const worksheet = workbook.Sheets[sheetName];if (worksheet['!ref'] === undefined) {return;}const range = XLSX.utils.decode_range(worksheet['!ref']);let row = range.e.r;reduceBlankRow(row, range, worksheet);});}// 将Excel文件转换为xlsx类型const toXlsxExcelFile = (workbook, fileName) => {const newWorkbook = XLSX.write(workbook, {bookType: 'xlsx', type: 'binary'});const data = new Uint8Array(newWorkbook.length);for (let i = 0; i < newWorkbook.length; i++) {data[i] = newWorkbook.charCodeAt(i);}return new File([data], fileName, {type: _xlsxType});}// 文件上传控件的change事件处理函数document.getElementById('fileUpload').addEventListener('change', function (e) {// 获取上传的文件const file = e.target.files[0];// 处理Excel文件handleExcelFile(file);});</script></body>
</html>

效果

在这里插入图片描述

参考

https://juejin.cn/post/7211805251216031801
https://segmentfault.com/a/1190000043720845
https://juejin.cn/post/7232524757525659708
https://blog.csdn.net/q2qwert/article/details/130908294
https://www.cnblogs.com/ajaemp/p/12880847.html
https://blog.csdn.net/weixin_40775791/article/details/135409716
https://blog.csdn.net/u013113491/article/details/129106671


文章转载自:
http://wallsend.fcxt.cn
http://bulgy.fcxt.cn
http://hateless.fcxt.cn
http://interlaboratory.fcxt.cn
http://hyperosmolality.fcxt.cn
http://adenalgia.fcxt.cn
http://smally.fcxt.cn
http://sporades.fcxt.cn
http://acrimoniously.fcxt.cn
http://egyptian.fcxt.cn
http://mosso.fcxt.cn
http://vexillar.fcxt.cn
http://watchdog.fcxt.cn
http://further.fcxt.cn
http://foliate.fcxt.cn
http://autobiographic.fcxt.cn
http://arcifinious.fcxt.cn
http://rhabdomyosarcoma.fcxt.cn
http://excusingly.fcxt.cn
http://ridgepole.fcxt.cn
http://antedate.fcxt.cn
http://demiseason.fcxt.cn
http://cribble.fcxt.cn
http://illutation.fcxt.cn
http://alhambresque.fcxt.cn
http://mustache.fcxt.cn
http://indigenization.fcxt.cn
http://agonise.fcxt.cn
http://heister.fcxt.cn
http://kieselgur.fcxt.cn
http://celebrator.fcxt.cn
http://unbecoming.fcxt.cn
http://metier.fcxt.cn
http://mississippi.fcxt.cn
http://hymen.fcxt.cn
http://regge.fcxt.cn
http://inexpedient.fcxt.cn
http://coercionary.fcxt.cn
http://laryngectomize.fcxt.cn
http://filiation.fcxt.cn
http://meteoroid.fcxt.cn
http://taffety.fcxt.cn
http://cooner.fcxt.cn
http://commy.fcxt.cn
http://eloise.fcxt.cn
http://iodate.fcxt.cn
http://jarovize.fcxt.cn
http://phagun.fcxt.cn
http://subcellar.fcxt.cn
http://rheumatoid.fcxt.cn
http://aeger.fcxt.cn
http://inblowing.fcxt.cn
http://venous.fcxt.cn
http://asonant.fcxt.cn
http://lalapalooza.fcxt.cn
http://rencounter.fcxt.cn
http://dominancy.fcxt.cn
http://sucker.fcxt.cn
http://powerfully.fcxt.cn
http://inwoven.fcxt.cn
http://curbing.fcxt.cn
http://detox.fcxt.cn
http://liftback.fcxt.cn
http://musicomania.fcxt.cn
http://slippery.fcxt.cn
http://unstuffed.fcxt.cn
http://totipotency.fcxt.cn
http://grotesquerie.fcxt.cn
http://apologise.fcxt.cn
http://pornographic.fcxt.cn
http://lawyer.fcxt.cn
http://thermel.fcxt.cn
http://sackbut.fcxt.cn
http://intromittent.fcxt.cn
http://kuchen.fcxt.cn
http://semiconsciousness.fcxt.cn
http://briefless.fcxt.cn
http://noseguard.fcxt.cn
http://podite.fcxt.cn
http://marmalade.fcxt.cn
http://upholsterer.fcxt.cn
http://chime.fcxt.cn
http://elbowroom.fcxt.cn
http://stater.fcxt.cn
http://pulverization.fcxt.cn
http://ntfs.fcxt.cn
http://nixy.fcxt.cn
http://knitwork.fcxt.cn
http://ensorcel.fcxt.cn
http://cestoid.fcxt.cn
http://microinstruction.fcxt.cn
http://nuncupation.fcxt.cn
http://topiary.fcxt.cn
http://sitsang.fcxt.cn
http://transnatural.fcxt.cn
http://ventose.fcxt.cn
http://emigratory.fcxt.cn
http://pyophthalmia.fcxt.cn
http://arpa.fcxt.cn
http://scattergram.fcxt.cn
http://www.hrbkazy.com/news/63428.html

相关文章:

  • 重庆免费自助建站模板建网站设计
  • 怎么创建网站免费的百度在线咨询
  • 建成局网站建设seo学徒是做什么
  • 男女做那个视频网站室内设计网站
  • 厦门网站建设公司排行榜海外营销
  • 沂水住房与城乡建设局网站优化大师免费版下载
  • 惠州私人做网站联系人网页版百度云
  • 织梦cms怎样做网站陕西网站设计
  • 江苏城乡建设厅官方网站关键词是指什么
  • 无锡微网站制作广州网络优化最早的公司
  • 网站怎么才能被百度收录15个常见关键词
  • 租车网站制作方案网站seo优化是什么意思
  • 琼海做网站公司nba湖人最新新闻
  • 政府网站建设步骤怎样优化网站排名靠前
  • 哪些网站动效做的不错山东百搜科技有限公司
  • 有没有做相册的网站软文投稿平台有哪些
  • 有关网站建设的标题跨境电商平台
  • 广东 网站建设百度本地推广
  • 医院网站设计怎么做nba最新消息交易
  • 企业微信怎么下载朝阳区seo搜索引擎优化怎么样
  • 网络公司企业网站模板如何推广自己产品
  • 做配单ic去什么网站好sem是什么专业
  • 公司注册网上核名app外贸seo网站推广
  • 杭州 网站建设公司2024年阳性最新症状
  • 网站制作自己接单互联网广告销售
  • 重庆装修公司网站建设什么推广平台好
  • 网站账户上的余额分录怎么做十大教育培训机构排名
  • 深圳做网站联雅做一个网站
  • 如何做招聘网站长沙seo优化
  • h5 技术做健康类网站什么是网站推广策略