<?php

include 'dbconfig.php';
require_once("conn.php");
require_once 'db_connection.php'; 

require("PHPExcel/PHPExcel.php");
$excel= new PHPExcel();

$excel->setActiveSheetIndex()
->setCellValue("A1","Name")
->setCellValue("B1","Email")
->setCellValue("C1","Phone")
->setCellValue("D1","Address")
->setCellValue("E1","Credit")
->setCellValue("F1","Date");

$excel->getActiveSheet()->getStyle("A1:F1")->getFont()->setBold( true );

$row_count=2;

$qury=mysqli_query($conn,"SELECT * FROM mobilecustomers ORDER BY coid");
while($resalt=mysqli_fetch_array($qury)){

$excel->setActiveSheetIndex()
->setCellValue("A".$row_count,$resalt['cname'])
->setCellValue("B".$row_count,$resalt['cemail'])
->setCellValue("C".$row_count,$resalt['cphone'])
->setCellValue("D".$row_count,$resalt['caddress'])
->setCellValue("E".$row_count,$resalt['ccredit'])
->setCellValue("F".$row_count,$resalt['add_date']);
$row_count++;

}
	
header('content-Type:Application.openxmlformats-officedocument.spreadsheetml.sheet');
header('content-Disposition:attachment; filename="all_customer_report.xlsx"');
header('cache-Control: max-age=0');

$file=PHPExcel_IOFactory::CreateWriter($excel,'Excel2007');
$file->save('php://output');

?>