vue如何實(shí)現(xiàn)在線(xiàn)編輯excel
vue實(shí)現(xiàn)在線(xiàn)編輯excel
不支持ie 支持edge 需要ie請(qǐng)換方法
vue不再贅述
安裝x-data-spreadsheet
npm install x-data-spreadsheet
<template>
<div id="x-spreadsheet-demo"></div>
</template>
<script>
import Spreadsheet from 'x-data-spreadsheet';
import zhCN from 'x-data-spreadsheet/dist/locale/zh-cn';
export default {
data() {
return {
options:{
mode: 'edit',
showToolbar: true,
showGrid: true,
showContextmenu: true,
view: {
/*寬高,因?yàn)槲沂亲远x的所以-----*/
/*height: () => document.documentElement.clientHeight - 300,
width: () => document.documentElement.clientWidth - 300,*/
height: () => document.documentElement.clientHeight - 64,
width: () => document.documentElement.clientWidth - 150,
},
formats: [],
fonts: [],
formula: [],
row: {
len: 100,
height: 25,
},
col: {
len: 26,
width: 100,
indexWidth: 60,
minWidth: 60,
},
/*freeze: 'C3',*/
style: {
bgcolor: '#ffffff',
align: 'left',
valign: 'middle',
textwrap: false,
textDecoration: 'normal',
strikethrough: false,
color: '#0a0a0a',
font: {
name: 'Helvetica',
size: 10,
bold: false,
italic: false,
},
},
},
/*數(shù)組*/
optionss:[{
name:'aaaa',
/*freeze: 'C3',*/
styles: [
{
/*小框背景色*/
bgcolor: '#f4f5f8',
textwrap: true,
color: '#900b09',
border: {
top: ['thin', '#0366d6'],
bottom: ['thin', '#0366d6'],
right: ['thin', '#0366d6'],
left: ['thin', '#0366d6'],
},
},{
/*小框背景色*/
bgcolor: '#000000',
textwrap: true,
color: '#000000',
border: {
top: ['thin', '#000000'],
bottom: ['thin', '#000000'],
right: ['thin', '#000000'],
left: ['thin', '#000000'],
},
},
],
/*合并單元格*/
merges: [
'C3:E4',
],
rows: {
/*第1行*/
1: {
cells: {
/*第0列 2列*/
0: { text: 'testingtesttestetst' },
2: { text: 'testing' },
},
},
2: {
cells: {
0: { text: 'render', style: 0 },
1: { text: 'Hello' },
2: { text: 'haha', merge: [1, 2] },
}
},
8: {
cells: {
8: { text: 'border test', style: 0 },
}
}
},
},{
name:'aaaa',
/*freeze: 'C3',*/
styles: [
{
/*小框背景色*/
bgcolor: '#f4f5f8',
textwrap: true,
color: '#900b09',
border: {
top: ['thin', '#0366d6'],
bottom: ['thin', '#0366d6'],
right: ['thin', '#0366d6'],
left: ['thin', '#0366d6'],
},
},{
/*小框背景色*/
bgcolor: '#000000',
textwrap: true,
color: '#000000',
border: {
top: ['thin', '#000000'],
bottom: ['thin', '#000000'],
right: ['thin', '#000000'],
left: ['thin', '#000000'],
},
},
],
/*合并單元格*/
merges: [
'C3:E4',
],
rows: {
/*第1行*/
1: {
cells: {
/*第0列 2列*/
0: { text: 'testingtesttestetst' },
2: { text: 'testing' },
},
},
2: {
cells: {
0: { text: 'render', style: 0 },
1: { text: 'Hello' },
2: { text: 'haha', merge: [1, 2] },
}
},
8: {
cells: {
8: { text: 'border test', style: 0 },
}
}
},
}]
}
},
methods: {
},
mounted:function(){
/*中文*/
Spreadsheet.locale('zh-cn', zhCN);
new Spreadsheet('#x-spreadsheet-demo', this.options).loadData(this.optionss).change((data) => {
console.log(data)
});
}
}
</script>
<style>
</style>vue導(dǎo)出excel模板
1、首先需要導(dǎo)入第三方插件xlsx(最好是指定版本,要不然容易報(bào)錯(cuò))
npm install --save xlsx@0.17.0
后續(xù)可能還會(huì)用到導(dǎo)入導(dǎo)出,也需要安裝第三方插件
npm install --save file-saver@2.0.5
2、哪個(gè)頁(yè)面需要下載excel模板就到哪里導(dǎo)入
import XLSX from "xlsx"
3、給下載模板按鈕綁定事件
<el-button @click="downloadExcel">嗨嗨嗨</el-button>
4、下載模板執(zhí)行內(nèi)容
downloadExcel() {
let excelData = [
[ '姓名', '電話(huà)', '生日', 'xx', "xx", "……"]//這里是表頭數(shù)據(jù)
]
let ws = XLSX.utils.aoa_to_sheet(excelData)
let wb = XLSX.utils.book_new()
XLSX.utils.book_append_sheet(wb, ws, '工作簿名稱(chēng)')
XLSX.writeFile(wb, '保存的文件名.xlsx')
}總結(jié)
以上為個(gè)人經(jīng)驗(yàn),希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。
相關(guān)文章
vue3 elementPlus 表格實(shí)現(xiàn)行列拖拽及列檢索功能(完整代碼)
本文通過(guò)實(shí)例代碼給大家介紹vue3 elementPlus 表格實(shí)現(xiàn)行列拖拽及列檢索功能,代碼簡(jiǎn)單易懂,對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友參考下吧2023-10-10
Vue 實(shí)現(xiàn)html中根據(jù)類(lèi)型顯示內(nèi)容
今天小編大家分享一篇Vue 實(shí)現(xiàn)html中根據(jù)類(lèi)型顯示內(nèi)容,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2019-10-10
vue.js入門(mén)教程之基礎(chǔ)語(yǔ)法小結(jié)
這篇文章我們將學(xué)習(xí)vue.js的基礎(chǔ)語(yǔ)法,對(duì)于大家學(xué)習(xí)vue.js具有一定的參考借鑒價(jià)值,有需要的朋友們下面來(lái)一起看看。2016-09-09
vue中json格式化顯示數(shù)據(jù)(vue-json-viewer)
這篇文章主要給大家介紹了關(guān)于vue中json格式化顯示數(shù)據(jù)(vue-json-viewer)的相關(guān)資料,Vue-json-viewer是一個(gè)Vue組件,用于在Vue應(yīng)用中顯示JSON數(shù)據(jù)的可視化工具,需要的朋友可以參考下2024-05-05
vue3.x?的shallowReactive?與?shallowRef?使用場(chǎng)景分析
在Vue3.x中,`shallowReactive`和`shallowRef`是用于創(chuàng)建淺層響應(yīng)式數(shù)據(jù)的API,它們與`reactive`和`ref`類(lèi)似,本文介紹vue3.x??shallowReactive?與?shallowRef的使用場(chǎng)景,感興趣的朋友一起看看吧2025-02-02
VUE插件vue-treeselect的使用及說(shuō)明
這篇文章主要介紹了VUE插件vue-treeselect的使用及說(shuō)明,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。2023-07-07

