Created
October 4, 2022 22:27
-
-
Save shanecandoit/aa6b9f423c21ec08b8934521c31dd112 to your computer and use it in GitHub Desktop.
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
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="utf-8"> | |
<meta http-equiv="X-UA-Compatible" content="IE=edge"> | |
<title></title> | |
<meta name="description" content=""> | |
<meta name="viewport" content="width=device-width, initial-scale=1"> | |
<link rel="stylesheet" href=""> | |
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script> | |
<style> | |
table{ | |
border: 1px solid red; | |
border-collapse: separate; | |
border-spacing: 0px; | |
} | |
td{ | |
border: 1px solid blue; | |
padding: 6px; | |
margin: 0px; | |
} | |
tbody tr:first-child { | |
background: black; | |
color: white; | |
} | |
</style> | |
</head> | |
<body> | |
<textarea name="excel_data"> | |
id name x y | |
1 a 345 324 | |
2 b 57 3425 | |
3 c 235 46 | |
4 d 3463 235 | |
5 e 456 344 | |
</textarea> | |
<br> <br> | |
<input type="button" onclick="tablize()" value="tablize"> | |
<br> <br> | |
<div id="excel_table" style="border:1px solid grey;"> | |
</div> | |
<script > | |
function tablize() { | |
// https://stackoverflow.com/questions/2006468/copy-paste-from-excel-to-a-web-page | |
var data = $('textarea[name=excel_data]').val(); | |
var rows = data.split("\n"); | |
var table = $('<table />'); | |
table.append('<tbody>'); | |
for(var y in rows) { | |
var cells = rows[y].split("\t"); | |
var row = $('<tr />'); | |
for(var x in cells) { | |
row.append('<td>'+cells[x]+'</td>'); | |
} | |
table.append(row); | |
} | |
// Insert into DOM | |
$('#excel_table').html(table); | |
} | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment