轉帖|使用教程|編輯:龔雪|2020-12-22 10:06:09.727|閱讀 216 次
概述:本文將為大家介紹如何3分鐘創建 SpreadJS 的 Vue 項目。
# 界面/圖表報表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
SpreadJS 純前端表格控件 V11.2(SP2)版本已經全面支持了 Vue 拓展,下面我們看下如何配合 VUE CLI,只需 3 分鐘快速構建一個 SpreadJS Vue 工程。
1. 安裝vue-cli(耗時30 S)
通過命令:npm install -g \@vue/cli 安裝()
2. 創建 vue-spreadjs 工程(耗時 1 Min)
請根據項目需求配置工程選項。
3. 通過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",
4. 修改 router/index.js 為 spreadJS 頁面添加 router(耗時 30 S)
routes: [ { path: '/', name: 'HelloWorld', component: HelloWorld }, { path: '/spreadjs', name: 'spreadJS', component: SpreadJS } ]
5. 新建 SpreadJS Component(耗時 30 S)
請在 components 下添加 SpreadJS.vue 文件
template 內容:
<template> <div> <h1>Spread.Sheets</h1> <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 中配置。
6. 運行項目(耗時 10 S)
創建 npm install 依賴后,即可通過npm start啟動項目
瀏覽器訪問 //localhost:8081/#/spreadjs 查看效果。
只需 3 分鐘,一個 SpreadJS 的 Vue 項目就創建完成了,當然純前端表格控件 SpreadJS 的強大不僅于此,去實際試用感受一下吧!
純前端表格控件SpreadJS,可滿足 .NET、Java、App 等應用程序中的 Web Excel 組件開發、數據填報、在線文檔、圖表公式聯動、類 Excel UI 設計等業務場景,并在數據可視化、Excel 導入導出、公式引用、數據綁定、框架集成中無需大量代碼開發和測試,極大降低了企業研發成本和項目交付風險。
本文轉載自
購正版SpreadJS報表控件授權限時優惠!最高立減萬元!點擊
本站文章除注明轉載外,均為本站原創或翻譯。歡迎任何形式的轉載,但請務必注明出處、不得修改原文相關鏈接,如果存在內容上的異議請郵件反饋至chenjj@fc6vip.cn
文章轉載自: