docs/content/guides/cell-features/clipboard/clipboard.md
Copy data from selected cells to the system clipboard.
[[toc]]
Handsontable supports copy, cut, and paste via the browser clipboard API and keyboard shortcuts. Configure clipboard behavior to control what data users can copy or paste.
You can copy or cut data from Handsontable to the system clipboard, either manually (using the context menu or the <kbd>Ctrl</kbd>/<kbd>⌘</kbd>+<kbd>C</kbd>/<kbd>X</kbd> shortcuts) or programmatically (using Handsontable's API methods).
Copy & Cut actions allow exporting data from Handsontable to the system clipboard. The CopyPaste plugin copies and cuts data as a text/plain and a text/html MIME-type.
Available keyboard shortcuts:
Available options in the browser's toolbar:
Edit > Copy - copies the content of the last cell in the selected rangeEdit > Cut - cuts the content of the last cell in the selected rangeTo let the end user copy the contents of column headers, see the Copy with headers section.
When the context menu is enabled, it includes default items, including copy & cut options.
copycutYou can use them in the same way as the rest of the predefined items in the context menu. These operations are executed by document.execCommand().
::: only-for javascript ::: example #example1 --js 1 --ts 2
::: :::
::: only-for react ::: example #example1 :react --js 1 --ts 2
::: :::
::: only-for angular ::: example #example1 :angular --ts 1 --html 2
::: :::
::: only-for vue ::: example #example1 :vue3
@code
::: :::
::: only-for react ::: tip
To use the Handsontable API, you'll need access to the Handsontable instance. You can do that by utilizing a reference to the HotTable component, and reading its hotInstance property.
For more information, see the Instance methods page.
::: :::
::: only-for angular ::: tip
To use the Handsontable API, you'll need access to the Handsontable instance. You can do that by utilizing a reference to the HotTable component, and reading its hotInstance property.
For more information, see the Instance access page.
::: :::
::: only-for vue ::: tip
To use the Handsontable API, add a template ref on <HotTable> and read hotTableRef.value?.hotInstance.
::: :::
First, select a cell range to copy or cut.
hot.selectCell(1, 1);
Then use one of the following commands:
document.execCommand('copy')document.execCommand('cut')The CopyPaste plugin listens to the browser's copy and cut events. If triggered, our implementation will copy or cut the selected data to the system clipboard.
::: only-for javascript ::: example #example3 --html 1 --js 2 --ts 3
::: :::
::: only-for react ::: example #example3 :react --js 1 --ts 2
::: :::
::: only-for angular ::: example #example3 :angular --ts 1 --html 2
::: :::
::: only-for vue ::: example #example3 :vue3
@code
::: :::
Mind that some of Handsontable's selection-related methods don't set focus on your grid automatically. To make sure that your grid is focused, call isListening() before you copy, cut or paste data.
The CopyPaste plugin exposes the following hooks to manipulate data during copy or cut operations:
Examples of how to use them are provided in their descriptions.
You can let the end user copy the contents of column headers, by enabling additional context menu items:
<span class="img-light"> </span> <span class="img-dark"> </span>Right-click on a cell to try it out:
::: only-for javascript ::: example #example2 --js 1 --ts 2
::: :::
::: only-for react ::: example #example2 :react --js 1 --ts 2
::: :::
::: only-for angular ::: example #example2 :angular --ts 1 --html 2
::: :::
::: only-for vue ::: example #example2 :vue3
@code
::: :::
To add the context menu items, configure the CopyPaste plugin with these options:
copyPaste: {
copyColumnHeaders: true,
copyColumnGroupHeaders: true,
copyColumnHeadersOnly: true,
}
To copy column headers programmatically, call the copyPaste.copy() method with these arguments:
::: only-for react ::: tip
To use the Handsontable API, you'll need access to the Handsontable instance. You can do that by utilizing a reference to the HotTable component, and reading its hotInstance property.
For more information, see the Instance methods page.
::: :::
::: only-for angular ::: tip
To use the Handsontable API, you'll need access to the Handsontable instance. You can do that by utilizing a reference to the HotTable component, and reading its hotInstance property.
For more information, see the Instance access page.
::: :::
::: only-for vue ::: tip
To use the Handsontable API, add a template ref on <HotTable> and read hotTableRef.value?.hotInstance.
::: :::
// access the `CopyPaste` plugin instance
const copyPastePlugin = hot.getPlugin('copyPaste');
// select some cells
hot.selectCell(1, 1);
// copy the selected cells along with their nearest column headers
copyPastePlugin.copy('with-column-headers');
// copy the selected cells along with all their related columns
// headers
copyPastePlugin.copy('with-all-column-headers');
// copy the column headers nearest to the selected cells
// (without copying the cells themselves)
copyPastePlugin.copy('column-headers-only');
The Paste action allows the importing of data from external sources, using the user's system clipboard. The CopyPaste plugin firstly looks for text/html in the system clipboard, followed by text/plain.
The parsePastedValue option controls how pasted content is written to cells when the user pastes from the clipboard into Handsontable (e.g. from another Handsontable instance or between cells in the same table). It does not affect how other applications read or process the clipboard.
By default (parsePastedValue: false), pasted content is written as plain strings. Non-scalar values such as objects are coerced to string (e.g. an object becomes "[object Object]"), which keeps the data model simple and avoids parsing clipboard text. Set parsePastedValue: true when you need to preserve JavaScript structures across paste: pasted text is then parsed (e.g. JSON-like content) and the resulting values are written to the data source, so you can copy and paste objects or arrays between cells or between instances. With parsing enabled, schema validation is relaxed so object-based values can be pasted into cells that would normally expect a scalar.
Available keyboard shortcuts:
Available options in the browser's toolbar:
Edit > Paste - paste the content into the last cell in the selected rangeDue to security reasons, modern browsers disallow reading from the system clipboard. Learn more
Due to security reasons, modern browsers disallow reading from the system clipboard. Learn more
The CopyPaste plugin exposes the following hooks to manipulate data during the pasting operation:
Examples of how to use them are provided in their descriptions.
CopyPaste plugin doesn't copy, cut or paste cells' appearance.'true'.document.execCommand can be called only during an immediate-execute event, such as a MouseEvent or a KeyboardEvent.| Windows | macOS | Action | Excel | Sheets |
|---|---|---|---|---|
| <kbd>Ctrl</kbd>+<kbd>X</kbd> | <kbd>⌘</kbd>+<kbd>X</kbd> | Cut the contents of the selected cells to the system clipboard | ✓ | ✓ |
| <kbd>Ctrl</kbd>+<kbd>C</kbd> | <kbd>⌘</kbd>+<kbd>C</kbd> | Copy the contents of the selected cells to the system clipboard | ✓ | ✓ |
| <kbd>Ctrl</kbd>+<kbd>V</kbd> | <kbd>⌘</kbd>+<kbd>V</kbd> | Paste from the system clipboard | ✓ | ✓ |
Configuration options
<div class="boxes-list"> </div>Core methods
<div class="boxes-list"> </div>Hooks
<div class="boxes-list"> </div>Plugins
<div class="boxes-list"> </div>Users can copy, cut, and paste cell data using keyboard shortcuts or the context menu. Programmatic copy and cut operations work by calling document.execCommand() after selecting the target cells.