-
-
Save KiranMantha/28ac405d5d15438ce11fdbb7e4944a12 to your computer and use it in GitHub Desktop.
Copy HTML table to clipboard, for pasting in Excel (javascript)
This file contains hidden or 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