Quantcast
Channel: console – CHUVASH.eu
Viewing all articles
Browse latest Browse all 7

Save an excel sheet as a clean table

$
0
0

To save an excel sheet as a html table is very easy. Just select the needed area, then go to Save as and check the selection and choose html as output format.

It works fine. It even looks like it did in Excel. But what if you don’t want all this junk, you want only the plain html table (e.g. for pasting into WP). When I saved my permission levels to html, I used this javascript code. First open the html page which Excel has created in Chrome, open the Dev Tools console, load the latest jQuery into the page, and remove all unnecessary attributes and styling, remove the comments, after that you can just copy the outerHTML of the table and paste into a text editor:

var script = document.createElement("script");
script.setAttribute("type","text/javascript");
script.setAttribute("src","http://code.jquery.com/jquery-latest.min.js")
document.body.appendChild(script);

//wait a second, then run the remainder

var $table = $("table");
var table = $table.get(0);
for (var i = table.attributes.length-1; i >= 0; i--) {
  $table.removeAttr(table.attributes[i].nodeName);
}
$("colgroup").remove();
$("tr, td").removeAttr("class").removeAttr("height").removeAttr("height").removeAttr("style");
$table.contents().each(function() {
	if(this.nodeType == 8) {
		$(this).remove();
	}
});
//dev tools command:copy
copy(table.outerHTML);


Viewing all articles
Browse latest Browse all 7

Trending Articles