JezK
Edit File: export_rating.php
<?php include_once("./app/adminObj.php"); include_once("./app/checkSession.php"); require_once("./vendor/autoload.php"); use PhpOffice\PhpSpreadsheet\Spreadsheet; use PhpOffice\PhpSpreadsheet\IOFactory; header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'); header('Content-Disposition: attachment;filename="RATING_LIST.xlsx"'); header('Cache-Control: max-age=0'); header('Cache-Control: max-age=1'); header('Cache-Control: cache, must-revalidate'); header('Pragma: public'); $spreadsheet = new Spreadsheet(); //Specify the properties for this document //To apply auto size to all fields from B to Z foreach(range('B','K') as $columnID) { $spreadsheet->getActiveSheet()->getColumnDimension($columnID) ->setAutoSize(true); } $condition=''; if(isset($_SESSION) && $_SESSION['customer_user_id']!=''){ $condition="user_id=".$_SESSION['customer_user_id']; } //~ // $rows = $adminObj->db->get_results($sql); $sql= "select urq.warehouse_request_type,urq.quotation_id,umw.warehouse_name,urq.warehouse_rating from uflexit_request_quote as urq join uflexit_master_warehouse as umw on umw.warehouse_id=urq.warehouse_id where ".$condition."and urq.quotation_status=3"; $details = $customerObj->db->get_results($sql); $col = 'A'; $heading_array=array('S.No', 'Warehouse Name','Quotation ID','Request Type','Ratings'); // setting the heading $i =1; foreach($heading_array as $heading) { $spreadsheet->getActiveSheet(0)->setCellValue($col++.$i,$heading); } $j=1; //~ $details = array(); foreach($details as $row) { $col = 'A'; $i++; if($row['warehouse_request_type']==1){ $request_type="Online"; }else if($row['warehouse_request_type']==0){ $request_type="Request Quote"; } if($row['warehouse_rating']==null){ $rating=0; }else{ $rating=$row['warehouse_rating']; } $spreadsheet->getActiveSheet(0)->setCellValue($col++.$i ,$j++); // $spreadsheet->getActiveSheet(0)->setCellValue($col++.$i ,$row['warehouse_number']); $spreadsheet->getActiveSheet(0)->setCellValue($col++.$i,$row['warehouse_name']); $spreadsheet->getActiveSheet(0)->setCellValue($col++.$i,$row['quotation_id']); $spreadsheet->getActiveSheet(0)->setCellValue($col++.$i,$request_type); $spreadsheet->getActiveSheet(0)->setCellValue($col++.$i,$rating); } // $spreadsheet->getActiveSheet() // ->setCellValue('C6', '=SUM(C1:C5)'); // $spreadsheet->getActiveSheet() // ->getStyle("C6")->getFont() // ->setBold(true); $writer = IOFactory::createWriter($spreadsheet, "Xlsx"); //Xls is also possible // $writer->save("my_excel_file.xlsx"); $writer->save('php://output'); ?>