vxe-table 实现复制粘贴、单元格选取、Excel 单元格复制粘贴功能

官网: https://vxetable.cn

复制粘贴,通过 keyboard-config.isClip 启用,支持快捷键操作:
Ctrl + A 选择全部单元格;
Ctrl + X 将单元格标记为剪贴状态并将内容复制到剪贴板(支持 Excel 和 WPS) ;
Ctrl + C 将单元格标记为复制状态并将内容复制到剪贴板(支持 Excel 和 WPS) ;
Ctrl + V 将剪贴板的内容粘贴到指定区域中(支持 Excel 和 WPS) ;

<template>
  <div>
    <vxe-table
      border
      show-overflow
      height="500"
      :column-config="columnConfig"
      :mouse-config="mouseConfig"
      :area-config="areaConfig"
      :edit-config="editConfig"
      :keyboard-config="keyboardConfig"
      :data="tableData">
      <vxe-column type="seq" width="60"></vxe-column>
      <vxe-column field="name" title="Name" :edit-render="{ name: 'input' }"></vxe-column>
      <vxe-column field="role" title="Role" :edit-render="{ name: 'input' }"></vxe-column>
      <vxe-column field="sex" title="Sex" :edit-render="{ name: 'input' }"></vxe-column>
      <vxe-column field="num" title="Num" :edit-render="{ name: 'input' }"></vxe-column>
      <vxe-column field="age" title="Age" :edit-render="{ name: 'input' }"></vxe-column>
      <vxe-column field="address" title="Address" width="200" :edit-render="{ name: 'input' }"></vxe-column>
    </vxe-table>
  </div>
</template>

<script setup>
import { ref, reactive } from 'vue'

const tableData = ref([
  { id: 10001, name: 'Test1', role: 'Develop', sex: 'Man', num: 23, age: 28, address: 'Shengzhen' },
  { id: 10002, name: 'Test2', role: 'Test', sex: 'Women', num: 23, age: 22, address: 'Guangzhou' },
  { id: 10003, name: 'Test3', role: 'PM', sex: 'Man', num: 23, age: 32, address: 'Shanghai' },
  { id: 10004, name: 'Test4', role: 'Designer', sex: 'Women', num: 456, age: 24, address: 'Shanghai' },
  { id: 10005, name: 'Test5', role: 'Designer', sex: 'Women', num: 23, age: 42, address: 'Guangzhou' },
  { id: 10006, name: 'Test6', role: 'Designer', sex: 'Man', num: 23, age: 38, address: 'Shengzhen' },
  { id: 10007, name: 'Test7', role: 'Test', sex: 'Women', num: 100, age: 24, address: 'Shengzhen' },
  { id: 10008, name: 'Test8', role: 'PM', sex: 'Man', num: 345, age: 34, address: 'Shanghai' },
  { id: 10009, name: 'Test9', role: 'Designer', sex: 'Man', num: 67, age: 52, address: 'Shanghai' },
  { id: 10010, name: 'Test10', role: 'Test', sex: 'Women', num: 23, age: 44, address: 'Guangzhou' },
  { id: 10011, name: 'Test11', role: 'Designer', sex: 'Man', num: 56, age: 52, address: 'Shanghai' },
  { id: 10012, name: 'Test12', role: 'Test', sex: 'Women', num: 23, age: 16, address: 'Guangzhou' },
  { id: 10013, name: 'Test13', role: 'Test', sex: 'Women', num: 38, age: 16, address: 'Shanghai' },
  { id: 10014, name: 'Test14', role: 'Test', sex: 'Man', num: 37, age: 16, address: 'Shengzhen' },
  { id: 10015, name: 'Test15', role: 'Test', sex: 'Women', num: 23, age: 16, address: 'Shengzhen' },
  { id: 10016, name: 'Test16', role: 'Test', sex: 'Women', num: 58, age: 16, address: 'Guangzhou' },
  { id: 10017, name: 'Test17', role: 'Test', sex: 'Man', num: 23, age: 16, address: 'Shanghai' },
  { id: 10018, name: 'Test18', role: 'Test', sex: 'Women', num: 52, age: 16, address: 'Shengzhen' },
  { id: 10019, name: 'Test19', role: 'Test', sex: 'Man', num: 37, age: 16, address: 'Guangzhou' },
  { id: 10020, name: 'Test20', role: 'Test', sex: 'Women', num: 23, age: 16, address: 'Shanghai' },
  { id: 10021, name: 'Test21', role: 'Test', sex: 'Man', num: 56, age: 16, address: 'Shengzhen' },
  { id: 10022, name: 'Test22', role: 'Test', sex: 'Women', num: 49, age: 16, address: 'Guangzhou' },
  { id: 10023, name: 'Test23', role: 'Test', sex: 'Man', num: 48, age: 16, address: 'Shengzhen' }
])

const columnConfig = reactive({
  resizable: true
})

const mouseConfig = reactive({
  area: true // 是否开启区域选取
})

const areaConfig = reactive({
  multiple: true // 是否启用多区域选取功能
})

const editConfig = reactive({
  mode: 'cell',
  trigger: 'dblclick'
})

const keyboardConfig = reactive({
  isClip: true,
  isEdit: true,
  isDel: true,
  isEsc: true // 是否开启Esc键关闭编辑功能
})
</script>
posted @ 2024-11-21 15:05  可不简单  阅读(4)  评论(0编辑  收藏  举报