Open klren0312 opened 3 years ago
<template>
<div :id="instanceId"></div>
</template>
<script>
import jexcel from 'jexcel' // excel组件
import 'jexcel/dist/jexcel.css'
export default {
name: 'ExcelTable',
props: {
instanceId: {
type: String,
default: 'excel-table'
}, // excel的DOM id, 防止初始化相互干扰
excelData: {
type: Array,
default: () => [[], [], []]
}, // excel数据
excelColumns: {
type: Array,
default: () => [
{ type: 'text', title: 'test', width: '150px' },
{ type: 'text', title: 'test', width: '150px' },
{ type: 'text', title: 'test', width: '150px' }
]
} // excel列标题
},
data() {
return {
excelInstance: null, // excel实例
excelOptions: {
data: this.excelData,
allowToolbar: true,
columns: this.excelColumns,
allowDeletingAllRows: false, // 允许删除所有行
allowRenameColumn: false, // 允许重命名列
allowDeleteColumn: false, // 允许删除列
tableOverflow: true, // 允许滚动
tableHeight: '400px', // 最大高度
text: {
noRecordsFound: '未找到',
showingPage: '显示 {1} 条中的第 {0} 条',
show: '显示 ',
search: '搜索',
entries: ' 条目',
columnName: '列标题',
insertANewColumnBefore: '在此前插入列',
insertANewColumnAfter: '在此后插入列',
deleteSelectedColumns: '删除选定列',
renameThisColumn: '重命名列',
orderAscending: '升序',
orderDescending: '降序',
insertANewRowBefore: '在此前插入行',
insertANewRowAfter: '在此后插入行',
deleteSelectedRows: '删除选定行',
editComments: '编辑批注',
addComments: '插入批注',
comments: '批注',
clearComments: '删除批注',
copy: '复制',
paste: '粘贴',
saveAs: '保存为',
about: '关于',
areYouSureToDeleteTheSelectedRows: '确定删除选定行?',
areYouSureToDeleteTheSelectedColumns: '确定删除选定列?',
thisActionWillDestroyAnyExistingMergedCellsAreYouSure:
'这一操作会破坏所有现存的合并单元格,确认操作?',
thisActionWillClearYourSearchResultsAreYouSure:
'这一操作会清空搜索结果,确认操作?',
thereIsAConflictWithAnotherMergedCell: '与其他合并单元格有冲突',
invalidMergeProperties: '无效的合并属性',
cellAlreadyMerged: '单元格已合并',
noCellsSelected: '未选定单元格'
} // 翻译
}
}
},
mounted() {
this.$nextTick(() => {
if (this.excelInstance) {
document.getElementById(this.instanceId).innerHTML = ''
this.excelInstance = null
}
this.excelOptions.data = this.excelData
this.excelInstance = jexcel(
document.getElementById(this.instanceId),
this.excelOptions
)
})
}
}
</script>
<style>
.jcontextmenu>div:last-child {
display: none;
}
.jexcel_selectall:after {
content: '序号';
display: block;
text-align: center;
}
</style>