JezK
Edit File: export-quotationList.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="ShipmentStatus.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); } if(isset($_GET['type']) && $_GET['type']!='') { $type=$_GET['type']; if($type==5){ $condition = "(1=1)"; } else{ $condition = "(urq.closed_status=$type)"; } } $startdate=''; $enddate=''; if(isset($_GET['startDate']) && $_GET['startDate']!='' && isset($_GET['endDate']) && $_GET['endDate']!='' ){ $startdate=$_GET['startDate']; $enddate=$_GET['endDate']; } $sql= "select urq.quotation_id,urq.warehouse_request_type,ur.role_name, umw.warehouse_name,uu.first_name,uu.last_name,urq.closed_status from uflexit_request_quote as urq JOIN uflexit_master_warehouse as umw ON umw.warehouse_id=urq.warehouse_id join uflexit_users as uu on uu.user_id=urq.user_id join uflexit_roles as ur on ur.role_id=uu.role_id where urq.modify_dt between '".$startdate."' and '".$enddate."' and $condition "; $details = $adminObj->db->get_results($sql); $col = 'A'; $heading_array=array('S.No','Quatation ID','Warehouse Name','Customer Name','Customer Type', 'Request Type','Status'); // setting the heading $i =1; foreach($heading_array as $heading) { $spreadsheet->getActiveSheet(0)->setCellValue($col++.$i,$heading); } $j=1; if($details){ foreach($details as $row) { $col = 'A'; $i++; $row['customer_name']=$row['first_name']." ".$row['last_name']; if($row['warehouse_request_type']==1){ $request_type="Online"; }else if($row['warehouse_request_type']==0){ $request_type="Request Quote"; } // $fetch['type']=$status; switch ($row['closed_status']) { case "0": $closedStatus = "Pending"; break; case "1": $closedStatus = "Waiting acceptance"; break; case "2": $closedStatus = "Lost"; break; case "3": $closedStatus = "Won"; break; case "4": $closedStatus = "Finally Closed"; break; default: $closedStatus = "Pending"; } $row['closed_status'] = $closedStatus ; $spreadsheet->getActiveSheet(0)->setCellValue($col++.$i ,$j++); $spreadsheet->getActiveSheet(0)->setCellValue($col++.$i,$row['quotation_id']); $spreadsheet->getActiveSheet(0)->setCellValue($col++.$i,$row['warehouse_name']); $spreadsheet->getActiveSheet(0)->setCellValue($col++.$i,$row['customer_name']); $spreadsheet->getActiveSheet(0)->setCellValue($col++.$i, $row['role_name']); $spreadsheet->getActiveSheet(0)->setCellValue($col++.$i,$request_type); $spreadsheet->getActiveSheet(0)->setCellValue($col++.$i,$row['closed_status']); // $spreadsheet->getActiveSheet(0)->setCellValue($col++.$i,$row['cost']); } } $writer = IOFactory::createWriter($spreadsheet, "Xlsx"); //Xls is also possible // $writer->save("my_excel_file.xlsx"); $writer->save('php://output'); ?>