Jump to content

User talk:Anichandran.a

Page contents not supported in other languages.
From Wikipedia, the free encyclopedia

how to generate excel report with php and mysql :

Hi Friends, Recently for one of my project work, I need to generate excel report for customer data using php and mysql. Here I am posting tutorial of generate excel report in easy steps.

Generate-excel-report-with-php-and-mysql Step 1. Include phpexcel class file along with your config file and make its object with excel file name passed parameter in constructor. Its will display if any error found in next echo statement.

require_once("excelwriter.class.php");


$excel=new ExcelWriter("report.xls");


if($excel==false)

echo $excel->error; Step 2. Now time to fetch data from mysql database. Before fetch data, call excel header having columns as values of array.

// this will create heading of each column in excel file

$myArr=array("S.No.","Company Name","Email","City","Username","Reg. Date");

$excel->writeLine($myArr);


// now fetch data from database table, there is a new line create each time loop runs


$qry=mysql_query("select * from customer");

if($qry!=false)

{

$i=1;
while($res=mysql_fetch_array($qry))
{
$myArr=array($i,$res['company_name'],$res['email'],...);
$excel->writeLine($myArr);
$i++;
}

} Step 3. Create link to generate excel file.

<a href="javascript:void(0);" onClick="download();">Download Excel Report</a> and here download function pointing to excel file

<script language="javascript">

function download()

{

window.location='report.xls';

}

</script>