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

相关推荐
SuperherRo2 分钟前
Web开发-JavaEE应用&SpringBoot栈&SnakeYaml反序列化链&JAR&WAR&构建打包
前端·java-ee·jar·反序列化·war·snakeyaml
大帅不是我5 分钟前
Python多进程编程执行任务
java·前端·python
前端怎么个事6 分钟前
框架的源码理解——V3中的ref和reactive
前端·javascript·vue.js
Ciito9 分钟前
将 Element UI 表格元素导出为 Excel 文件(处理了多级表头和固定列导出的问题)
前端·vue.js·elementui·excel
不爱吃饭爱吃菜1 小时前
uniapp微信小程序一键授权登录
前端·javascript·vue.js·微信小程序·uni-app
heart000_11 小时前
从零开始打造个人主页:HTML/CSS/JS实战教程
javascript·css·html
90后小陈老师2 小时前
3D个人简历网站 5.天空、鸟、飞机
前端·javascript·3d
chenbin___2 小时前
react native text 显示 三行 超出部分 中间使用省略号
javascript·react native·react.js
漫路在线6 小时前
JS逆向-某易云音乐下载器
开发语言·javascript·爬虫·python
不爱吃糖的程序媛6 小时前
浅谈前端架构设计与工程化
前端·前端架构设计