JezK
Edit File: export_shipment.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="TOTAL_SHIPMENT_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="uar.user_id=".$_SESSION['customer_user_id']; } //~ // $rows = $adminObj->db->get_results($sql); $sql="select urq.currency_type,uc.currency,uar.asn_status,umw.warehouse_name,uu.first_name,uu.last_name,uar.date, uar.warehouse_id,uar.price, urq.warehouse_request_type,urq.from_date ,uar.quotation_id ,uws.request_status from uflexit_asn_request as uar join uflexit_request_quote as urq on uar.quotation_id=urq.quotation_id join uflexit_master_warehouse as umw on umw.warehouse_id=uar.warehouse_id join uflexit_users as uu on uu.user_id=uar.user_id join uflexit_warehouse_status as uws on urq.warehouse_request_type=uws.status_type join uflexit_countries as uc on uc.country_id=urq.currency_type where $condition"; $details = $customerObj->db->get_results($sql); $count=$details? count($details):0; $col = 'A'; $heading_array=array('S.No','Warehouse Id', 'Warehouse Name','Request Type','Customer Name','Value','ASN Date','Status'); // setting the heading $i =1; foreach($heading_array as $heading) { $spreadsheet->getActiveSheet(0)->setCellValue($col++.$i,$heading); } $j=1; //~ $details = array(); if($count>0){ 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"; } $date=date_create($row['date']); $row['date']=date_format($date,"d-m-Y"); $name=$row['first_name']." ".$row['last_name']; $value=$row['price']." ".$row['currency']; $spreadsheet->getActiveSheet(0)->setCellValue($col++.$i ,$j++); $spreadsheet->getActiveSheet(0)->setCellValue($col++.$i ,$row['warehouse_id']); // $spreadsheet->getActiveSheet(0)->setCellValue($col++.$i,$row['warehouse_id']); $spreadsheet->getActiveSheet(0)->setCellValue($col++.$i,$row['warehouse_name']); $spreadsheet->getActiveSheet(0)->setCellValue($col++.$i,$request_type); $spreadsheet->getActiveSheet(0)->setCellValue($col++.$i,$name); $spreadsheet->getActiveSheet(0)->setCellValue($col++.$i,$value); $spreadsheet->getActiveSheet(0)->setCellValue($col++.$i,$row['date']); $spreadsheet->getActiveSheet(0)->setCellValue($col++.$i,$row['asn_status']); } } // $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'); ?>