excel文件预览: luckyexcel+luckysheet

luckyexcel 使用

javascript 复制代码
npm i luckyexcel --save

luckysheet 使用 luckysheet文档

  1. 克隆Luckysheet源码到本地
javascript 复制代码
git clone https://github.com/dream-num/Luckysheet.git
  1. 安装依赖
javascript 复制代码
npm install
npm install gulp -g  
  1. 开发
javascript 复制代码
npm run dev
  1. 打包
javascript 复制代码
npm run build

本地引入

npm run build 后 dist 文件夹下的所有文件复制到vue项目的public目录下,然后在index.html文件中通过相对路径引入:

html 复制代码
<link rel='stylesheet' href='./plugins/css/pluginsCss.css' />
<link rel='stylesheet' href='./plugins/plugins.css' />
<link rel='stylesheet' href='./css/luckysheet.css' />
<link rel='stylesheet' href='./assets/iconfont/iconfont.css' />
<script src="./plugins/js/plugin.js"></script>
<script src="./luckysheet.umd.js"></script>

表格容器

html 复制代码
<div id="luckysheet" style="margin:0px;padding:0px;position:absolute;width:100%;height:100%;left: 0px;top: 0px;"></div>

1.预览本地文件/后端返回文件流文件

javascript 复制代码
      // 获取文件流
      const token = '用户token'
      axios.get('你的接口地址', {
        headers: { 'Token': token },
        responseType: 'blob',
        params: {
          // 参数
        }
      }).then((response) => {
        // 将获取到的文件对象传递给 uploadExcel 方法
        const file = new File([response.data], 'XXX.xlsx', { type: response.data.type });
      })
      .catch((error) => {
        console.error('文件获取失败:', error);
      })
javascript 复制代码
import LuckyExcel from 'luckyexcel'

LuckyExcel.transformExcelToLucky(file, (exportJson, luckysheetfile) => {
   if(exportJson.sheets==null || exportJson.sheets.length==0){
       console.log("文件读取失败!");
       return;
   }
   // 销毁原来的表格
   luckysheet.destroy();
   // 重新创建新表格
   exportJson.sheets[0].defaultRowHeight = 25  // 行高
   luckysheet.create({
      container: 'luckysheet', // 设定DOM容器的id
      column: 15,
      row: 30,
      showtoolbar: false, // 是否显示工具栏
      showinfobar: false, // 是否显示顶部信息栏
      showsheetbarConfig:{
          add: false,
          menu: false,
      },
      sheetRightClickConfig: {
          delete: false, // 删除
          copy: false, // 复制
          rename: false, //重命名
          color: false, //更改颜色
          hide: false, //隐藏,取消隐藏
          move: false, //向左移,向右移
       },
       //自定义单元格右键菜单
       cellRightClickConfig: {
          copy: false, // 复制
          copyAs: false, // 复制为
          paste: false, // 粘贴
          insertRow: false, // 插入行
          insertColumn: false, // 插入列
          deleteRow: false, // 删除选中行
          deleteColumn: false, // 删除选中列
          deleteCell: false, // 删除单元格
          hideRow: false, // 隐藏选中行和显示选中行
          hideColumn: false, // 隐藏选中列和显示选中列
          rowHeight: false, // 行高
          columnWidth: false, // 列宽
          clear: false, // 清除内容
          matrix: false, // 矩阵操作选区
          sort: false, // 排序选区
          filter: false, // 筛选选区
          chart: false, // 图表生成
          image: false, // 插入图片
          link: false, // 插入链接
          data: false, // 数据验证
          cellFormat: false // 设置单元格格式
       },
       showstatisticBar: false, // 是否显示底部计数栏
       sheetBottomConfig: false, // sheet页下方的添加行按钮和回到顶部按钮配置
       allowEdit: false, // 是否允许前台编辑
       enableAddRow: false, // 是否允许增加行
       enableAddCol: false, // 是否允许增加列
       sheetFormulaBar: false, // 是否显示公式栏
       enableAddBackTop: false, //返回头部按钮
       data: exportJson.sheets, //表格内容
       title: exportJson.info.name, //表格标题
    });
});

2.excel文件地址

javascript 复制代码
LuckyExcel.transformExcelToLuckyByUrl(excelUrl, excelName, (exportJson, luckysheetfile) => {})
相关推荐
小葱炖豆腐10 小时前
python绘制excel折线图
python·excel·numpy·pandas·matplotlib
cspttty21 小时前
2026年财务分析岗JD中的Excel、SQL、BI与业务分析要求
大数据·sql·excel
cspttty21 小时前
HR数字化校招准备路线:Excel、SQL、BI和AI工具怎么学
人工智能·sql·excel
鲲穹AI种草2 天前
Excel 表格批量处理与数据整理,多款表格工具能力客观记录
excel·表格处理
cspttty2 天前
2026秋招供应链分析师技能栈:SQL、Excel、BI与业务分析
数据库·sql·excel
Zzq_Fighting3 天前
Excel批量匹配数据
excel
E_ICEBLUE3 天前
Python 实现 Excel 转 Markdown,支持工作表、单元格区域和批量处理
python·excel·markdown·格式转换
拆房老料3 天前
ONLYOFFICE 集群部署实战:9.3 多实例方案与 9.4 架构变化
开源·word·excel·开源软件·ppt
ms365copilot3 天前
Excel Copilot挖掘数据洞察,不用精通函数也能做数据分析 (1)
数据分析·excel·copilot
babe小鑫3 天前
精算学专业秋招:Excel、SQL、R和Python应该先练什么
sql·r语言·excel