vue+spreadjs开发

创建vue3项目

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

安装spreadjs包

bash 复制代码
pnpm install "@grapecity-software/[email protected]" "@grapecity-software/[email protected]" "@grapecity-software/[email protected]" --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/[email protected]" "@grapecity-software/[email protected]"  "@grapecity-software/[email protected]" "@grapecity-software/[email protected]" "@grapecity-software/[email protected]" "@grapecity-software/[email protected]" "@grapecity-software/[email protected]" "@grapecity-software/[email protected]" "@grapecity-software/[email protected]" --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

相关推荐
嘻嘻嘻嘻嘻嘻ys16 分钟前
《Spring Boot 3 + GraalVM原生镜像实战:云原生时代的毫秒启动与性能调优》
前端·后端
嘻嘻嘻嘻嘻嘻ys19 分钟前
《Spring Boot 3.0×GraalVM:云原生时代的毫秒级启动实战革命》
前端·后端
嘻嘻嘻嘻嘻嘻ys21 分钟前
《Vue 3.4响应式内核优化与WebAssembly性能突破实战指南》
前端·后端
海天胜景23 分钟前
vue3 el-table 右击
javascript·vue.js·elementui
Mercury-circle25 分钟前
JavaScript基础知识合集笔记1——数据类型
开发语言·javascript·笔记
一天睡25小时36 分钟前
前端性能优化面试回答技巧(一)
前端·面试
樊小肆36 分钟前
Vue3 在线 PDF 编辑 2.0 缩放拖拽、渲染优化功能解析
前端·vue.js·开源
程序员韩立37 分钟前
精通 React Hooks:从核心技巧到自定义实践
前端
WEI_Gaot38 分钟前
React Hooks useRef useId
前端·react.js
一天睡25小时39 分钟前
视频HLS分片与关键帧优化深度解析
前端·javascript