Clipboard in Vue Spreadsheet component
11 Jun 202418 minutes to read
The Spreadsheet provides support for the clipboard operations (cut, copy, and paste). Clipboard operations can be enabled or disabled by setting the enableClipboard
property in Spreadsheet.
By default, the
enableClipboard
property is true.
Cut
It is used to cut the data from selected range of cells, rows or columns in a spreadsheet and make it available in the clipboard.
User Interface:
Cut can be done in one of the following ways.
- Using Cut button in the Ribbon’s HOME tab to perform cut operation.
- Using Cut option in the Context Menu.
-
Using Ctrl + X
Command + X
keyboard shortcut. - Using the
cut
method.
Copy
It is used to copy the data from selected range of cells, rows or columns in a spreadsheet and make it available in the clipboard.
User Interface:
Copy can be done in one of the following ways.
- Using Copy button in the Ribbon’s HOME tab to perform copy operation.
- Using Copy option in the Context Menu.
-
Using Ctrl + C
Command + C
keyboard shortcut. - Using the
copy
method.
Paste
It is used to paste the clipboard data to the selected range, rows or columns. You have the following options in Paste,
-
Paste Special
- You can paste the values with formatting. -
Paste
- You can paste only the values without formatting.
It also performs for external clipboard operation. If you perform cut and paste, clipboard data will be cleared, whereas in copy and paste the clipboard contents will be maintained. If you perform paste inside the copied range, the clipboard data will be cleared.
User Interface:
Paste can be done in one of the following ways.
- Using Paste button in the Ribbon’s HOME tab to perform paste operation.
- Using Paste option in the Context Menu.
-
Using Ctrl + V
Command + V
keyboard shortcut. - Using the
paste
method.
If you use the Keyboard shortcut key for cut ( Ctrl + X
)copy ( Ctrl + C
) from other sources, you should useCtrl + V
shortcut while pasting into the spreadsheet.
<template>
<div>
<ejs-dropdownbutton :items='items' :select='itemSelect'>Clipboard</ejs-dropdownbutton>
<ejs-spreadsheet ref="spreadsheet" :created="created">
<e-sheets>
<e-sheet>
<e-ranges>
<e-range :dataSource="dataSource"></e-range>
</e-ranges>
<e-columns>
<e-column :width="width1"></e-column>
<e-column :width="width2"></e-column>
</e-columns>
</e-sheet>
</e-sheets></ejs-spreadsheet>
</div>
</template>
<script setup>
import { ref } from "vue";
import { SpreadsheetComponent as EjsSpreadsheet, ColumnsDirective as EColumns, ColumnDirective as EColumn, RangesDirective as ERanges, RangeDirective as ERange, SheetsDirective as ESheets, SheetDirective as ESheet } from "@syncfusion/ej2-vue-spreadsheet";
import { DropDownButtonComponent as EjsDropdownbutton } from "@syncfusion/ej2-vue-splitbuttons";
import { defaultData } from './data.js';
const dataSource = defaultData;
const width1 = 130;
const width2 = 96;
const spreadsheet = ref(null);
const items = [
{
text: "Cut"
},
{
text: "Copy"
},
{
text: "Paste"
}];
const created = function () {
spreadsheet.value.cellFormat({ fontWeight: 'bold', textAlign: 'center' }, 'A1:H1');
};
const itemSelect = function (args) {
if (args.item.text === 'Cut')
spreadsheet.value.cut();
if (args.item.text === 'Copy')
spreadsheet.value.copy();
if (args.item.text === 'Paste')
spreadsheet.value.paste();
}
</script>
<style>
@import "../node_modules/@syncfusion/ej2-vue-spreadsheet/styles/material.css";
@import '../node_modules/@syncfusion/ej2-base/styles/material.css';
@import '../node_modules/@syncfusion/ej2-buttons/styles/material.css';
@import '../node_modules/@syncfusion/ej2-dropdowns/styles/material.css';
@import '../node_modules/@syncfusion/ej2-inputs/styles/material.css';
@import '../node_modules/@syncfusion/ej2-navigations/styles/material.css';
@import '../node_modules/@syncfusion/ej2-popups/styles/material.css';
@import '../node_modules/@syncfusion/ej2-splitbuttons/styles/material.css';
@import '../node_modules/@syncfusion/ej2-grids/styles/material.css';
@import "../node_modules/@syncfusion/ej2-spreadsheet/styles/material.css";
</style>
<template>
<div>
<ejs-dropdownbutton :items='items' :select='itemSelect'>Clipboard</ejs-dropdownbutton>
<ejs-spreadsheet ref="spreadsheet" :created="created">
<e-sheets>
<e-sheet>
<e-ranges>
<e-range :dataSource="dataSource"></e-range>
</e-ranges>
<e-columns>
<e-column :width="width1"></e-column>
<e-column :width="width2"></e-column>
</e-columns>
</e-sheet>
</e-sheets></ejs-spreadsheet>
</div>
</template>
<script>
import { SpreadsheetComponent, ColumnsDirective, ColumnDirective, RangesDirective, RangeDirective, SheetsDirective, SheetDirective } from "@syncfusion/ej2-vue-spreadsheet";
import { DropDownButtonComponent } from "@syncfusion/ej2-vue-splitbuttons";
import { defaultData } from './data.js';
export default {
name: "App",
components: {
"ejs-dropdownbutton": DropDownButtonComponent,
"ejs-spreadsheet": SpreadsheetComponent,
"e-sheets": SheetsDirective,
"e-sheet": SheetDirective,
"e-ranges": RangesDirective,
"e-range": RangeDirective,
"e-columns": ColumnsDirective,
"e-column": ColumnDirective
},
data: () => {
return {
dataSource: defaultData,
width1: 130,
width2: 96,
items: [
{
text: "Cut"
},
{
text: "Copy"
},
{
text: "Paste"
}]
}
},
methods: {
created: function () {
let spreadsheet = this.$refs.spreadsheet;
spreadsheet.cellFormat({ fontWeight: 'bold', textAlign: 'center' }, 'A1:H1');
},
itemSelect: function (args) {
let spreadsheet = this.$refs.spreadsheet;
if (args.item.text === 'Cut')
spreadsheet.cut();
if (args.item.text === 'Copy')
spreadsheet.copy();
if (args.item.text === 'Paste')
spreadsheet.paste();
}
}
}
</script>
<style>
@import "../node_modules/@syncfusion/ej2-vue-spreadsheet/styles/material.css";
@import '../node_modules/@syncfusion/ej2-base/styles/material.css';
@import '../node_modules/@syncfusion/ej2-buttons/styles/material.css';
@import '../node_modules/@syncfusion/ej2-dropdowns/styles/material.css';
@import '../node_modules/@syncfusion/ej2-inputs/styles/material.css';
@import '../node_modules/@syncfusion/ej2-navigations/styles/material.css';
@import '../node_modules/@syncfusion/ej2-popups/styles/material.css';
@import '../node_modules/@syncfusion/ej2-splitbuttons/styles/material.css';
@import '../node_modules/@syncfusion/ej2-grids/styles/material.css';
@import "../node_modules/@syncfusion/ej2-spreadsheet/styles/material.css";
</style>
Prevent the paste functionality
The following example shows, how to prevent the paste action in spreadsheet. In actionBegin
event, you can set cancel
argument as false in paste request type.
<template>
<div>
<ejs-dropdownbutton :items='items' :select='itemSelect'>Clipboard</ejs-dropdownbutton>
<ejs-spreadsheet ref="spreadsheet" :created="created" :actionBegin="actionBeginHandler">
<e-sheets>
<e-sheet>
<e-ranges>
<e-range :dataSource="dataSource"></e-range>
</e-ranges>
<e-columns>
<e-column :width="width1"></e-column>
<e-column :width="width2"></e-column>
</e-columns>
</e-sheet>
</e-sheets></ejs-spreadsheet>
</div>
</template>
<script setup>
import { ref } from "vue";
import { SpreadsheetComponent as EjsSpreadsheet, ColumnsDirective as EColumns, ColumnDirective as EColumn, RangesDirective as ERanges, RangeDirective as ERange, SheetsDirective as ESheets, SheetDirective as ESheet } from "@syncfusion/ej2-vue-spreadsheet";
import { DropDownButtonComponent as EjsDropdownbutton } from "@syncfusion/ej2-vue-splitbuttons";
import { defaultData } from './data.js';
const spreadsheet = ref(null);
const dataSource = defaultData;
const width1 = 130;
const width2 = 96;
const items = [
{
text: "Cut"
},
{
text: "Copy"
},
{
text: "Paste"
}]
const created = function () {
spreadsheet.value.cellFormat({ fontWeight: 'bold', textAlign: 'center' }, 'A1:H1');
}
// Triggers before the action begins.
const actionBeginHandler = function (pasteArgs) {
// To cancel the paste action.
if (pasteArgs.args.eventArgs.requestType === 'paste') {
pasteArgs.args.eventArgs.cancel = true;
}
}
const itemSelect = function (args) {
if (args.item.text === 'Cut')
spreadsheet.value.cut();
if (args.item.text === 'Copy')
spreadsheet.value.copy();
if (args.item.text === 'Paste')
spreadsheet.value.paste();
}
</script>
<style>
@import '../node_modules/@syncfusion/ej2-base/styles/material.css';
@import '../node_modules/@syncfusion/ej2-buttons/styles/material.css';
@import '../node_modules/@syncfusion/ej2-dropdowns/styles/material.css';
@import '../node_modules/@syncfusion/ej2-inputs/styles/material.css';
@import '../node_modules/@syncfusion/ej2-navigations/styles/material.css';
@import '../node_modules/@syncfusion/ej2-popups/styles/material.css';
@import '../node_modules/@syncfusion/ej2-splitbuttons/styles/material.css';
@import '../node_modules/@syncfusion/ej2-grids/styles/material.css';
@import "../node_modules/@syncfusion/ej2-vue-spreadsheet/styles/material.css";
</style>
<template>
<div>
<ejs-dropdownbutton :items='items' :select='itemSelect'>Clipboard</ejs-dropdownbutton>
<ejs-spreadsheet ref="spreadsheet" :created="created" :actionBegin="actionBeginHandler">
<e-sheets>
<e-sheet>
<e-ranges>
<e-range :dataSource="dataSource"></e-range>
</e-ranges>
<e-columns>
<e-column :width="width1"></e-column>
<e-column :width="width2"></e-column>
</e-columns>
</e-sheet>
</e-sheets></ejs-spreadsheet>
</div>
</template>
<script>
import { SpreadsheetComponent, ColumnsDirective, ColumnDirective, RangesDirective, RangeDirective, SheetsDirective, SheetDirective } from "@syncfusion/ej2-vue-spreadsheet";
import { DropDownButtonComponent } from "@syncfusion/ej2-vue-splitbuttons";
import { defaultData } from './data.js';
export default {
name: "App",
components: {
"ejs-dropdownbutton": DropDownButtonComponent,
"ejs-spreadsheet": SpreadsheetComponent,
"e-sheets": SheetsDirective,
"e-sheet": SheetDirective,
"e-ranges": RangesDirective,
"e-range": RangeDirective,
"e-columns": ColumnsDirective,
"e-column": ColumnDirective
},
data: () => {
return {
dataSource: defaultData,
width1: 130,
width2: 96,
items: [
{
text: "Cut"
},
{
text: "Copy"
},
{
text: "Paste"
}]
}
},
methods: {
created: function () {
let spreadsheet = this.$refs.spreadsheet;
spreadsheet.cellFormat({ fontWeight: 'bold', textAlign: 'center' }, 'A1:H1');
},// Triggers before the action begins.
actionBeginHandler: function (pasteArgs) {
// To cancel the paste action.
if (pasteArgs.args.eventArgs.requestType === 'paste') {
pasteArgs.args.eventArgs.cancel = true;
}
},
itemSelect: function (args) {
let spreadsheet = this.$refs.spreadsheet;
if (args.item.text === 'Cut')
spreadsheet.cut();
if (args.item.text === 'Copy')
spreadsheet.copy();
if (args.item.text === 'Paste')
spreadsheet.paste();
}
}
}
</script>
<style>
@import '../node_modules/@syncfusion/ej2-base/styles/material.css';
@import '../node_modules/@syncfusion/ej2-buttons/styles/material.css';
@import '../node_modules/@syncfusion/ej2-dropdowns/styles/material.css';
@import '../node_modules/@syncfusion/ej2-inputs/styles/material.css';
@import '../node_modules/@syncfusion/ej2-navigations/styles/material.css';
@import '../node_modules/@syncfusion/ej2-popups/styles/material.css';
@import '../node_modules/@syncfusion/ej2-splitbuttons/styles/material.css';
@import '../node_modules/@syncfusion/ej2-grids/styles/material.css';
@import "../node_modules/@syncfusion/ej2-vue-spreadsheet/styles/material.css";
</style>
Limitations
- External clipboard is not fully supported while copying data from another source and pasting into a spreadsheet, it only works with basic supports (Values, Number, cell, and Text formatting).
- If you copy =SUM(A2,B2) and paste, the formula reference will change depending on the pasted cell address but we don’t have support for nested formula(formula reference will be same).
- Clipboard is not supported with conditional formatting (values only pasting).
- We have limitation while copying the whole sheet data and pasting it into another sheet.
Note
You can refer to our Vue Spreadsheet feature tour page for its groundbreaking feature representations. You can also explore our Vue Spreadsheet example to knows how to present and manipulate data.