JezK
Edit File: export_materialTransaction.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="MATERIAL_TRANSACTION_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); } // print_r($_GET); if(isset($_GET['wid']) && $_GET['wid']!=''){ $quoteCondition = "umt.warehouse_id=".$_GET['wid']; } // else if(isset($_SESSION['user_id']) && isset($_SESSION['user_id'])!=''){ // $quoteCondition = "umw.company_id=".(int)$_SESSION['company_id']; // } //~ if(isset($_SESSION) && $_SESSION['user_id']!=''){ //~ $condition="user_id=".$_SESSION['user_id']; //~ } //~ // $rows = $adminObj->db->get_results($sql); $sql= "select umt.quotation_id,umt.warehouse_id,umt.type,umt.randval,umt.itemcode,umt.qty,umt.item_desc,umw.warehouse_name from uflexit_material_transactions as umt JOIN uflexit_master_warehouse as umw ON umw.warehouse_id=umt.warehouse_id WHERE $quoteCondition "; $details = $wareHouseAdminObj->db->get_results($sql); $col = 'A'; $heading_array=array('S.No','Quotation ID','Warehouse Id','Warehouse Name','Item No','Item Description','Quantity','Transaction Type'); // 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++; // $row['customer_name']=$row['first_name'].' '. $row['last_name']; // $row['customer_type']=$row['role_id']==3?'Individual':'Business'; if($row['type']==1){ $row['status']="Issued"; }else if($row['type']==2){ $row['status']="Received"; } $spreadsheet->getActiveSheet(0)->setCellValue($col++.$i ,$j++); $spreadsheet->getActiveSheet(0)->setCellValue($col++.$i,$row['quotation_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, $row['itemcode']); $spreadsheet->getActiveSheet(0)->setCellValue($col++.$i, $row['item_desc']); $spreadsheet->getActiveSheet(0)->setCellValue($col++.$i, $row['qty']); $spreadsheet->getActiveSheet(0)->setCellValue($col++.$i,$row['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'); ?>