Last active
October 10, 2024 07:31
-
-
Save drodsou/9989ed5c8f30bf9e213117f795c72f67 to your computer and use it in GitHub Desktop.
Copy HTML table to clipboard, for pasting in Excel (javascript)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// In Excel make sure to have this option enabled: Home / Clipboard / Options / Collect without showing the Office clipboard | |
// Tested in Windows 10 only | |
let table = document.querySelector('#table').outerHTML; | |
table = table | |
.replaceAll('\n','<br style="mso-data-placement:same-cell;"/>') // new lines inside html cells => Alt+Enter in Excel | |
.replaceAll('<td','<td style="vertical-align: top;"'); // align top | |
navigator.clipboard.writeText(table).then( | |
()=>console.log("success"), | |
(e)=>console.log("error", e), | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment