Created
September 16, 2011 04:13
-
-
Save andyj/1221179 to your computer and use it in GitHub Desktop.
Paste Excel in to HTML to create at <table>
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
<html> | |
<head> | |
<style> | |
*{ | |
font-family: arial; | |
font-size: 11px; | |
} | |
table{ | |
border-collapse: collapse; | |
border: 1px solid silver; | |
} | |
tr{ | |
border-bottom: 1px solid silver; | |
} | |
/*This will style the header row!*/ | |
tr:first-child td { | |
background-color: #EEE; | |
border: 1px solid silver; | |
font-weight: bold; | |
padding: 2px; | |
text-align: center; | |
} | |
</style> | |
<script language="javascript"> | |
function createTable() { | |
// Get the data | |
var excelData = document.getElementById('csv').value; | |
// split into rows | |
excelRow = excelData.split(String.fromCharCode(10)); | |
// split rows into columns | |
for (i=0; i<excelRow.length; i++) { | |
excelRow[i] = excelRow[i].split(String.fromCharCode(9)); | |
} | |
// start to create the HTML table | |
var myTable = document.createElement("table"); | |
var myTbody = document.createElement("tbody"); | |
// Loop over the rows | |
for (i=0; i<excelRow.length - 1; i++) { | |
// create a row in the HTML table | |
var myRow = document.createElement("tr"); | |
// Loop over the columns and add TD to the TR | |
for (j=0; j<excelRow[i].length; j++) { | |
// Loop over the row columns | |
if (excelRow[i][j].length != 0) { | |
var myCell = document.createElement("td"); | |
myCell.innerHTML = excelRow[i][j]; | |
} | |
myRow.appendChild(myCell); | |
} | |
myTbody.appendChild(myRow); | |
} | |
myTable.appendChild(myTbody); | |
document.body.appendChild(myTable); | |
// console.log(myTable) | |
} | |
</script> | |
</head> | |
<body> | |
<p> | |
On your XLSX document "Select All" then "copy" the data, come to this page, put focus on the <textarea> box and "paste" the text in. In some instance (large data sets) this might take a couple of seconds. | |
Once there simply click the button to product the table. | |
</p> | |
<textarea id="csv" placeholder="Paste XLSX content here" style="width: 300px; height: 100px;"></textarea><br/> | |
<input type="button" value="Create HTML Table from XLSX content" onclick="createTable()" > | |
</body> | |
</html> | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment