javascript - 如何从excel中复制一行并粘贴到制表符表格中以保持字段可编辑?
问题描述
我正在使用带有 vue.js 的制表器库,我想从 excel 中复制单行或多行并将其粘贴到制表器表中,但是这样做时,数据只会粘贴到一列中。
下面是来自 excel 的数据,我想复制这些数据并粘贴到制表符表(注意:制表符表也有 3 列)所以在粘贴这些 excel 数据时,这些数据被添加到制表符的一列中,但我想要这些复制的数据应添加到 3 列。谁能建议我该怎么做?
这是我的代码:
<template>
<div ref="table"></div>
</template>
<script>
import Tabulator from 'tabulator-tables'; //import Tabulator library
import 'tabulator-tables/dist/css/tabulator.min.css';
import moment from 'moment';
export default {
data: function() {
return {
tabulator: null, //variable to hold your table
tableData: [
], //data for table to display
columns: [
{
title: 'Name',
field: 'name',
editor: 'input',
validator: ['required', 'maxLength:50'],
},
{
title: 'Task',
field: 'owner',
editor: 'input',
},
{
title: 'Start Date',
field: 'start_date',
sorter: 'date',
editor: 'input',
validator: 'required',
},
],
};
},
watch: {
//update table if data changes
tableData: {
handler: function(newData) {
this.tabulator.replaceData(newData);
},
deep: true,
},
},
mounted() {
//instantiate Tabulator when element is mounted
this.tabulator = new Tabulator(this.$refs.table, {
data: this.tableData, //link data to table
reactiveData: true, //enable data reactivity'
layout: 'fitColumns',
columns: this.columns, //define table columns
selectable: false,
});
},
};
</script>
解决方案
您似乎没有在表格中启用剪贴板功能,如果没有启用此功能,制表器将无法接受粘贴的数据。
您需要在表构造函数中设置剪贴板选项
var table = new Tabulator("#example-table", {
clipboard:"paste", //enable clipboard paste functionality
});
有关完整详细信息,请参阅剪贴板文档
推荐阅读
- java - 将已经运行的 java 程序带到前台
- ios - IOS/Objective-C/Storyboard:手势识别器可通过 Tabbar 访问整个应用程序吗?
- amazon-web-services - 添加将所有电子邮件地址列入白名单以使用 AWS SES 发送电子邮件的功能?
- performance - Cython:如何有效地对 memoryviewslice 对象求和?
- sql - case语句中的多个值用作where子句sql oracle的右操作数
- kubernetes - k8s:在 pod 部署后将文件复制到容器
- xml - 使用 Logstash 将 XML 加载到 Elasticsearch
- css - 仅显示方块来代替阿拉伯字符
- javascript - 回调函数说明
- java - 如何将字节转换为int并与值进行比较