0

I would like to export the content of a html table with javascript.

First I would walk through all TD-elements and collect the data to send it in one big POST-query to another PHP-Page, that generates CSV-Excel from it.

Or could I use another framework, that already includes this functionality?

1

3 Answers 3

1

Here is a useful plugin that converts a table to CSV string.

Sign up to request clarification or add additional context in comments.

1 Comment

That page seems not be obtained anymore, I copied the source to github: github.com/rubo77/table2CSV
1

window.open(MIMEtype, dataContainerItem) can be used to export the html table data directly from browser without making a server trip. But as per web standards it has some limitations and also we can't handle the output file name. Simple steps to do so are -

  1. wrap your html table into a container (DIV).
  2. pass the html content of this container(DIV) html to window.open along with MIME type.

ex.

window.open('data:application/vnd.ms-excel,' + encodeURIComponent( $('div[id$=divTableDataHolder]').html()));

You may refer- http://codepattern.net/Blog/post/jQuery-export-table-data-into-MS-Excel

and awesome details on its limitations at - Export to CSV using jQuery and html

Comments

0

Use Data URIs and table2CSV:

var data = $table.table2CSV({delivery:'value'});

$('<a></a>')
    .attr('id','downloadFile')
    .attr('href','data:text/csv;charset=utf8,' + encodeURIComponent(data))
    .attr('download','filename.csv')
    .appendTo('body');

$('#downloadFile').ready(function() {
    $('#downloadFile').get(0).click();
});

1 Comment

TableCSV has some bugs and is not developed any more, but there is another fork: github.com/ZachWick/TableCSVExport that already implemented some more new features (emptyValue, showHiddenRows, rowFilter)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.