0xV3NOMx
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 : 18.224.38.165


Current Path : /var/www/html/univadmin/Reports/
Upload File :
Current File : /var/www/html/univadmin/Reports/studwiseCollListExl.php

<?php

$main_src = substr($_SERVER['SCRIPT_FILENAME'], 0, strlen($_SERVER['SCRIPT_FILENAME']) - 7);
error_reporting(E_ALL);
ini_set('display_errors', TRUE);
ini_set('display_startup_errors', TRUE);
date_default_timezone_set('GMT+5:30');
// PHPExcel_Shared_Font::setAutoSizeMethod(PHPExcel_Shared_Font::AUTOSIZE_METHOD_EXACT);
if (PHP_SAPI == 'cli')
    die('This example should only be run from a Web Browser');

/** Include PHPExcel */
$pdf_writer_class = $main_src . '/PHPExcel/Classes/PHPExcel.php';
require_once($pdf_writer_class);

function getheaders($objPHPExcel, $fileName)
{
    //To Fit To Page while printing
    $objPHPExcel->getActiveSheet()->getPageSetup()->setRowsToRepeatAtTopByStartAndEnd(1);
    $objPHPExcel->getActiveSheet()->getPageSetup()->setFitToWidth(1);
    $objPHPExcel->getActiveSheet()->getPageSetup()->setFitToHeight(0);
    $objPHPExcel->getActiveSheet()->getPageSetup()->setHorizontalCentered(true);
    $objPHPExcel->getActiveSheet()->getPageSetup()->setVerticalCentered(false);

    // Redirect output to a client’s web browser (Excel5)
    header('Content-Type: application/vnd.ms-excel');
    header('Content-Disposition: attachment;filename="' . $fileName . '.xls"');
    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
    ob_clean();
    $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
    $objWriter->save('php://output');
}


function studentwiseCollListExl($aobj_context)
{
    $objPHPExcel = new PHPExcel();
    $fileName = 'CollegewiseStudentList';
    $objPHPExcel->getProperties()->setCreator("Uniclare")
    ->setLastModifiedBy("Me")->setTitle("My Excel Sheet")
    ->setSubject("My Excel Sheet")->setDescription("Excel Sheet")
    ->setKeywords("Excel Sheet")->setCategory("Me");

    // Set active sheet index to the first sheet, so Excel opens this as the first sheet
    $objPHPExcel->setActiveSheetIndex(0);
    
    // Add column headers and make them bold
    $styleArray = array(
        'borders' => array(
            'allborders' => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN,
                'color' => array('argb' => '000000'),
            ),
        ),
    );

    $univcode = $aobj_context->mobj_data["univcode"];  
    $fcollfrom = $aobj_context->mobj_data["fcollfrom"]; 
    $fcollto = $aobj_context->mobj_data["fcollto"];  
    $fdegfrom = $aobj_context->mobj_data["fdegfrom"];  
    $fdegto = $aobj_context->mobj_data["fdegto"];  
    $fdeggrpfrom = $aobj_context->mobj_data["fdeggrpfrom"];
    $fdeggrpto = $aobj_context->mobj_data["fdeggrpto"];  
    $count = "";

    $alpha = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 
    'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'AA', 'AB', 'AC',
    'AD', 'AF', 'AE', 'AF', 'AG', 'AH'
  ];

  $query = "select c.fcollcode,CONCAT(c.fcollname,',',c.ftown) AS fcollname,d.fdescpn, d.FEXAMNAME, s.FSLNO, 
  lcase(FNAME) as FNAME,if(s.fgender='M','Male','Female') as FGENDER,
  lcase(FFATNAME) as FFATNAME,lcase(FMOTNAME) as FMOTNAME,
  if(date_format(s.FDOB,'%d/%m/%Y')='00/00/00','',date_format(s.FDOB,'%d/%m/%Y')) as FDOB,
  ifnull(s.FSEX,'') as FSEX,	s.FCASTE,s.FDEGREE, cs.FEXAMNO,cs.FCOLLCODE, cs.FREGNO
  from student s inner join candsum cs on cs.FDEGREE = s.FDEGREE  and cs.FCOLLCODE=s.FCOLLCODE and cs.FREGNO=s.FREGNO 
  inner join degree d on cs.fdegree = d.fdegree and cs.fexamno = d.fexamno
  INNER JOIN college c ON c.fcollcode = cs.fcollcode
  WHERE cs.FCOLLCODE between '{$fcollfrom}' and '{$fcollto}'
  and d.fdegree between '{$fdegfrom}' and '{$fdegto}' 
  and d.fdeggrp IN ('{$fdeggrpfrom}','{$fdeggrpto}')
  GROUP BY cs.FDEGREE,cs.FEXAMNO, cs.FCOLLCODE,cs.FREGNO 
  ORDER BY cs.fcollcode, cs.FDEGREE, cs.FREGNO";

  $result1 = $aobj_context->pobj_db->GetAll($query);  

  $objPHPExcel->getActiveSheet()->getStyle('1:1')->getFont()->setBold(true);
  $objPHPExcel->getActiveSheet()->getStyle('1:1')->getFont()->setSize(12);
//   if($oldDeg!=$result1[0]["FDEGREE"])
//   {
    
//     $oldDeg = $result1[0]["FDEGREE"];  
//     $objPHPExcel->setActiveSheetIndex(0)->mergeCells('A2:H2');
//     $objPHPExcel->getActiveSheet()->setCellValue('A2',$result1[0]['FDEGREE'].'  '.$result1[0]['fdescpn']);

//   }
  
  $objPHPExcel->getActiveSheet()->freezePane('A2');
  $objPHPExcel->getActiveSheet()
    ->setCellValue('A1', 'Sl. No.')
    ->setCellValue('B1', 'College Code')
    ->setCellValue('C1', 'College Name')
    ->setCellValue('D1', 'Degree Code')
    ->setCellValue('E1', 'Description')
    ->setCellValue('F1', 'Reg. No.')
    ->setCellValue('G1', 'Student Name')
    ->setCellValue('H1', 'Gender')
    ->setCellValue('I1', 'DOB')
    ->setCellValue('J1', 'Category')
    ->setCellValue('K1', 'Father Name')
    ->setCellValue('L1', 'Mother Name')
  ;

  $objPHPExcel->getActiveSheet()->getStyle('A1:L1')->applyFromArray($styleArray);
  // // $objPHPExcel->getActiveSheet()->getColumnDimension('G1')->setAutoSize(true);
  $objPHPExcel->getActiveSheet()->getRowDimension('1')->setRowHeight(45);
  $objPHPExcel->getActiveSheet()->getStyle('A1:L1')->getAlignment()->setWrapText(true);
  $objPHPExcel->getActiveSheet()->getStyle('A1:L1')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  $objPHPExcel->getActiveSheet()->getStyle('A1:L1')->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER);
       

    foreach ($result1 as $key => $value) {
      $slNo = $key + 2;

      $objPHPExcel->getActiveSheet()->setCellValue('A' . $slNo, $slNo - 1)->getColumnDimension('A')->setwidth(5);
      $objPHPExcel->getActiveSheet()->setCellValue('B' . $slNo, $value['fcollcode'])->getColumnDimension('B')->setwidth(10);
      $objPHPExcel->getActiveSheet()->setCellValue('C' . $slNo, $value['fcollname'])->getColumnDimension('C')->setwidth(50);
      $objPHPExcel->getActiveSheet()->setCellValue('D' . $slNo, $value['FDEGREE'])->getColumnDimension('D')->setwidth(10);
      $objPHPExcel->getActiveSheet()->setCellValue('E' . $slNo, $value['fdescpn'])->getColumnDimension('E')->setwidth(40);
      $objPHPExcel->getActiveSheet()->setCellValue('F' . $slNo, $value['FREGNO'])->getColumnDimension('F')->setwidth(10);
      $objPHPExcel->getActiveSheet()->setCellValue('G' . $slNo, ucwords($value['FNAME']))->getColumnDimension('G')->setwidth(40);
      $objPHPExcel->getActiveSheet()->setCellValue('H' . $slNo, $value['FGENDER'])->getColumnDimension('H')->setwidth(8.43);
      $objPHPExcel->getActiveSheet()->setCellValue('I' . $slNo, $value['FDOB'])->getColumnDimension('I')->setwidth(13);
      $objPHPExcel->getActiveSheet()->setCellValue('J' . $slNo, $value['FCASTE'])->getColumnDimension('J')->setwidth(10);
      $objPHPExcel->getActiveSheet()->setCellValue('K' . $slNo, ucwords($value['FFATNAME']))->getColumnDimension('K')->setwidth(40);
      $objPHPExcel->getActiveSheet()->setCellValue('L' . $slNo, ucwords($value['FMOTNAME']))->getColumnDimension('L')->setwidth(40);


      // $objPHPExcel->getActiveSheet()->getColumnDimension('D')->setwidth(12);
      $objPHPExcel->getActiveSheet()->getStyle('A' . $slNo . ':L'. $slNo)->applyFromArray($styleArray);
      $objPHPExcel->getActiveSheet()->getRowDimension($slNo)->setRowHeight(19);      

      // $objPHPExcel->getActiveSheet()->getStyle('A' . $slNo . ':H'.$slNo)->getAlignment()->setWrapText(true);

      $objPHPExcel->getActiveSheet()->getStyle('A' . $slNo . ':C' . $slNo)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
      $objPHPExcel->getActiveSheet()->getStyle('A' . $slNo . ':C' . $slNo)->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER);
      
      $objPHPExcel->getActiveSheet()->getStyle('E' . $slNo)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_LEFT);
      $objPHPExcel->getActiveSheet()->getStyle('E' . $slNo)->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER);

      $objPHPExcel->getActiveSheet()->getStyle('D' . $slNo . ':D' . $slNo)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
      $objPHPExcel->getActiveSheet()->getStyle('D' . $slNo . ':D' . $slNo)->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER);

      $objPHPExcel->getActiveSheet()->getStyle('H' . $slNo . ':J' . $slNo)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
      $objPHPExcel->getActiveSheet()->getStyle('H' . $slNo . ':J' . $slNo)->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER);

    }

    $objPHPExcel->getActiveSheet()->setTitle($fileName);
    $objPHPExcel->getActiveSheet()->getPageSetup()
    ->setOrientation(PHPExcel_Worksheet_PageSetup::ORIENTATION_LANDSCAPE);
    
    $get_coll_name = "select FUNIVNAME as 'FUNIVNAME',FUNIVCODE,
    FUNIVADD1 as 'state', pdf_logo_path,
    ifnull(FEXAMAPPREQ,'F') as FEXAMAPPREQ From control";

    $lobj_get_coll_name = $aobj_context->pobj_db->GetRow($get_coll_name);

    $collQry ="select concat(FCOLLCODE,' ',FCOLLNAME,', ',FTOWN) as college_name
    from college where FCOLLCODE='{$fcollcode}'";
    $collRes = $aobj_context->pobj_db->GetRow($collQry);


    $aobj_context->FUNIVNAME = $lobj_get_coll_name['FUNIVNAME'];
    $aobj_context->s_state = $lobj_get_coll_name['state'];
    $aobj_context->pdf_logo_path = $lobj_get_coll_name['pdf_logo_path'];
    $aobj_context->FUNIVCODE = $lobj_get_coll_name['FUNIVCODE']; 
    $objPHPExcel->getActiveSheet()->getPageMargins()->setTop(1);  

    // $objPHPExcel->getActiveSheet()->getHeaderFooter()->addImage($aobj_context->main_src.'img/'.$aobj_context->FUNIVCODE.'_logo.jpg', PHPExcel_Worksheet_HeaderFooter::IMAGE_HEADER_LEFT);
    $objPHPExcel->getActiveSheet()->getHeaderFooter()->setOddHeader('&C&H&"-,Bold"&16' . $aobj_context->FUNIVNAME 
    . "\n" . '&12' . $fileName. "\n " .$collRes['college_name']."\n".'Degree Group - '.$fdeggrp);    

    $objPHPExcel->getActiveSheet()->getHeaderFooter()->setOddFooter('&RPage &P of &N');

    getheaders($objPHPExcel, $fileName);
}

?>