轉(zhuǎn)帖|使用教程|編輯:龔雪|2020-12-22 10:06:09.727|閱讀 216 次
概述:本文將為大家介紹如何3分鐘創(chuàng)建 SpreadJS 的 Vue 項(xiàng)目。
# 界面/圖表報(bào)表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
SpreadJS 純前端表格控件 V11.2(SP2)版本已經(jīng)全面支持了 Vue 拓展,下面我們看下如何配合 VUE CLI,只需 3 分鐘快速構(gòu)建一個(gè) SpreadJS Vue 工程。
1. 安裝vue-cli(耗時(shí)30 S)
通過(guò)命令:npm install -g \@vue/cli 安裝()
2. 創(chuàng)建 vue-spreadjs 工程(耗時(shí) 1 Min)
請(qǐng)根據(jù)項(xiàng)目需求配置工程選項(xiàng)。
3. 通過(guò)npm install 或者在package.json中添加引用的方式安裝spread.sheets(耗時(shí)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",
4. 修改 router/index.js 為 spreadJS 頁(yè)面添加 router(耗時(shí) 30 S)
routes: [ { path: '/', name: 'HelloWorld', component: HelloWorld }, { path: '/spreadjs', name: 'spreadJS', component: SpreadJS } ]
5. 新建 SpreadJS Component(耗時(shí) 30 S)
請(qǐng)?jiān)?components 下添加 SpreadJS.vue 文件
template 內(nèi)容:
<template> <div> <h1>Spread.Sheets</h1> <div> <input type='file' @change="processFile($event)"/> <button @click="importExcel">導(dǎo)入</button> <button @click="exportExcel">導(dǎo)出</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內(nèi)容: <style> .spread-host { width: 100%; height: 400px; border: 1px solid black; } </style> Script內(nèi)容: <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 初始化完成后的回調(diào)事件,我們可以在事件中得到初始化好的 workbook 對(duì)象。
部署授權(quán)需要同時(shí)給 Sheets 和 ExcelIO 同時(shí)添加,部署授權(quán)可以在全局 config 中配置。
6. 運(yùn)行項(xiàng)目(耗時(shí) 10 S)
創(chuàng)建 npm install 依賴后,即可通過(guò)npm start啟動(dòng)項(xiàng)目
瀏覽器訪問(wèn) //localhost:8081/#/spreadjs 查看效果。
只需 3 分鐘,一個(gè) SpreadJS 的 Vue 項(xiàng)目就創(chuàng)建完成了,當(dāng)然純前端表格控件 SpreadJS 的強(qiáng)大不僅于此,去實(shí)際試用感受一下吧!
純前端表格控件SpreadJS,可滿足 .NET、Java、App 等應(yīng)用程序中的 Web Excel 組件開發(fā)、數(shù)據(jù)填報(bào)、在線文檔、圖表公式聯(lián)動(dòng)、類 Excel UI 設(shè)計(jì)等業(yè)務(wù)場(chǎng)景,并在數(shù)據(jù)可視化、Excel 導(dǎo)入導(dǎo)出、公式引用、數(shù)據(jù)綁定、框架集成中無(wú)需大量代碼開發(fā)和測(cè)試,極大降低了企業(yè)研發(fā)成本和項(xiàng)目交付風(fēng)險(xiǎn)。
本文轉(zhuǎn)載自
購(gòu)正版SpreadJS報(bào)表控件授權(quán)限時(shí)優(yōu)惠!最高立減萬(wàn)元!點(diǎn)擊
本站文章除注明轉(zhuǎn)載外,均為本站原創(chuàng)或翻譯。歡迎任何形式的轉(zhuǎn)載,但請(qǐng)務(wù)必注明出處、不得修改原文相關(guān)鏈接,如果存在內(nèi)容上的異議請(qǐng)郵件反饋至chenjj@fc6vip.cn
文章轉(zhuǎn)載自: