I create data on a website, which is table like. I want to copy that data to excel. I do that using Tabs to go to the next cell in the row and newlines to go to the next row:
let clipboard = 'My link' + "\t" + secondCell + "\t" + thirdCell + "\n" +
firstCellSecondRow + "\t" + secondCellSecondRow + "\t" + thirdCellSecondRow;
navigator.clipboard.writeText(clipboard);
Copying that text into an excel table works well:
Now my challenge is, that I want to add a link to text of one cell. My intuitive approach was to add the following text to the clipboard:
let clipboard = '<a href="https://www.my-url.com">My link</a>' + "\t" + secondCell + "\t" + thirdCell + "\n" +
firstCellSecondRow + "\t" + secondCellSecondRow + "\t" + thirdCellSecondRow;
navigator.clipboard.writeText(clipboard);
But that doesn't work, it will actually display the text with the html in it:
What I want is only the text "My link" and an actual link that is clickable:
Since copying of text with links is possible in excel, I feel that it should somehow work. Can I do that with javascript?
In Excel, select the cell that will be in the upper left corner of the pasted data. Go to Home and select the Paste dropdown arrow to display a list of Paste Options. Choose a Link option. The linked data appears in the destination file.
3. Locate the "Clipboard" area of the ribbon, located on the far-left end. Click the small arrow to the right of the word "Clipboard" and the clipboard will appear on the left edge of the Excel spreadsheet. Click on any item in the clipboard to paste it into whatever cell you currently have selected.
Here's how to copy your table to clipboard: Click to select the Table on Piktochart. With your keyboard shortcut, use CTRL+C to copy the table.
This method is based on the shortcut key CTRL+V which is used to paste data. With a VBA code, you can use this command to paste data from the clipboard. First, ➤ Right-click on the sheet name from the Project panel of the VBA window. A dropdown menu will appear.
Each cell is separated by a tab stop, and each record exists on a separate line in the text file. Select all of the text you want to copy to Excel and copy it to your clipboard. 2. Select the cell in Excel that you want to paste into. Select the upper-leftmost cell that you want your pasted data to appear in.
To copy a hyperlink in excel, the use of a mouse click is the easiest and most convenient way. In the following dataset, we will copy the hyperlink of the company “Exceldemy”. After that, we will paste it to cell C12.
How to automatically copy a cell to clipboard with single click in Excel? Normally, when copying a cell to clipboard, you need to select the cell firstly, and then press the Ctrl + C key to copy it. How to automatically copy a cell by just clicking on it without pressing the hotkeys?
Here is how you achieve it in JavaScript:
let html = '<table><tr><td><a href="https://www.my-url.com">My link</a></td><td>secondCell</td></tr><tr><td>firstCellSecondRow</td><td>secondCellSecondRow</td></tr></table>';
const blob = new Blob([html], { type: "text/html" });
navigator.clipboard.write([new ClipboardItem({ [blob.type]: blob })]);
I didn't write it as a snippet in the answer because StackOverflow has security limitations that disallows the clipboard in snippets.
If you try it in your console, this error may occur:
Uncaught (in promise) DOMException: Document is not focused.
Here is a console-testable version of the code, it implies that you click on the page during the 3s timeout:
let html = '<table><tr><td><a href="https://www.my-url.com">My link</a></td><td>secondCell</td></tr><tr><td>firstCellSecondRow</td><td>secondCellSecondRow</td></tr></table>';
const blob = new Blob([html], { type: "text/html" });
setTimeout(() => navigator.clipboard.write([new ClipboardItem({ [blob.type]: blob })]), 3000);
Result in Excel:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With