JezK
Edit File: export-shipmentStatus.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['wid']) && $_GET['wid']!='') // { // $wid=$_GET['wid']; // $condition = "(umt.warehouse_id=$wid)"; // } // $rows = $adminObj->db->get_results($sql); $sql= "select distinct umw.* from uflexit_master_warehouse as umw join uflexit_asn_request as uar on uar.warehouse_id=umw.warehouse_id where (umw.warehouse_status=1 or umw.warehouse_status=3) Order by warehouse_id desc "; $details = $adminObj->db->get_results($sql); $col = 'A'; $heading_array=array('S.No','Warehouse ID','Warehouse Name'); // 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']; // $dateTimestamp1 = strtotime($row['created_date']); // $dateTimestamp2 = strtotime($row['date']); // if($dateTimestamp1>$dateTimestamp2){ // $status1="Late"; // } else if( $dateTimestamp1<$dateTimestamp2){ // $status1="Early"; // } // else if($dateTimestamp1==$dateTimestamp2){ // $status1="OnTime"; // } // $row['status']=$status1; // if($row['type']==1){ // $status="Issued"; // } // else{ // $status="Recieved"; // } // $row['type']=$status; $spreadsheet->getActiveSheet(0)->setCellValue($col++.$i ,$j++); $spreadsheet->getActiveSheet(0)->setCellValue($col++.$i,$row['warehouse_id']); $spreadsheet->getActiveSheet(0)->setCellValue($col++.$i,$row['warehouse_name']); // $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'); ?>