Linux ip-172-26-7-228 5.4.0-1103-aws #111~18.04.1-Ubuntu SMP Tue May 23 20:04:10 UTC 2023 x86_64
Your IP : 3.139.72.210
Current Path : /var/www/html/oums/src/ |
| Current File : /var/www/html/oums/src/employees_report_excel.php |
<?php
/** Error reporting */
error_reporting(E_ALL);
ini_set('display_errors', TRUE);
ini_set('display_startup_errors', TRUE);
define('EOL', (PHP_SAPI == 'cli') ? PHP_EOL : '<br />');
include("sys_session.php");
include("sys_connect.php");
include("sys_mainphp.php");
/** Include PHPExcel */
require_once("phpexcel/Classes/PHPExcel.php");
// Create new PHPExcel object
$objPHPExcel = new PHPExcel();
// Set document properties
$objPHPExcel->getProperties()->setCreator("Logisys")
->setLastModifiedBy("Logisys")
->setTitle("Office 2007 XLSX Test Document")
->setSubject("Office 2007 XLSX Test Document")
->setDescription("Test document for Office 2007 XLSX, generated using PHP classes.")
->setKeywords("office 2007 openxml php")
->setCategory("Report File");
$mysql = "select dp.fdeptcode,dp.fdeptname,em.femplcode,em.femplname,dn.fempldesn,em.femplmobl from masempl em
inner join masdept dp on em.fdeptcode = dp.fdeptcode
inner join masdesn dn on em.fempldesn = dn.fempldesn
where em.femplstat='T' and ifnull(em.fdeleted,'F')<>'T'
order by em.fdeptcode,dn.fdesnordr,dn.fempldesn,em.fempltype,em.femplname";
$myres = mysqli_query($mycon, $mysql);
$objPHPExcel->setActiveSheetIndex(0)
->setCellValue('A1', 'Sl. No.')
->setCellValue('B1', 'Client Code')
->setCellValue('C1', 'Client Name')
->setCellValue('D1', 'Empl ID')
->setCellValue('E1', 'Employee Name')
->setCellValue('F1', 'Designation')
->setCellValue('G1', 'Mobile No.');
$i = 2;
while ($myrow = mysqli_fetch_object($myres)) {
$objPHPExcel->setActiveSheetIndex(0)
->setCellValue('A' . $i, $i - 1)
->setCellValue('B' . $i, $myrow->fdeptcode)
->setCellValue('C' . $i, $myrow->fdeptname)
->setCellValue('D' . $i, $myrow->femplcode)
->setCellValue('E' . $i, $myrow->femplname)
->setCellValue('F' . $i, $myrow->fempldesn)
->setCellValue('G' . $i, $myrow->femplmobl);
$i++;
}
$lastrow = $objPHPExcel->getActiveSheet()->getHighestRow();
$objPHPExcel->getActiveSheet()->getStyle('A1:A' . $lastrow)->getAlignment()->setHorizontal('center');
$objPHPExcel->getActiveSheet()->getStyle('B1:B' . $lastrow)->getAlignment()->setHorizontal('center');
$objPHPExcel->getActiveSheet()->getStyle('C1:C' . $lastrow)->getAlignment()->setHorizontal('left');
$objPHPExcel->getActiveSheet()->getStyle('D1:D' . $lastrow)->getAlignment()->setHorizontal('center');
$objPHPExcel->getActiveSheet()->getStyle('E1:E' . $lastrow)->getAlignment()->setHorizontal('center');
$objPHPExcel->getActiveSheet()->getStyle('F1:F' . $lastrow)->getAlignment()->setHorizontal('center');
$objPHPExcel->getActiveSheet()->getStyle('G1:G' . $lastrow)->getAlignment()->setHorizontal('center');
//freeze top row
$objPHPExcel->getActiveSheet()->freezePane('A2');
//set column width
$objPHPExcel->getActiveSheet()->getColumnDimension('A')->setWidth(10);
$objPHPExcel->getActiveSheet()->getColumnDimension('B')->setWidth(20);
$objPHPExcel->getActiveSheet()->getColumnDimension('C')->setWidth(30);
$objPHPExcel->getActiveSheet()->getColumnDimension('D')->setWidth(20);
$objPHPExcel->getActiveSheet()->getColumnDimension('E')->setWidth(20);
$objPHPExcel->getActiveSheet()->getColumnDimension('F')->setWidth(20);
$objPHPExcel->getActiveSheet()->getColumnDimension('G')->setWidth(20);
//merge cells
$objPHPExcel->getActiveSheet()->mergeCells('A1:A1');
//alignment
$objPHPExcel->getActiveSheet()->getStyle('A1:X1')->getAlignment()->setHorizontal('center');
//styling
$objPHPExcel->getActiveSheet()->getStyle('A1:X1')->getFont()->setSize(11);
$objPHPExcel->getActiveSheet()->getStyle('A1:X1')->getFont()->setBold(true);
// Set header and footer. When no different headers for odd/even are used, odd header is assumed.
$objPHPExcel->getActiveSheet()->getHeaderFooter()->setOddHeader('&L&G&C&HLogisys, Bangalore');
$objPHPExcel->getActiveSheet()->getHeaderFooter()->setOddFooter('&L&B' . '&CPage &P of &N');
// Set page orientation and size
$objPHPExcel->getActiveSheet()->getPageSetup()->setOrientation(PHPExcel_Worksheet_PageSetup::ORIENTATION_LANDSCAPE);
$objPHPExcel->getActiveSheet()->getPageSetup()->setPaperSize(PHPExcel_Worksheet_PageSetup::PAPERSIZE_A4);
// Rename worksheet
$objPHPExcel->getActiveSheet()->setTitle('employee_list');
// Set active sheet index to the first sheet, so Excel opens this as the first sheet
$objPHPExcel->setActiveSheetIndex(0);
// Redirect output to a client’s web browser (Excel2007)
header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
header('Content-Disposition: attachment;filename="oums_report.xlsx"');
header('Cache-Control: max-age=0');
// If you're serving to IE 9, then the following may be needed
header('Cache-Control: max-age=1');
// If you're serving to IE over SSL, then the following may be needed
header('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); // Date in the past
header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT'); // always modified
header('Cache-Control: cache, must-revalidate'); // HTTP/1.1
header('Pragma: public'); // HTTP/1.0
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
$objWriter->save('php://output');
exit;
|