Clipboard operations
Through a set of dedicated methods, HyperFormula supports clipboard operations, such as copying, cutting, and pasting. This lets you integrate the functionality of interacting with the clipboard.
The copied or cut data is stored as a memory reference, not directly in the system clipboard.
To copy the contents of a cell or range, use the copy() method. Pass arguments of type SimpleCellRange.
const hfInstance = HyperFormula.buildFromArray([ ['1', '2'],], { licenseKey: 'gpl-v3' });
// copy [ [ 2 ] ]const clipboardContent = hfInstance.copy({ start: { sheet: 0, col: 1, row: 0 }, end: { sheet: 0, col: 1, row: 0 },});To cut the contents of a cell or range, use the cut() method. Pass arguments of type SimpleCellRange.
const hfInstance = HyperFormula.buildFromArray([ ['1', '2'],], { licenseKey: 'gpl-v3' });
// returns the values that were cut: [ [ 1 ] ]const clipboardContent = hfInstance.cut({ start: { sheet: 0, col: 0, row: 0 }, end: { sheet: 0, col: 0, row: 0 },});To paste the contents of a cell or range, use the paste() method.
paste() requires only one parameter: the top left corner of the target range.
const hfInstance = HyperFormula.buildFromArray([ ['1', '2'],], { licenseKey: 'gpl-v3' });
// [ [ 2 ] ] was copiedconst clipboardContent = hfInstance.copy({ start: { sheet: 0, col: 1, row: 0 }, end: { sheet: 0, col: 1, row: 0 },});
// returns a list of modified cells: their absolute addresses and new valuesconst changes = hfInstance.paste({ sheet: 0, col: 1, row: 0 });If the clipboard is empty, the paste() method doesn’t do anything.
Copy and paste
Section titled “Copy and paste”When called after copy(), the paste() method:
- Pastes the copied data into the target range.
- Triggers a recalculation of all affected formulas.
Cut and paste
Section titled “Cut and paste”When called after cut(), the paste() method:
- Moves the cut data into the target range, by calling the
moveCells()method. - Removes the cut data from the source range.
- Triggers a recalculation of all affected formulas.
Pasting named expressions
Section titled “Pasting named expressions”If a copied or cut formula contains a named expression defined for a local scope, and the formula is pasted to a sheet that is out of scope for that expression, the expression’s scope changes to global.
If the copied or cut named expression’s scope is the same as the target’s, the expression’s local scope remains the same.
Clear the clipboard
Section titled “Clear the clipboard”To clear the clipboard, use the clearClipboard()
method.
To check if the clipboard holds any data, use the isClipboardEmpty() method.
Data storage
Section titled “Data storage”The copied or cut data is stored as a memory reference, not directly in the system clipboard.
Depending on what was cut, the data is stored as:
- An array of arrays
- A number
- A string
- A boolean
- An empty value
| Name | Surname | Both |
|---|