Skip to content

Instantly share code, notes, and snippets.

@diewland
Last active August 31, 2023 11:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save diewland/7e9b4de1eef4ac0c418a87bd5bfd363b to your computer and use it in GitHub Desktop.
Save diewland/7e9b4de1eef4ac0c418a87bd5bfd363b to your computer and use it in GitHub Desktop.
Handle clipboard from Excel by javascript
<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