使用葡萄城+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

相关推荐
hello_simon7 小时前
免费在线文档工具,在线PDF添加空白页,免费在任意位置插入空白页,多样化的文件处理
pdf·html·excel·pdf转html·excel转pdf格式
chenchihwen9 小时前
常用 Excel VBA 技巧,简单好学易上手
excel
夔8889 小时前
Excel通过VBA脚本去除重复数据行并保存
java·服务器·excel
啊波次得饿佛哥10 小时前
excel中的VBA指令示例(一)
excel·vba
inxunoffice10 小时前
批量将 JSON 转换为 Excel/思维导入等其它格式
json·excel
忘忧记11 小时前
如何在 Excel 中处理并拆分你提供的这种混合单位的库存数据。
excel
CAT_cwds1 天前
EasyExcel-一款好用的excel生成工具
excel·easy
Eiceblue1 天前
C# 设置Excel中文本的对齐方式、换行、和旋转
开发语言·c#·excel