Last active
August 31, 2023 11:32
-
-
Save diewland/7e9b4de1eef4ac0c418a87bd5bfd363b to your computer and use it in GitHub Desktop.
Handle clipboard from Excel by 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
<h1>Handle paste clipboard from excel by JS</h1> | |
<div id='out'></div> | |
<script> | |
// https://stackoverflow.com/a/38326762/466693 | |
document.addEventListener('paste', function (event) { | |
window.clipText = event.clipboardData.getData('Text'); | |
render_table(clipText); | |
}); | |
function render_table(cb){ | |
var html = "<table border='1'>"; | |
cb.split("\n").forEach(function(line){ | |
if(line){ | |
html += "<tr>"; | |
html += line.split('\t').map(function(l){ return "<td>"+ l +"</td>"; }).join(''); | |
html += "</tr>"; | |
} | |
}); | |
html += "</table>"; | |
document.querySelector('#out').innerHTML = html; | |
} | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment