Silahkan Melihat Tutorial di website kami dengan nyaman ENJOY YOUR LIFE ☕

PHP :: Export HTML Table Data to Excel, CSV, PNG and PDF using jQuery Plugin



Exporting data in to a format is a very common features in website.There is a lot of plugin which is used to export table data into xml,csv and png format but that will use for separate jquery file for each exporting format.
The tableExport is a wonderful jquery plugin which extracting table data into all formats like JSON , XML, PNG, CSV, TXT, SQL, MS-Word, Ms-Excel, Ms-Powerpoint and PDF, so with help of this jquery plugin you not need any other jquery plugin to extract data from tables.You can integrate tableExportplugin very easily with your project.
Here i will let you know basic use of tableExport jquery plugin with HTML table and with dynamic data using php and mysql.
Simple Example to extract table data into JSON XML,PNG,CSV,TXT,SQL,MS-Word,Ms-Excel,Ms-Powerpoint and PDF format using jquery and php
Simple Example to extract table data into JSON XML,PNG,CSV,TXT,SQL,MS-Word,Ms-Excel,Ms-Powerpoint and PDF format using jquery and php

We Can export HTML tables to the following formats:

  1. JSON
  2. XML
  3. PNG
  4. CSV
  5. TXT
  6. SQL
  7. MS-Word
  8. Ms-Excel
  9. Ms-Powerpoint
  10. PDF

How To Use table Export JQuery plugin :

following are basic files which you need to include into your head section of index.html file or Project. jquery plugin is necessary to tableExport jquery plugin.
1
2
3
<script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script type="text/javascript" src="tableExport.js"></script>
<script type="text/javascript" src="jquery.base64.js"></script>

How To Import Table data into PNG format:

we need to include html2canvas.js file into your head section to export table data into PNG format.
1
<script type="text/javascript" src="html2canvas.js"></script>

How To Import Table data into PDF format:

we need to include below files into your head section to export table data into PDF format.
1
2
3
<script type="text/javascript" src="jspdf/libs/sprintf.js"></script>
<script type="text/javascript" src="jspdf/jspdf.js"></script>
<script type="text/javascript" src="jspdf/libs/base64.js"></script>

Other option are:

separator: ‘,’
ignoreColumn: [2,3],
tableName:’yourTableName’
type:’csv’
pdfFontSize:14
pdfLeftMargin:20
escape:’true’
htmlContent:’false’
consoleLog:’false’

Other Type are:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
{type:'json',escape:'false'}
{type:'json',escape:'false',ignoreColumn:'[2,3]'}
{type:'json',escape:'true'}

{type:'xml',escape:'false'}
{type:'sql'}

{type:'csv',escape:'false'}
{type:'txt',escape:'false'}

{type:'excel',escape:'false'}
{type:'doc',escape:'false'}
{type:'powerpoint',escape:'false'}

{type:'png',escape:'false'}
{type:'pdf',pdfFontSize:'7',escape:'false'}
You can also check other tutorial of Export Data with PHP,

How to use export table with php and mysql.

Here i will demonstrate integration of exportTable with php and mysql,its very easy and simple.We need to following below points to export html table data into Excel, CSV, JSON, PDF, PNG using jQuery,php and mysql.
Step 1: Include all necessary files of exportTable jquery plugin.
1
2
3
4
5
6
7
8
9
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css"/>
<script type="text/javascript" src="tableExport.js"></script>
<script type="text/javascript" src="jquery.base64.js"></script>
<script type="text/javascript" src="html2canvas.js"></script>
<script type="text/javascript" src="jspdf/libs/sprintf.js"></script>
<script type="text/javascript" src="jspdf/jspdf.js"></script>
<script type="text/javascript" src="jspdf/libs/base64.js"></script>
<script type="text/javascript" src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
Step 2: Create PHP Connection with MYSQL database to get all records from database.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
<?php
mysql_connect('localhost', 'root');
mysql_select_db('test');


$qry="SELECT * FROM employee";
$result=mysql_query($qry);


$records = array();

while($row = mysql_fetch_assoc($result)){
$records[] = $row;
}

?>
Step 3: Create UI of table grid and bind MYSQL records with HTML table.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
<div class="row" style="height:300px;overflow:scroll;">
<table id="employees" class="table table-striped">
<thead>
<tr class="warning">
<th>Id</th>
<th>Name</th>
<th>Salary</th>
<th>age</th>
</tr>
</thead>
<tbody>
<?php foreach($records as $rec):?>
<tr>
<td>
<?php
echo $rec['id']?></td>
<td>
<?php
echo $rec['employee_name']?></td>
<td>
<?php
echo $rec['employee_salary']?></td>
<td>
<?php
echo $rec['employee_age']?></td>
</tr>
<?php
endforeach; ?>
</tbody>
</table>
</div>
Step 4: Call exportTable function to export data on click of format icon.
1
2
<li><a href="#" onclick="$('#employees').tableExport({type:'json',escape:'false'});"> <img src="images/json.jpg" width="24px"> JSON</a></li>
<li><a href="#" onclick="$('#employees').tableExport({type:'json',escape:'false'});"><img src="images/json.jpg" width="24px">JSON (ignoreColumn)</a></li>
You can get more details from Official Website

You can download source code and Demo from below link





0 komentar:

Post a Comment

PHP :: Export HTML Table Data to Excel, CSV, PNG and PDF using jQuery Plugin