vue引入Excel表格插件的方法
更新時(shí)間:2021年04月28日 17:11:15 作者:涼夕小主
這篇文章主要為大家詳細(xì)介紹了vue引入Excel表格插件的方法,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
本文實(shí)例為大家分享了vue引入Excel表格插件的具體代碼,供大家參考,具體內(nèi)容如下
一、安裝
npm install handsontable-pro @handsontable-pro/vue npm install handsontable @handsontable/vue
二、引用(在頁面引用)
import { HotTable } from ‘@handsontable-pro/vue'
import ‘…/…/node_modules/handsontable-pro/dist/handsontable.full.css'
import Handsontable from ‘handsontable-pro'
三、使用(在標(biāo)簽中使用)
<div id="hotTable" class="hotTable">
<HotTable ref="hotTableComponent" :settings="hotSettings"></HotTable>
</div>
四、數(shù)據(jù)中定義
data () {
return {
list: [],
root: 'test-hot',
hotSettings: {
data: [ // 數(shù)據(jù)可以是二維數(shù)組,也可以是數(shù)組對象
],
startRows: 3, // 行列范圍
startCols: 3,
minRows: 20, // 最小行數(shù)
minCols: 5, //最小列數(shù)
maxRows: 20, // 最大行列
maxCols: 20,//最大列數(shù)
rowHeaders: true, // 行表頭,可以使布爾值(行序號),可以使字符串(左側(cè)行表頭相同顯示內(nèi)容,可以解析html),也可以是數(shù)組(左側(cè)行表頭單獨(dú)顯示內(nèi)容)。
colHeaders: ['賬戶等級', '賬戶名稱', '賬戶編號', '賬戶類別'], // 自定義列表頭or 布爾值
minSpareCols: 0, // 列留白
minSpareRows: 0, // 行留白
currentRowClassName: 'currentRow', // 為選中行添加類名,可以更改樣式
currentColClassName: 'currentCol', // 為選中列添加類名
autoWrapRow: true, // 自動換行
className: 'htCenter htMiddle', // 默認(rèn)單元格樣式,垂直居中
contextMenu: {
items: {
// 'row_above': {
// name: '上方插入一行'
// },
// 'row_below': {
// name: '下方插入一行'
// },
// 'col_left': {
// name: '左方插入列'
// },
// 'col_right': {
// name: '右方插入列'
// },
'hsep1': '---------', // 提供分隔線
'remove_row': {
name: '刪除行'
},
'remove_col': {
name: '刪除列'
},
'make_read_only': {
name: '只讀'
},
'borders': {
name: '表格線'
},
'copy': {
name: '復(fù)制'
},
'cut': {
name: '剪切'
},
'commentsAddEdit': {
name: '添加備注'
},
'commentsRemove': {
name: '取消備注'
},
'freeze_column': {
name: '固定列'
},
'unfreeze_column': {
name: '取消列固定'
},
'mergeCells': {
name: '合并單元格'
},
'alignment': {
name: '文字位置'
},
'hsep2': '---------'
}
},
afterChange: function (changes, source) { // 數(shù)據(jù)改變時(shí)觸發(fā)此方法
// console.log(this.getSourceData())
this.list = this.getSourceData() // 獲取表格里的數(shù)據(jù)
// console.log(this.getPlugin('MergeCells').mergedCellsCollection.mergedCells) // 獲取表格合并單元格的參數(shù)
},
manualColumnFreeze: true, // 手動固定列 ?
manualColumnMove: true, // 手動移動列
manualRowMove: true, // 手動移動行
manualColumnResize: true, // 手工更改列距
manualRowResize: true, // 手動更改行距
comments: true, // 添加注釋 ?
// cell: [ // ???
// {row: 1, col: 1, comment: {value: 'this is test'}}
// ],
customBorders: [], // 添加邊框
columnSorting: true, // 排序
stretchH: 'all', // 根據(jù)寬度橫向擴(kuò)展,last:只擴(kuò)展最后一列,none:默認(rèn)不擴(kuò)展
fillHandle: true, // 選中拖拽復(fù)制 possible values: true, false, "horizontal", "vertical"
fixedColumnsLeft: 0, // 固定左邊列數(shù)
fixedRowsTop: 0, // 固定上邊列數(shù)
mergeCells: [ // 合并
// {row: 1, col: 1, rowspan: 3, colspan: 3}, // 指定合并,從(1,1)開始行3列3合并成一格
// {row: 3, col: 4, rowspan: 2, colspan: 2}
],
columns: [ // 設(shè)置表頭名稱
{
data: 'acctLevel'
},
{
data: 'acctName'
},
{
data: 'acctNo'
},
{
data: 'acctType'
},
]
}
}
},
五、引入組件
components: {
HotTable
},
六、方法中使用
methods: {
swapHotData: function () {
// The Handsontable instance is stored under the `hotInstance` property of the wrapper component.
// this.$refs.hotTableComponent.hotInstance.loadData([['new', 'data']])
console.log(this.$refs.hotTableComponent.hotInstance.getPlugin('MergeCells').mergedCellsCollection.mergedCells)
}
},
重點(diǎn):
this.$refs.hotTableComponent.hotInstance // 獲取表格數(shù)據(jù),調(diào)用表格方法, ****** 指向表格 getPlugin(‘MergeCells').mergedCellsCollection.mergedCells) // 獲取合并單元格之后需要的參數(shù)
注意:需要接口獲取數(shù)據(jù)直接對this.hotSettings下data賦值就行
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
您可能感興趣的文章:
- Vue3實(shí)現(xiàn)動態(tài)導(dǎo)入Excel表格數(shù)據(jù)的方法詳解
- 使用SpringBoot+EasyExcel+Vue實(shí)現(xiàn)excel表格的導(dǎo)入和導(dǎo)出詳解
- vue項(xiàng)目中常見的三種文件類型在線預(yù)覽實(shí)現(xiàn)(pdf/word/excel表格)
- vue導(dǎo)出excel表格的新手詳細(xì)教程
- Vue請求后端接口導(dǎo)出excel表格方式
- vue+element表格導(dǎo)出為Excel文件
- vue項(xiàng)目預(yù)覽excel表格功能(file-viewer插件)
相關(guān)文章
Vue3視頻播放器組件Vue3-video-play新手入門教程
這篇文章主要給大家介紹了關(guān)于Vue3視頻播放器組件Vue3-video-play新手入門教程的相關(guān)資料,本文實(shí)例為大家分享了vue-video-player視頻播放器的使用配置,供大家參考,需要的朋友可以參考下2023-12-12
解決vue js IOS H5focus無法自動彈出鍵盤的問題
今天小編就為大家分享一篇解決vue js IOS H5focus無法自動彈出鍵盤的問題,具有很好的參考價(jià)值,希望對大家有所幫助。一起跟隨小編過來看看吧2018-08-08
vue?點(diǎn)擊按鈕?路由跳轉(zhuǎn)指定頁面的實(shí)現(xiàn)方式
這篇文章主要介紹了vue?點(diǎn)擊按鈕?路由跳轉(zhuǎn)指定頁面的實(shí)現(xiàn)方式,具有很好的參考價(jià)值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教2022-04-04
Vue實(shí)現(xiàn)插槽下渲染dom字符串的使用
本文主要介紹了Vue實(shí)現(xiàn)插槽下渲染dom字符串的使用,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2023-04-04
electron-vue?項(xiàng)目添加啟動loading動畫的實(shí)現(xiàn)思路
electron-vue腳手架搭建的項(xiàng)目,在開發(fā)階段可能你注意不到項(xiàng)目啟動慢的問題,但是在build?生成的exe可執(zhí)行文件,啟動后,要反應(yīng)很久才能進(jìn)入到app.vue?中加載的頁面,體驗(yàn)性很差,本文給大家介紹electron?vue啟動動畫效果的實(shí)例代碼,感興趣的朋友一起看看吧2022-01-01

