HTML Table to CSV

This is small JQuery utility which allows you to export any HTML table as CSV file. Its very handy tool to use specially during development of reporting projects. It is also useful when you have some 3rd party JQuery table search plugin attached to your table.

Example

Title Name Phone
Mr. John 07868785831
Miss Linda 0141-2244-5566
Master Jack 0142-1212-1234
Mr. Bush 911-911-911

Option 1  Option 2  Option 3  Option 3.1  Option 4  Download   Comments About

<script type="text/javascript" src="http://jqueryjs.googlecode.com/files/jquery-1.3.1.min.js" > </script>
<script type="text/javascript" src="http://www.kunalbabre.com/projects/table2CSV.js" > </script>

Download Plugin    

Option 1

$('#example1').table2CSV();



Option 2

This can be used when you need custom header

$('#example1').table2CSV({

	header:['prefix','Employee Name','Contact']

});




Option 3

This can be used when you need to get output as string

alert(

$('#example1').table2CSV({

delivery:'value',

header:['prefix','Employee Name','Contact']

}));




Option 3.1 - Generate CSV File

This can be done by posting the csv value obtained above to PHP or any similar server side script.
Step 1: Html File
<form action="getCSV.php" method ="post" > 
<input type="hidden" name="csv_text" id="csv_text">
<input type="submit" value="Get CSV File" 
       onclick="getCSVData()"
</form>

<script>
function getCSVData(){
 var csv_value=$('#example1').table2CSV({delivery:'value'});
 $("#csv_text").val(csv_value);	
}
</script>

Step 2: PHP File ( getCSV.php )
<?php
header("Content-type: application/octet-stream");
header("Content-Disposition: attachment; filename=\"my-data.csv\"");
$data=stripcslashes($_REQUEST['csv_text']);
echo $data; 
?>


Option 4

This can be used when you need different separator

alert(

$('#example1').table2CSV({

separator : ';',

delivery:'value',

header:['prefix','Employee Name','Contact']

}));


Comments

Name:

Email:

Comments:

What is sum of 40 + 151:



Fatal error: Out of memory (allocated 61865984) (tried to allocate 188 bytes) in /homepages/30/d447419538/htdocs/wsb7162780401/projects/table2CSV.php on line 479