本帖最后由 pioneer_web 于 2021-1-18 10:18 编辑
- <div class="file-area">
- <span class="upload" @change="importExcel($event)" v-if="isView == true">导入<input type="file" class="elchange" /></span>
- <el-button type="primary" @click="exportExcel()">导出</el-button>
- </div>
- <gc-spread-sheets class='spreadHost' @workbookInitialized="initSpread($event)" ref="spreadBosh">
- <gc-worksheet></gc-worksheet>
- </gc-spread-sheets>
复制代码- //导入
- importExcel(event) {
- const file = event.target.files[0];
- this.fileName = file.name;
- let self = this;
- if (!/\.(xlsx|xls|XLSX|XLS)$/.test(file.name)) {
- this.$message.error('导入文件格式有误');
- }
- let excelIO = new ExcelIO.IO();
- excelIO.open(file, (spreadJSON) => {
- if (self.spread) {
- self.spread.fromJSON(spreadJSON);
- }
- });
- console.log(excelIO, 'excelIO')
- },
- //导出
- exportExcel() {
- let self = this;
- if (self.spread) {
- let spreadJSON = JSON.stringify(self.spread.toJSON());
- let excelIO = new ExcelIO.IO();
- excelIO.save(spreadJSON, (blob)=>{
- FileSaver.saveAs(blob, this.fileName + ".xlsx");
- })
- }
- },
复制代码
|
|