vue3+luckyexcel+php在线编辑excel文件

开发过程中,需要开发一个在线编辑excel文档的功能,找到了这个合适的组件

Luckysheet ,一款纯前端类似excel的在线表格,功能强大、配置简单、完全开源。

可以导入文档,预览、编辑、保存、导出等功能,可以满足大部分需求

第一步:需要先安装 vue3 运行下面三个安装命令

npm install exceljs -S 
npm install luckyexcel -S
npm install file-saver

第二步:前端部分index.html 加入引用代码

<link rel='stylesheet' href='/luckysheet/pluginsCss.css' />
      <link rel='stylesheet' href='/luckysheet/plugins.css' />
      <link rel='stylesheet' href='/luckysheet/luckysheet.css' />
      <link rel='stylesheet' href='/luckysheet/iconfont.css' />
      <script src="/luckysheet/plugin.js"></script>
      <script src="/luckysheet/luckysheet.umd.js"></script>

组件部分test.vue

<template>
  <div style="position: absolute; top: 0">
    <input id="uploadBtn" type="file" @change="loadExcel" />
    <button class="btn" @click="getExcel">后台数据</button>
    <span>Or文件:</span>

    <select v-model="selected" @change="selectExcel">
      <option disabled value="">Choose</option>
      <option v-for="option in options" :key="option.text" :value="option.value">
        {{ option.text }}
      </option>
    </select>
    <input class="inp" type="text" v-model="excelTitel">
    <button class="blueBtn" @click="editClicked">编辑</button>
    <button class="btn" @click="saveExcel">保存</button>
    <a href="javascript:void(0)" @click="downloadExcel">下载</a>
  </div>
  <div id="luckysheet"></div>
  <div v-show="isMaskShow" id="tip">Downloading</div>
</template>
test.vue   script代码部分
import { ref, onMounted } from 'vue'
import http from '@/assets/js/procure-http.js'
import { exportExcel } from '@/components/export'
import LuckyExcel from 'luckyexcel'

const isMaskShow = ref(false)
const selected = ref('')
const jsonData = ref({})
const excelTitel = ref('')
const congifdata = ref({
  container: 'luckysheet',
  title: "bi", // 工作簿名称
  lang: "zh", // 设定表格语言 国际化设置,允许设置表格的语言,支持中文("zh")和英文("en")
  allowCopy: false, // 是否允许拷贝
  showtoolbar: false, // 是否显示工具栏
  showinfobar: true, // 是否显示顶部信息栏
  showsheetbar: false, // 是否显示底部sheet页按钮
  showstatisticBar: false, // 是否显示底部计数栏
  sheetBottomConfig: false, // sheet页下方的添加行按钮和回到顶部按钮配置
  allowEdit: false, // 是否允许前台编辑
  enableAddRow: false, // 允许增加行
  enableAddCol: false, // 允许增加列
  userInfo: false, // 右上角的用户信息展示样式
  showRowBar: false, // 是否显示行号区域
  showColumnBar: false, // 是否显示列号区域
  sheetFormulaBar: false, // 是否显示公式栏
  enableAddBackTop: false,//返回头部按钮
  rowHeaderWidth: 0,//纵坐标
  columnHeaderHeight: 0,//横坐标
  showstatisticBarConfig: {
    count:false,
    view:false,
    zoom:false,
  },
  showsheetbarConfig: {
    add: false, //新增sheet
    menu: false, //sheet管理菜单
    sheet: false, //sheet页显示
  },
  forceCalculation: true,//强制计算公式
})
const options = ref([
  { text: 'Money Manager.xlsx', value: 'https://xxxxxx/storage/salarytemp/20231222/20231222162622.xlsx' },
  {text: 'Activity costs tracker.xlsx', value: 'https://xxxxxx/storage/salary/20231031/0f724adf33a2d3d0b95071b0c52fb711.xlsx'}
])

const loadExcel = (evt) => {
  const files = evt.target.files
  if (files == null || files.length == 0) {
    alert('No files wait for import')
    return
  }

  let name = files[0].name
  let suffixArr = name.split('.'),
      suffix = suffixArr[suffixArr.length - 1]
  if (suffix != 'xlsx') {
    alert('Currently only supports the import of xlsx files')
    return
  }
  LuckyExcel.transformExcelToLucky(files[0], function (exportJson, luckysheetfile) {
    if (exportJson.sheets == null || exportJson.sheets.length == 0) {
      alert('Failed to read the content of the excel file, currently does not support xls files!')
      return
    }
    console.log('exportJson', exportJson)
    jsonData.value = exportJson
    console.log(exportJson.sheets)
    window.luckysheet.destroy()
    excelTitel.value = exportJson.info.name
    congifdata.value.data = exportJson.sheets
    congifdata.value.title = exportJson.info.name
    congifdata.value.userInfo = exportJson.info.name.creator
    window.luckysheet.create(congifdata.value)
  })
}
const selectExcel = (evt) => {
  const value = selected.value
  const name = evt.target.options[evt.target.selectedIndex].innerText

  if (value == '') {
    return
  }
  isMaskShow.value = true

  LuckyExcel.transformExcelToLuckyByUrl(value, name, (exportJson, luckysheetfile) => {
    if (exportJson.sheets == null || exportJson.sheets.length == 0) {
      alert('Failed to read the content of the excel file, currently does not support xls files!')
      return
    }
    console.log('exportJson', exportJson)
    jsonData.value = exportJson

    isMaskShow.value = false
    window.luckysheet.destroy()

    window.luckysheet.create({
      container: 'luckysheet', //luckysheet is the container id
      showinfobar: false,
      data: exportJson.sheets,
      title: exportJson.info.name,
      userInfo: exportJson.info.name.creator
    })
  })
}
// 导出
const downloadExcel = () => {
  exportExcel(luckysheet.getAllSheets(), excelTitel.value)
}
// 从后台获取数据
const getExcel = () => {
  http.get('/index/index', {}, res => {
    if(res.code == 200) {
      window.luckysheet.destroy()
      console.log(JSON.parse(res.data))
      congifdata.value.data = JSON.parse(res.data)
      congifdata.value.title = '测试'
      window.luckysheet.create(congifdata.value)
    }
  })
}
// 保存excel数据
const saveExcel = () => {
  var excel = luckysheet.getAllSheets();
  //去除临时数据,减小体积
  for(var i in excel)
    excel[i].data = undefined
  // console.log(JSON.stringify(data))
  http.post('/index/update', {data:JSON.stringify(excel)}, res => {
    console.log(res)
    if(res.code == 200) {

    }
  })
}
const editClicked = () =>{
  congifdata.value.showtoolbar = true
  congifdata.value.allowEdit = true
  luckysheet.create(congifdata.value)
}
// !!! create luckysheet after mounted
onMounted(() => {
  luckysheet.create(congifdata.value)
})
</script>

<style scoped>
#luckysheet {
  margin: 0px;
  padding: 0px;
  position: absolute;
  width: 100%;
  left: 0px;
  top: 30px;
  bottom: 0px;
  height:900px;
}

#uploadBtn {
  font-size: 16px;
}

#tip {
  position: absolute;
  z-index: 1000000;
  left: 0px;
  top: 0px;
  bottom: 0px;
  right: 0px;
  background: rgba(255, 255, 255, 0.8);
  text-align: center;
  font-size: 40px;
  align-items: center;
  justify-content: center;
  display: flex;
}
</style>

运行后效果如图

本地引用文件的需要下载好组件

 

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mfbz.cn/a/274674.html

如若内容造成侵权/违法违规/事实不符,请联系我们进行投诉反馈qq邮箱809451989@qq.com,一经查实,立即删除!

相关文章

关于“Python”的核心知识点整理大全45

目录 15.4.6 绘制直方图 die_visual.py 注意 15.4.7 同时掷两个骰子 dice_visual.py 15.4.8 同时掷两个面数不同的骰子 different_dice.py 15.5 小结 第 16 章 16.1 CSV 文件格式 16.1.1 分析 CSV 文件头 highs_lows.py 注意 16.1.2 打印文件头及其位置 highs_l…

电影“AI化”已成定局,华为、小米转战入局又将带来什么?

从华为、Pika、小米等联合打造电影工业化实验室、到Pika爆火&#xff0c;再到国内首部AI全流程制作《愚公移山》开机……业内频繁的新动态似乎都在预示着2023年国内电影开始加速进入新的制片阶段&#xff0c;国内AI电影热潮即将来袭。 此时以华为为首的底层技术科技企业加入赛…

OCP NVME SSD规范解读-2.复位与控制器配置要求-part2

Maximum Data Transfer Size (MDTS)&#xff1a;设备应支持至少256KB的最大数据传输大小。 CSTS.CFS Reporting: 设备固件应支持报告CSTS.CFS&#xff08;Controller Status and Capabilities Field in the Status Register&#xff09;。 Queue Depths: 每个提交队列的SQ最小…

钉钉机器人接入定时器(钉钉API+XXL-JOB)

钉钉机器人接入定时器&#xff08;钉钉APIXXL-JOB&#xff09; 首先需要创建钉钉内部群 在群设置中找到机器人选项 选择“自定义”机器人 通过Webhook接入自定义服务 创建完成后会生成一个send URL和一个加签码 下面就是干货 代码部分了 DingDingUtil.sendMessageByText(webho…

Java EasyExcel 导入代码

Java EasyExcel 导入代码 导入方法 /*** 仓库库位导入** param req* param res* param files* throws Exception*/RequestMapping(value {"/import/line_store_locs"}, method {RequestMethod.POST})ResponseBodypublic void importStoreLoc(HttpServletRequest …

工具系列:TimeGPT_(8)使用不规则时间戳进行时间序列预测

文章目录 介绍不规则时间戳的单变量时间预测不规则时间戳的外生变量时间预测 介绍 在处理时间序列数据时&#xff0c;时间戳的频率是一个关键因素&#xff0c;可以对预测结果产生重大影响。像每日、每周或每月这样的常规频率很容易处理。然而&#xff0c;像工作日这样的不规则…

Linux磁盘与文件系统管理

在linux系统中使用硬盘 建立分区 安装文件系统 挂载 磁盘的数据结构 磁盘&#xff1a;扇区固定大小&#xff0c;每个扇区4k。磁盘会进行磨损&#xff0c;损失生命周期。 扇区 磁道 柱面 磁盘接口类型 ide SATA SAS SCSI SCSI 设备类型 块设备&#xff1a;block …

2024年HTML+CSS+JS 网页版烟花代码

&#x1f482; 个人网站:【 海拥】【神级代码资源网站】【办公神器】&#x1f91f; 基于Web端打造的&#xff1a;&#x1f449;轻量化工具创作平台&#x1f485; 想寻找共同学习交流的小伙伴&#xff0c;请点击【全栈技术交流群】 直接跳到末尾 获取完整源码 在线体验地址&…

分支指令的方向预测

对于分支指令来说,它的方向只有两个:发生跳转(taken)和不发生跳转(nottaken),因此可以用1 和0 来表示。 很多分支指令的方向是有规律可循的。 方式一&#xff1a;last-outcom prediction 其准确度&#xff0c;无法接受&#xff1b; 方式二&#xff1a;基于两位饱和计数器的分…

模式识别与机器学习-SVM(线性支持向量机)

线性支持向量机 线性支持向量机间隔距离学习的对偶算法算法:线性可分支持向量机学习算法线性可分支持向量机例子 谨以此博客作为复习期间的记录 线性支持向量机 在以上四条线中&#xff0c;都可以作为分割平面&#xff0c;误差率也都为0。但是那个分割平面效果更好呢&#xff1…

2022年全球软件质量效能大会(QECon上海站)-核心PPT资料下载

一、峰会简介 近年来&#xff0c;以云计算、移动互联网、物联网、工业互联网、人工智能、大数据及区块链等新一代信息技术构建的智能化应用和产品出现爆发式增长&#xff0c;突破了对于软件形态的传统认知&#xff0c;正以各种展现方式诠释着对新型智能软件的定义。这也使得对…

open_vins 安装(ubuntu18.04 opencv3.2.0)

openvins官网 Getting Started Installation Guide (ROS1 and ROS2) | OpenVINS Ubuntu 18.04 ROS 1 Melodic (uses OpenCV 3.2) 这里他指的是ros1 melodic&#xff0c;他们用的opencv3.2测试过。 open_vins 官方给的组合Ubuntu 18.04 ROS 1 Melodic (uses OpenCV 3.2) Ub…

IDEA 开发中常用的快捷键

目录 Ctrl 的快捷键 Alt 的快捷键 Shift 的快捷键 Ctrl Alt 的快捷键 Ctrl Shift 的快捷键 其他的快捷键 Ctrl 的快捷键 Ctrl F 在当前文件进行文本查找 &#xff08;必备&#xff09; Ctrl R 在当前文件进行文本替换 &#xff08;必备&#xff09; Ctrl Z 撤…

奇富科技跻身国际AI学术顶级会议ICASSP 2024,AI智能感知能力迈入新纪元

近日&#xff0c;2024年IEEE声学、语音与信号处理国际会议ICASSP 2024&#xff08;2024 IEEE International Conference on Acoustics, Speech, and Signal Processing&#xff09;宣布录用奇富科技关于语音情感计算的最新研究成果论文“MS-SENet: Enhancing Speech Emotion Re…

PHP的Laravel加一个小页面出现问题(whereRaw的用法)

1.权限更新问题 因为是已经有样例了所以html和php页面很快写出来了 然后就是页面写完了路由不知道在哪写&#xff0c;后来想起来之前有要开权限来着&#xff0c;试了一下&#xff0c;还是不行&#xff0c;不过方向是对了 这是加的路由&#xff0c;不过需要在更新一下权限 这…

知识库问答LangChain+LLM的二次开发:商用时的典型问题及其改进方案

前言 如之前的文章所述&#xff0c;我司下半年成立大模型项目团队之后&#xff0c;我虽兼管整个项目团队&#xff0c;但为让项目的推进效率更高&#xff0c;故分成了三大项目组 第一项目组由霍哥带头负责类似AIGC模特生成系统第二项目组由阿荀带头负责论文审稿GPT以及AI agen…

在 Windows 中安装 SQLite 数据库

在 Windows 上安装 SQLite 步骤1 请访问 SQLite 下载页面&#xff0c;从 Windows 区下载预编译的二进制文件 ​ 步骤2 您需要下载 sqlite-dll-win-x64-3440200.zip 和 sqlite-tools-win-x64-3440200.zip 压缩文件 步骤3 创建文件夹 C:\Program Files\SQLite&#xff0c;并在…

PHP的Laravel的数据库迁移

1.默认迁移文件 2.数据库迁移 在终端输入以下代码 php artisan migrate 我的报错啦&#xff01;&#xff01;&#xff01;&#xff01;&#xff01; 数据库里面只有两张表&#xff0c;实际上应该有四张的&#xff01;&#xff01;&#xff01; 解决方法&#xff1a; 反正表已…

Modbus RTU转Modbus TCP模块,RS232/485转以太网模块,YL102 多功能串口服务器模块

特点&#xff1a; ● Modbus RTU协议自动转换成Mobus TCP协议 ● 100M高速网卡&#xff0c;10/100M 自适应以太网接口 ● 支持 AUTO MDI/MDIX&#xff0c;可使用交叉网线或平行网线连接 ● RS232波特率从300到256000可设置 ● 工作方式可选择TCP Server, TCP Client, U…

【Leetcode】重排链表、旋转链表、反转链表||

目录 &#x1f4a1;重排链表 题目描述 方法一&#xff1a; 方法二&#xff1a; &#x1f4a1;旋转链表 题目描述 方法&#xff1a; &#x1f4a1;反转链表|| 题目描述 方法&#xff1a; &#x1f4a1;总结 &#x1f4a1;重排链表 题目描述 给定一个单链表 L 的头节…