<?php

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

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

$excel->setActiveSheetIndex()
->setCellValue("A1","Quotation No")
->setCellValue("B1","Customer")
->setCellValue("C1","Address")
->setCellValue("D1","Contact")
->setCellValue("E1","Value")
->setCellValue("F1","Date");

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

$row_count=2;

$qury=mysqli_query($conn,"SELECT *  FROM quotations ORDER BY q_id  DESC");
while($resalt=mysqli_fetch_array($qury)){

$excel->setActiveSheetIndex()
->setCellValue("A".$row_count,$resalt['q_id'])
->setCellValue("B".$row_count,$resalt['q_customer'])
->setCellValue("C".$row_count,$resalt['q_address'])
->setCellValue("D".$row_count,$resalt['q_contact'])
->setCellValue("E".$row_count,$resalt['q_amount'])
->setCellValue("F".$row_count,$resalt['q_date']);
$row_count++;

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

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

?>