vue+spreadjs开发

创建vue3项目

bash 复制代码
pnpm create vite --registry=http://registry.npm.taobao.org

安装spreadjs包

bash 复制代码
pnpm install "@grapecity-software/spread-sheets@17.1.7" "@grapecity-software/spread-sheets-resources-zh@17.1.7" "@grapecity-software/spread-sheets-vue@17.1.7" --registry=http://registry.npm.taobao.org

修改main.ts

ts 复制代码
import { createApp } from 'vue'
import './style.css'
import App from './App.vue'
import { GcSpreadSheets, GcWorksheet, GcColumn } from '@grapecity-software/spread-sheets-vue'


let app = createApp(App);
app.component('gc-spread-sheets', GcSpreadSheets);
app.component('gc-worksheet', GcWorksheet);
app.component('gc-column', GcColumn);
app.mount("#app");

修改App.vue

html 复制代码
<template>
  <div id="spread-host">
    <gc-spread-sheets hostClass="spreadHost" @workbookInitialized="initWorkbook">
    </gc-spread-sheets>
  </div>
</template>

<script setup lang="ts">
import "@grapecity-software/spread-sheets/styles/gc.spread.sheets.excel2016colorful.css";
import * as GC from "@grapecity-software/spread-sheets";
import "@grapecity-software/spread-sheets-vue";

function initWorkbook(spread:GC.Spread.Sheets.Workbook) {
  let sheet = spread.getActiveSheet();
  sheet
      .getCell(0, 0)
      .vAlign(GC.Spread.Sheets.VerticalAlign.center)
      .value("Hello SpreadJS");
}
</script>

<style>
.spreadHost {
  width: 800px;
  height: 800px;
}
</style>

运行之后的结果

spreadjs-design

在上面的基础上添加如下npm包

bash 复制代码
pnpm install "@grapecity-software/spread-sheets-designer-vue@17.1.7" "@grapecity-software/spread-sheets-designer@17.1.7"  "@grapecity-software/spread-sheets-designer-resources-cn@17.1.7" "@grapecity-software/spread-excelio@17.1.7" "@grapecity-software/spread-sheets-pdf@17.1.7" "@grapecity-software/spread-sheets-io@17.1.7" "@grapecity-software/spread-sheets-languagepackages@17.1.7" "@grapecity-software/spread-sheets-charts@17.1.7" "@grapecity-software/spread-sheets-barcode@17.1.7" --registry=http://registry.npm.taobao.org

修改App.vue

html 复制代码
<template>
  <div id="spread-host">
    <designer style="width: 100%;height: 800px;" v-on:designer-initialized="init"></designer>
  </div>
</template>

<script setup lang="ts">
import "@grapecity-software/spread-sheets/styles/gc.spread.sheets.excel2016colorful.css";
import "@grapecity-software/spread-sheets-designer/styles/gc.spread.sheets.designer.min.css"
import "@grapecity-software/spread-sheets-designer-resources-cn"
import * as GC from "@grapecity-software/spread-sheets-designer"
import "@grapecity-software/spread-sheets-vue";
import Designer from "@grapecity-software/spread-sheets-designer-vue"

const init=(design:any)=>{
  const  designer = design as GC.Spread.Sheets.Designer.Designer;
  if(designer){
    console.log('初始化')
    console.log(designer.getWorkbook())
  }

}
</script>

<style>
</style>

运行之后效果如下

也可以不用组件自己实现

html 复制代码
<template>
  <div id="spread-host">
    <div ref="ssDesigner" style="height:700px;width:100%;text-align: left;"></div>
  </div>
</template>

<script setup lang="ts">
import {onMounted,ref} from "vue";
import "@grapecity-software/spread-sheets/styles/gc.spread.sheets.excel2016colorful.css";
import "@grapecity-software/spread-sheets-designer/styles/gc.spread.sheets.designer.min.css"
import "@grapecity-software/spread-sheets-designer-resources-cn"
import * as GC from "@grapecity-software/spread-sheets-designer"
import "@grapecity-software/spread-sheets-vue";

const ssDesigner = ref(null);

onMounted(()=>{
  if(ssDesigner.value){
    console.log(ssDesigner.value)
    const divElement = ssDesigner.value as HTMLDivElement;
    if(divElement)
    {
      var designer = new GC.Spread.Sheets.Designer.Designer(divElement);
      console.log(designer)
    }else{
      console.log('divElement不存在')
    }
  }
})
</script>

<style>
</style>

效果如上图

还可以增加配置

js 复制代码
var config = GC.Spread.Sheets.Designer.DefaultConfig;

var designer = new GC.Spread.Sheets.Designer.Designer(divElement,config);

参考

vue框架支持
https://www.grapecity.com.cn/blogs/spreadjs-vue3-component-development-combat-part2

相关推荐
浪浪山小白兔8 分钟前
HTML5 常用事件详解
前端·html·html5
Python大数据分析@25 分钟前
通俗的讲,网络爬虫到底是什么?
前端·爬虫·网络爬虫
不爱学英文的码字机器42 分钟前
[操作系统] 环境变量详解
开发语言·javascript·ecmascript
Lysun0011 小时前
vue2的$el.querySelector在vue3中怎么写
前端·javascript·vue.js
毛毛三由1 小时前
【组件分享】商品列表组件-最佳实践
vue.js
jerry-891 小时前
Centos类型服务器等保测评整/etc/pam.d/system-auth
java·前端·github
工业甲酰苯胺1 小时前
深入解析 Spring AI 系列:解析返回参数处理
javascript·windows·spring
小爬菜1 小时前
Django学习笔记(启动项目)-03
前端·笔记·python·学习·django
想要打 Acm 的小周同学呀1 小时前
前端Vue2项目使用md编辑器
前端·编辑器·vue2·markdown 语法
计算机-秋大田2 小时前
基于SSM的家庭记账本小程序设计与实现(LW+源码+讲解)
java·前端·后端·微信小程序·小程序·课程设计