Luckysheet类似excel的在线表格(vue)

参考文档:快速上手 | Luckysheet文档

一、引入

在vue项目的public文件夹下的index.html的<head>标签里面引入

html 复制代码
    <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>

二、页面应用

2.1、视图中定义一个容器

html 复制代码
<template>
  <div>
    <div @click="DateShow">Excel在线编辑</div>
    <div
      id="luckysheetContainer"
      style="margin: 0px; padding: 0px; width: 60%; height: 80vh"
    ></div>
  </div>
</template>

2.2、初始化容器

javascript 复制代码
  mounted() {
    let dataS;
    dataS = [
      [
        {
          ct: {
            fa: "General",
            t: "g",
          },
          m: "节次",
          v: "节次",
          id: "111",
        },
        {
          ct: {
            fa: "General",
            t: "g",
          },
          m: " 开始时间",
          v: " 开始时间",
        },
        {
          ct: {
            fa: "General",
            t: "g",
          },
          m: " 结束时间",
          v: " 结束时间",
        },
        {
          ct: {
            fa: "General",
            t: "g",
          },
          m: "星期一",
          v: "星期一",
        },
        {
          ct: {
            fa: "General",
            t: "g",
          },
          m: "星期二",
          v: "星期二",
        },
        {
          ct: {
            fa: "General",
            t: "g",
          },
          m: "星期三",
          v: "星期三",
        },
        {
          ct: {
            fa: "General",
            t: "g",
          },
          m: "星期四",
          v: "星期四",
        },
      ],
      [
        {
          ct: {
            fa: "General",
            t: "g",
          },
          m: "1",
          v: "1",
        },
        {
          ct: {
            fa: "General",
            t: "g",
          },
          m: "12:00",
          v: "12:00",
        },
        {
          ct: {
            fa: "General",
            t: "g",
          },
          m: "14:00",
          v: "14:00",
        },
      ],
      [
        {
          ct: {
            fa: "General",
            t: "g",
          },
          m: "2",
          v: "2",
        },
        {
          ct: {
            fa: "General",
            t: "g",
          },
          m: "15:00",
          v: "15:00",
        },
        {
          ct: {
            fa: "General",
            t: "g",
          },
          m: "18:00",
          v: "18:00",
        },
      ],
    ];
    // 获取容器元素
    // const container = document.getElementById("luckysheetContainer");
    // console.log("container", container);
    // 将数据渲染到LuckySheet表格
    window.luckysheet.create({
      container: "luckysheetContainer", // DOM容器的ID
      title: "电子表格", // 工作簿名称
      lang: "zh", // 设定表格的语言
      // showtoolbarConfig: {
      //   print: false, // 工具栏隐藏打印按钮
      // },
      // showsheetbarConfig: {
      //   add: false, // 底部sheet页隐藏新增sheet按钮
      //   menu: false, // 底部sheet页隐藏管理按钮
      // },
      // sheetRightClickConfig: {
      //   hide: false, // 隐藏,取消隐藏
      //   move: false, // 向左移,向右移
      // },
    });
    this.sheetfile = window.luckysheet.getluckysheetfile();
    this.sheetfile[0].data = dataS;
    console.log(dataS, "this.sheetfile", this.sheetfile);
  },

可以自行编辑数据,也可以将数据渲染上去进行展示与二次编辑

2.3、效果展示

2.4、数据处理

javascript 复制代码
    DateShow() {
      this.sheetfile = window.luckysheet.getluckysheetfile();
      console.log("this.sheetfile", this.sheetfile);
const filteredArr = this.sheetfile[0].data.filter((row) =>
     row.some((cell) => cell !== null)
     );
     const filteredArr2 = filteredArr.map((row) =>
     row.filter((cell) => cell !== null)
      );
console.log("value", filteredArr2);
    },

上面的"filteredArr2"可以拿到表格中不为null的数据,后续其他功能可以在文档里查找。

相关推荐
苏打水com几秒前
第二十篇:Day58-60 前端性能优化进阶——从“能用”到“好用”(对标职场“体验优化”需求)
前端·css·vue·html·js
沛沛老爹2 分钟前
Web开发者快速上手AI Agent:基于提示工程的旅游攻略系统实战
前端·人工智能·ai·agent·react·旅游攻略
qq_172805595 分钟前
Modbus Server数据采集Web之Server端模拟功能
前端·后端·golang·modbus
LYFlied7 分钟前
【每日算法】LeetCode 739. 每日温度:从暴力遍历到单调栈的优雅解决
前端·算法·leetcode·面试·职场和发展
烛阴12 分钟前
深入 C# 字符串世界:基础语法、常用方法与高阶实战
前端·c#
这是个栗子14 分钟前
【前端知识点总结】关于基地址baseURL的介绍
前端·axios·baseurl
豆苗学前端16 分钟前
Vue 2 vs Vue 3 响应式原理深度对比(源码理解层面,吊打面试官)
前端·javascript·面试
无名修道院18 分钟前
XSS 跨站脚本攻击:3 种类型(存储型 / 反射型 / DOM 型)原理以 DVWA 靶场举例
前端·网络安全·渗透测试·代码审计·xss
代码猎人20 分钟前
CSS可继承属性和不可继承属性有哪些
前端
wtsolutions20 分钟前
Sheet-to-Doc: Automate Document Generation with Excel Data and Word Templates
word·excel·wtsolutions