SpreadJS純前端表格控件 V11.2(SP2)版本已經全面支持了Vue拓展,下面我們看下如何配合VUE CLI,只需3分鐘快速構建一個SpreadJS Vue工程。
通過命令```npm install -g @vue/cli ```安裝(https://cli.vuejs.org/)
請根據項目需求配置工程選項:
"@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",
routes: [ { path: '/', name: 'HelloWorld', component: HelloWorld }, { path: '/spreadjs', name: 'spreadJS', component: SpreadJS } ]
請在 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中配置。
創建 npm install 依賴后,即可通過npm start啟動項目
瀏覽器訪問 http://localhost:8081/#/spreadjs 查看效果。
只需3分鐘,一個SpreadJS 的Vue項目就創建完成了,當然純前端表格控件SpreadJS的強大不僅于此,去實際試用感受一下吧
這篇文章,講述的是《3分鐘創建 SpreadJS 的 React 項目》,需要的同學請深入了解。
純前端表格控件SpreadJS,是市面上布局與功能都與 Excel 高度類似的一款表格控件,全中文操作界面,適用于.NET、Java、移動端等多個平臺的類 Excel 數據開發,備受華為、海信、立信、中國平安、中國能建、中通快遞、金麒麟和北京神軟等客戶青睞。
關于葡萄城
賦能開發者!葡萄城公司成立于 1980 年,是全球領先的集開發工具、商業智能解決方案、管理系統設計工具于一身的軟件和服務提供商。西安葡萄城是其在中國的分支機構,面向全球市場提供軟件研發服務,并為中國企業的信息化提供國際先進的開發工具、軟件和研發咨詢服務。葡萄城的控件和軟件產品在國內外屢獲殊榮,在全球被數十萬家企業、學校和政府機構廣泛應用。
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。