Export as .csv with jQuery

This is so simple and very useful for reporting purpose. You can easily export your html table to .csv format with this jquery scripts.

Step 1: Html File

<form action="getCSV.php" method="post">
<input id="csv_text" name="csv_text" type="hidden" />
<input onclick="getCSVData()" type="submit" value="Get CSV File" />
<script type="text/javascript"><!--mce:0--></script>

Step 2: PHP File ( getCSV.php )

header("Content-type: application/octet-stream");
header("Content-Disposition: attachment; filename=\"my-data.csv\"");
echo $data;

Thanks to the code writer
source: http://www.kunalbabre.com/projects/table2CSV.php

Leave a Reply

Your email address will not be published. Required fields are marked *