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的数据,后续其他功能可以在文档里查找。

相关推荐
zhanlang0217几秒前
HTML 零基础入门到企业实战【第七章 7.2】form 标签属性:action、method、name、target 详解
前端·html
涛涛ing33 分钟前
面试了20个前端,我发现高薪的都不怎么拼“底层原理”
前端
翼帆1 小时前
我用 AI 复刻了 CodeTank,重温代码坦克
前端·javascript·开源·ai编程·游戏开发·codetank
有趣的老凌1 小时前
学习MarkDown笔记
前端
掘金者阿豪2 小时前
数据库选型到底应该看什么?从业务需求到技术架构的实践分析
前端·后端
徐小夕3 小时前
万字拆解:零向量库、无模型微调,SAG2 凭什么刷新多跳问答 SOTA
前端·vue.js·github
用户0332126663673 小时前
使用 Python 删除 Excel 中的空白行或空白列
python·excel
黑土豆3 小时前
用 drawink 给业务页面加一层画板:从网页批注到无限板书
前端·javascript·github
恋猫de小郭4 小时前
Flutter 3.50.0 Release 的第一个崩溃,修好了,还没 hotfix
android·前端·flutter
IT_陈寒18 小时前
Redis那个过期删除策略,差点让我线上崩了
前端·人工智能·后端