温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

只需3 分钟,就能创建 一个SpreadJS 的 Vue 项

发布时间:2020-06-27 23:01:55 来源:网络 阅读:987 作者:powertoolsteam 栏目:软件技术

概述

SpreadJS纯前端表格控件 V11.2(SP2)版本已经全面支持了Vue拓展,下面我们看下如何配合VUE CLI,只需3分钟快速构建一个SpreadJS Vue工程。

只需3 分钟,就能创建 一个SpreadJS 的 Vue 项

安装vue-cli(耗时30S)

通过命令```npm install -g @vue/cli ```安装(cli.vuejs.org/

创建vue-spreadjs工程(耗时1Min)

请根据项目需求配置工程选项:

通过npm install 或者在package.json中添加引用的方式安装spread.sheets(耗时20S)

"@grapecity/spread-excelio": "^11.2.3",
"@grapecity/spread-sheets": "^11.2.3",
"@grapecity/spread-sheets-print": "^11.2.3",
"@grapecity/spread-sheets-resources-zh": "^11.2.3",
"@grapecity/spread-sheets-vue": "^11.2.3",

修改router/index.js为spreadJS页面添加router(耗时30S)

routes: [
{
path: '/',
name: 'HelloWorld',
component: HelloWorld
},
{
path: '/spreadjs',
name: 'spreadJS',
component: SpreadJS
}
]

新建SpreadJS Component(耗时30S)

请在 components 下添加SpreadJS.vue文件

template 内容:

<template>
<div>
<h2>Spread.Sheets</h2>
<div>
<input type='file' @change="processFile($event)"/>
<button @click="importExcel">导入</button>
<button @click="exportExcel">导出</button>
<button @click="printWorkbook">打印</button>
</div>
<div style="text-align: left">
<gc-spread-sheets
hostClass='spread-host'
@workbookInitialized = 'workbookInitialized($event)'>
<gc-worksheet>
</gc-worksheet>
</gc-spread-sheets>
</div>
</div>
</template>

Style内容:

<style>
.spread-host {
width: 100%;
height: 400px;
border: 1px solid black;
}
</style>

Script内容:

<script>
/* eslint-disable */
import "@grapecity/spread-sheets/styles/gc.spread.sheets.excel2016colorful.css";
import GC from "@grapecity/spread-sheets";
import "@grapecity/spread-sheets-vue";
import "@grapecity/spread-sheets-resources-zh";
import ExcelIO from "@grapecity/spread-excelio";
import FaverSaver from "file-saver";
import "@grapecity/spread-sheets-print";
GC.Spread.Common.CultureManager.culture("zh-cn");
GC.Spread.Sheets.LicenseKey = ExcelIO.LicenseKey = "your key"
export default {
methods: {
processFile (event) {
this.excelFile = event.target.files[0];
},
importExcel () {
var excelIO = new ExcelIO.IO();
console.log(excelIO);
var self = this;
excelIO.open(this.excelFile, function(json) {
self.spread.fromJSON(json);
console.log(json);
});
},
exportExcel () {
var excelIO = new ExcelIO.IO();
var json = this.spread.toJSON();
excelIO.save(
json,
function(blob) {
FaverSaver.saveAs(blob, "export.xlsx");
},
function(e) {
console.log(e);
}
);
},
printWorkbook (){
this.spread.print();
},
workbookInitialized(spread) {
this.spread = spread;
spread.refresh();
}
}
}
</script>

workbookInitialized是spread初始化完成后的回调事件,我们可以在事件中得到初始化好的workbook对象。

部署授权需要同时给Sheets和ExcelIO同时添加,部署授权可以在全局config中配置。

运行项目(耗时10S)

创建 npm install 依赖后,即可通过npm start启动项目

浏览器访问 http://localhost:8081/#/spreadjs 查看效果。

只需3分钟,一个SpreadJS 的Vue项目就创建完成了,当然纯前端表格控件SpreadJS的强大不仅于此,去实际试用感受一下吧

扩展阅读

这篇文章,讲述的是《3分钟创建 SpreadJS 的 React 项目》,需要的同学请深入了解。

纯前端表格控件SpreadJS,是市面上布局与功能都与 Excel 高度类似的一款表格控件,全中文操作界面,适用于.NET、Java、移动端等多个平台的类 Excel 数据开发,备受华为、海信、立信、中国平安、中国能建、中通快递、金麒麟和北京神软等客户青睐。

关于葡萄城

赋能开发者!葡萄城公司成立于 1980 年,是全球领先的集开发工具、商业智能解决方案、管理系统设计工具于一身的软件和服务提供商。西安葡萄城是其在中国的分支机构,面向全球市场提供软件研发服务,并为中国企业的信息化提供国际先进的开发工具、软件和研发咨询服务。葡萄城的控件和软件产品在国内外屡获殊荣,在全球被数十万家企业、学校和政府机构广泛应用。


向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI