Skip to content

Instantly share code, notes, and snippets.

@fitnr
Created January 30, 2015 17:47
Show Gist options
  • Save fitnr/00c515a5104f74de37d4 to your computer and use it in GitHub Desktop.
Save fitnr/00c515a5104f74de37d4 to your computer and use it in GitHub Desktop.
convert table to csv (uses JQuery)
// encoded:
// javascript:(function()%7B$('table').each(function()%7Bvar%20$table=$(this);$('%3Ctextarea%3E').css('width',$table.width()).css('height','400px').html($.map($table.find('tr'),function(tr)%7Breturn%20$.map($(tr).find('th,%20td'),function(e)%7Breturn'%22'+$(e).text().replace('%22','%22%22').replace('%5Cn','%20')+'%22'%7D).join(',')%7D).join('&%2313;&%2310;')).insertAfter($table);%7D)%7D)()
javascript:(function() {
$('table').each(function() {
var $table = $(this);
$('<textarea>').css('width', $table.width())
.css('height', '400px')
.html(
$.map(
$table.find('tr'), function(tr) {
return $.map($(tr).find('th, td'), function(e) {
return '"' + $(e).text().replace('"', '""').replace('\n', ' ') + '"'
}).join(',')
}).join('&#13;&#10;'))
.insertAfter($table);
})
})()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment