Shubham
Shubham

Reputation: 187

How to export html table to excel or pdf in a HTML page through jQuery/JavaScript?

I have a html page with a table which is populated dynamically. I need to put 2 buttons below it which enables exporting the table structure data to Excel and PDF.

What is the best/easiest approach to implement this?

I will prefer some Javascript/jQuery solution. I have seen DocRaptor, but I think its a paid service. I need something similar which works on IE8 browser. Please Help !

Upvotes: 2

Views: 15969

Answers (3)

FPDF is a PHP class which allows to generate PDF files

Upvotes: 0

user2587132
user2587132

Reputation:

 $("button").click(function () {
  var str="";
  $('tr').each(function() {

        $(this).find('td').each(function() {

         str=str+$(this).html()+"\t";
  });
      str=str+"\n";

  });

  alert(str);

        window.open('data:application/vnd.ms-excel,' + encodeURIComponent(str));
    });

http://jsfiddle.net/4Vr89/1/

Upvotes: 4

Zaheer Ahmed
Zaheer Ahmed

Reputation: 28548

TableTools is a plug-in for the DataTables HTML table enhancer, which adds a highly customisable button toolbar to a DataTable. Key features include:

  • Copy to clipboard
  • Save table data as CSV, XLS or PDF files
  • Print view for clean printing
  • Row selection options
  • Easy use predefined buttons
  • Simple customisation of buttons
  • Well defined API for advanced control

Upvotes: 4

Related Questions