您好,登錄后才能下訂單哦!
本篇內容主要講解“怎么快速創建一個SpreadJS的Vue項目”,感興趣的朋友不妨來看看。本文介紹的方法操作簡單快捷,實用性強。下面就讓小編來帶大家學習“怎么快速創建一個SpreadJS的Vue項目”吧!
通過命令```npm install -g @vue/cli ```安裝(https://)
請根據項目需求配置工程選項:
"@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中配置。
到此,相信大家對“怎么快速創建一個SpreadJS的Vue項目”有了更深的了解,不妨來實際操作一番吧!這里是億速云網站,更多相關內容可以進入相關頻道進行查詢,關注我們,繼續學習!
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。