使用葡萄城+vue实现Excel

最终实现效果如下

包含增加复选框 设置公式 设置背景颜色等,代码实在太多 有需要可留言

第一步:创建表头 请使用官网提供的网址:在线 Excel 编辑器 | SpreadJS 在线表格编辑器

1.点击下方+号,创建一个新的sheet页 默认新创建的sheet页名字是sheet8,这个县不用管,后续会修改

2.把你需要的表头粘贴进来

3.点击左上方的文件 ,接着按照图示例操作,就会得到一个js文件,我这里命名为aaa.js

第二步:

在vue文件install葡萄城必要的包,我引入的仅做为参考,此处根据项目需求进行增删包

第三步:

1.创建.vue文件,并引入包

html 复制代码
<template>
            <div class="spread-container">
            <gc-spread-sheets
                host-class="work-sheet"
                @workbookInitialized="initWorkbook"
            >
                <gc-worksheet />
            </gc-spread-sheets>
        </div>
</template>
<script>
import '@grapecity/spread-sheets/styles/gc.spread.sheets.excel2016colorful.css'
import '@grapecity/spread-sheets-vue'
import * as GC from '@grapecity/spread-sheets'
import { IO } from '@grapecity/spread-excelio'
import { saveAs } from 'file-saver'
const spreadNS = GC.Spread.Sheets
import layoutData from './aaa.js'
</script>

2.修改aaa.js

因为要import引入,所以需要修改原有的aaa.js的格式,变成图上示例的格式,具体需要修改的地方已用红色标记,其余不用修改,需要注意:one为原来的sheet8,此处可根据项目需要修改任意值

第四步:在methods中增加需要的方法

1.initWorkbook初始化工作簿

html 复制代码
        initWorkbook(spread) {
            this.loading = true
            // 设置spread基础样式
            this.ininSpreadStyle(spread)
            // 请求数据,渲染shet
            this.renderFn(spread)
        },

2.初始设施spread基础样式

html 复制代码
        // 初始设施spread基础样式
        ininSpreadStyle(spread) {
            this.spread = spread
            spread.removeSheet(0)
            // 不允许修改表单名
            spread.options.tabEditable = false
            // 不允许用户通过点击"+"按钮(默认是显示)添加工作表。
            spread.options.newTabVisible = false
            // 不允许拖拽调整那个表单顺序
            spread.options.allowSheetReorder = false
            // 设置背景色为白色
            spread.options.grayAreaBackColor = '#fff'
            // 设置滚动条宽度
            spread.options.tabStripRatio = 0.6
            // 右键菜单清空
            spread.contextMenu.menuData = []
            // 绑定点击单元格事件 
            spread.bind(spreadNS.Events.SelectionChanged, (e, args) => {
                this.checkedCellInfo.axis = args.newSelections[0]
                this.checkedCellInfo.nameCode = args.sheet.nameCode
            })
        },

3.请求数据 渲染sheet

相关推荐
Eiceblue36 分钟前
将 Python 列表导出为 Excel 文件:一维、二维、字典列表
开发语言·python·excel·visual studio code
Shi_haoliu16 小时前
inno setup6.6.1实例,制作安装包,创建共享文件夹,写入注册表(提供给excel加载项,此文章解释iss文件)
前端·vue.js·windows·excel
2501_9071368216 小时前
通用财务账模板【Excel版】
excel·软件需求
CodeCraft Studio17 小时前
Excel处理控件Aspose.Cells教程:使用C#在Excel中创建折线图
java·c#·excel·aspose.cells·excel图表·excel api库·excel折线图
狼与自由18 小时前
excel 导入 科学计数法问题处理
java·前端·excel
爱吃山竹的大肚肚20 小时前
Spring Boot 与 Apache POI 实现复杂嵌套结构 Excel 导出
java·spring boot·后端·spring·spring cloud·excel
AI_56781 天前
Python RPA解放Excel生产力
python·excel·rpa
七夜zippoe1 天前
AutoGen数据分析智能体实战:让Excel自动说话
人工智能·数据分析·excel·智能体·autogen
开开心心_Every1 天前
定时管理进程:防止沉迷电脑的软件推荐
xml·java·运维·服务器·网络·数据库·excel
Hello.Reader2 天前
Flink 系统内置函数(Built-in Functions)分类、典型用法与选型建议
大数据·flink·excel