How to introduce Excel table plug-in into Vue

How to introduce Excel table plug-in into Vue

This article shares the specific code of Vue introducing the Excel table plug-in for your reference. The specific content is as follows

1. Installation

npm install handsontable-pro @handsontable-pro/vue
npm install handsontable @handsontable/vue

2. Citation (Citation on the page)

import { HotTable } from '@handsontable-pro/vue'
import '…/…/node_modules/handsontable-pro/dist/handsontable.full.css'
import Handsontable from 'handsontable-pro'

3. Use (use in labels)

<div id="hotTable" class="hotTable">
    <HotTable ref="hotTableComponent" :settings="hotSettings"></HotTable>
</div>

4. Definition in Data

data () {
    return {
      list: [],
      root: 'test-hot',
      hotSettings: {
        data: [ // data can be a two-dimensional array or an array object],
        startRows: 3, // row and column range startCols: 3,
        minRows: 20, // Minimum number of rowsminCols: 5, // Minimum number of columnsmaxRows: 20, // Maximum number of rows and columnsmaxCols: 20, // Maximum number of columnsrowHeaders: true, // Row headers can be Boolean values ​​(row numbers), strings (the left row headers display the same content, and can parse HTML), or arrays (the left row headers display content separately).
        colHeaders: ['Account Level', 'Account Name', 'Account Number', 'Account Category'], // Custom column header or Boolean valueminSpareCols: 0, // Column blankminSpareRows: 0, // Row blankcurrentRowClassName: 'currentRow', // Add a class name for the selected row, you can change the stylecurrentColClassName: 'currentCol', // Add a class name for the selected columnautoWrapRow: true, // Automatic line wrapclassName: 'htCenter htMiddle', // Default cell style, vertical centercontextMenu: {
          items: {
            // 'row_above': {
            // name: 'Insert a row above'
            // },
            // 'row_below': {
            // name: 'Insert a row below'
            // },
            // 'col_left': {
            // name: 'Insert column to the left'
            // },
            // 'col_right': {
            // name: 'Insert column to the right'
            // },
            'hsep1': '---------', // Provide separator line 'remove_row': {
              name: 'Delete row'
            },
            'remove_col': {
              name: 'Delete column'
            },
            'make_read_only': {
              name: 'read-only'
            },
            'borders': {
              name: 'Table line'
            },
            'copy': {
              name: 'Copy'
            },
            'cut': {
              name: 'Cut'
            },
            'commentsAddEdit': {
              name: 'Add Notes'
            },
            'commentsRemove': {
              name: 'Cancel note'
            },
            'freeze_column': {
              name: 'Fixed columns'
            },
            'unfreeze_column': {
              name: 'Cancel column pinning'
            },
            'mergeCells': {
              name: 'Merge cells'
            },
            'alignment': {
              name: 'Text position'
            },
            'hsep2': '---------'
          }
        },
        afterChange: function (changes, source) { // This method is triggered when the data changes // console.log(this.getSourceData())
          this.list = this.getSourceData() // Get the data in the table // console.log(this.getPlugin('MergeCells').mergedCellsCollection.mergedCells) // Get the parameters of the merged cells in the table},
        manualColumnFreeze: true, // Manually fix columns?
        manualColumnMove: true, // Manually move columnsmanualRowMove: true, // Manually move rowsmanualColumnResize: true, // Manually change column spacingmanualRowResize: true, // Manually change row spacingcomments: true, // Add comments?
        // cell: [ // ???
        // {row: 1, col: 1, comment: {value: 'this is test'}}
        // ],
        customBorders: [], // Add borders columnSorting: true, // Sorting stretchH: 'all', // Expand horizontally according to width, last: only expand the last column, none: do not expand by default fillHandle: true, // Select and drag to copy possible values: true, false, "horizontal", "vertical"
        fixedColumnsLeft: 0, // Fixed the number of columns on the left fixedRowsTop: 0, // Fixed the number of columns on the top mergeCells: [ // Merge // {row: 1, col: 1, rowspan: 3, colspan: 3}, // Specify the merge, starting from (1,1), row 3 and column 3 are merged into one grid // {row: 3, col: 4, rowspan: 2, colspan: 2}
        ],
        columns: [ // Set the table header name {
            data: 'acctLevel'
          },
          {
            data: 'acctName'
          },
          {
            data: 'acctNo'
          },
          {
            data: 'acctType'
          },
        ]
      }
    }
  },

5. Introducing components

components:
    HotTable
 },

6. Use of methods

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)
    }
},

Key Points:

this.$refs.hotTableComponent.hotInstance // Get table data, call table method, ****** points to the table getPlugin('MergeCells').mergedCellsCollection.mergedCells) // Get the parameters needed after merging cells

Note: If you need to obtain data through the interface, just assign the data under this.hotSettings directly.

The above is the full content of this article. I hope it will be helpful for everyone’s study. I also hope that everyone will support 123WORDPRESS.COM.

You may also be interested in:
  • The whole process record of Vue export Excel function
  • Detailed steps to implement the Excel import function in Vue
  • How to export web page data to Excel in Vue
  • Vue imports excel table, and automatically downloads the data that failed to import

<<:  Detailed explanation of the practice of installing the Permeate range system using VMware

>>:  How to implement import and export mysql database commands under linux

Recommend

Vue+js realizes video fade-in and fade-out effect

Vue+js realizes the fade in and fade out of the v...

mysql5.7.22 download process diagram

1. Go to the official website www.mysql.com and s...

How to use vw+rem for mobile layout

Are you still using rem flexible layout? Does it ...

Tips for implementing multiple borders in CSS

1. Multiple borders[1] Background: box-shadow, ou...

Three Vue slots to solve parent-child component communication

Table of contents Preface Environment Preparation...

Better-scroll realizes the effect of linking menu and content

1. Basic use <!DOCTYPE html> <html lang=...

Vue globally introduces scss (mixin)

Table of contents 1. mixin.scss 2. Single file us...

Refs and Ref Details in Vue3

The editor also shares with you the corresponding...

Detailed example of removing duplicate data in MySQL

Detailed example of removing duplicate data in My...

MySQL 8.0.20 winx64 installation and configuration method graphic tutorial

This article shares with you the installation and...

Solution to IDEA not being able to connect to MySQL port number occupation

I can log in to MYSQL normally under the command ...