<?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 mobilesuppliers ORDER BY spid");
while($resalt=mysqli_fetch_array($qury)){

$excel->setActiveSheetIndex()
->setCellValue("A".$row_count,$resalt['spname'])
->setCellValue("B".$row_count,$resalt['spemail'])
->setCellValue("C".$row_count,$resalt['spphone'])
->setCellValue("D".$row_count,$resalt['spaddress'])
->setCellValue("E".$row_count,$resalt['credit'])
->setCellValue("F".$row_count,$resalt['add_date']);
$row_count++;

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

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

?>