JezK
Edit File: myquotationExportcsv.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="QuotationList.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['user_id']!=''){ $condition="urq.user_id=".$_SESSION['user_id']; } //~ // $rows = $adminObj->db->get_results($sql); $sql= "select urq.quotation_id,umw.warehouse_name,us.first_name,us.last_name,us.role_id, urq.quotation_status,urq.closed_status from uflexit_request_quote as urq JOIN uflexit_master_warehouse as umw ON urq.warehouse_id=umw.warehouse_id JOIN uflexit_users as us ON us.user_id=urq.user_id where $condition"; $details = $customerObj->db->get_results($sql); $col = 'A'; $heading_array=array('S.No', 'Warehouse Name','Quotation Number','Customer Name','Customer Type','Status'); // 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++; $customer_name = $row['first_name'].$row['last_name']; $type=""; if ($row['role_id'] == 1){ $type = "Owner"; }else if($row['role_id'] == 2){ $type = "Sub Admin"; }else if($row['role_id'] == 3){ $type = "Individual Customer"; }else if($row['role_id'] == 4){ $type = "Business Customer"; } switch ($row['quotation_status']) { case "0": $quotationStatus = "Open"; break; case "1": $quotationStatus = "Pending"; break; case "3": $quotationStatus = "Accepted"; break; case "2": $quotationStatus = "Rejected"; break; case "4": $quotationStatus = "Finally Closed"; break; default: $quotationStatus = "Open"; } $row['status']=$quotationStatus; // $richText = $wizard->toRichTextObject($row['warehouse_description']); // $reader = new \PhpOffice\PhpSpreadsheet\Reader\Html(); // $richText = $reader->loadFromString($row['warehouse_description']); // $richText = htmlspecialchars($row['warehouse_description']); // $richText = html_entity_encode($row['warehouse_description'],ENT_QUOTES,'UTF-8'); // $reader = new Html(); // $reader = new \PhpOffice\PhpSpreadsheet\Reader\Html(); // $richText = $reader->loadFromString($row['warehouse_description']); // $richText = $reader->load($row['warehouse_description']); $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,$customer_name); $spreadsheet->getActiveSheet(0)->setCellValue($col++.$i,$type); $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'); ?>