本帖最后由 裴松晨 于 2025-5-6 17:11 编辑
1.我的场景是将excel中的文件进行导入
下面是我的操作代码
<template>
<el-dialog title='导入文件' :close-on-click-modal='false' :modal='false'
class='JNPF-dialog JNPF-dialog_center JNPF-dialog-import' lock-scroll width='1000px'>
<div class='import-main'>
<div class='upload'>
<div class='up_right'>
<p class='title'>上传填好的数据表</p>
<p class='tip'>文件后缀名必须是xlsx,点击保存赋值到下面报表中</p>
<el-upload :action="define.comUrl+'/api/extend/Employee/Uploader'"
:headers='{ Authorization: $store.getters.token}' n-success='handleSuccess'
:file-list='fileList' accept=".xls,.xlsx"
class='upload-area'>
<el-button type='text'>上传文件</el-button>
</el-upload>
</div>
</div>
</div>
<span slot='footer' class='dialog-footer'>
<el-button @click='cancel()'>取 消</el-button>
<el-button @click='cancel(true)' type='primary'>确 定</el-button>
</span>
</el-dialog>
</template>
<script>
import * as ExcelIO from '@grapecity/spread-excelio'
export default {
props: ['template', 'year'],
data() {
return {
importExcelFile: null,
fileName: '',
fileList: [],
list: []
}
},
methods: {
//导入的方法
cancel(isRefresh) {
if (isRefresh) {
// let spread = this.spreadValue
let excelIo = new ExcelIO.IO()
let excelFile = this.importExcelFile
var _this = this
excelIo.open(excelFile, function(json) {
// spread.fromJSON(workbookObj);
// _this.$emit('ImportInit', json)
console.log(json)
_this.$parent.ImportInit(json)
}, function(e) {
// process error
alert(e.errorMessage)
})
}
},
handleSuccess(res, file, fileList) {
this.importExcelFile = file.raw
if (res.code == 200) {
this.fileList = fileList.slice(-1)
this.fileName = res.data.name
} else {
this.fileList = fileList.filter(o => o.uid != file.uid)
this.$message({ message: res.msg, type: 'error', duration: 1000 })
}
}
}
}
</script>
2.这是我的控制台删除后输出5列是对的
|