<?php

require 'cn2.php';

$sql= "select * from mg_antenas";

$resultado = $mysqli->query($sql);
if($resultado -> num_rows > 0){
    date_default_timezone_set('America/Mexico_City');
    
   
    require_once 'Classes/PHPExcel.php';
    $objPHPExcel= new PHPExcel();
    $objPHPExcel->getProperties()->setCreator("Sistemas MG")->
    setLastModifiedBy("MG")->
    setTitle("ANTENAS WIFI")->
    setSubject("Reporte de Antenas WIFI")->
    setDescription("Reporte de Antenas WIFI MG")->
    setKeywords("Reporte de Antenas WIFI MG ")->
    setCategory("Reporte");

    $tituloreporte = "Antenas WIFI MG";
    $titulosColumnas = array('ID','SUCURSAL','RED','IP','USUARIO','PASSWORD','SSD','CLAVE');
    
    $objPHPExcel->setActiveSheetIndex(0)
    ->mergeCells('A1:H1');
    
    $objPHPExcel->setActiveSheetIndex(0)
    ->setCellValue('A1',  $tituloreporte)
    ->setCellValue('A2',  $titulosColumnas[0])  
    ->setCellValue('B2',  $titulosColumnas[1])
    ->setCellValue('C2',  $titulosColumnas[2])
    ->setCellValue('D2',  $titulosColumnas[3])
    ->setCellValue('E2',  $titulosColumnas[4])  
    ->setCellValue('F2',  $titulosColumnas[5])
    ->setCellValue('G2',  $titulosColumnas[6])
    ->setCellValue('H2',  $titulosColumnas[7]);
    
     $i=3;            
    while($fila= $resultado->fetch_array()) {
        $objPHPExcel->setActiveSheetIndex(0)
        ->setCellValue('A'.$i, $fila['id'])
        ->setCellValue('B'.$i, $fila['sucursal'])
        ->setCellValue('C'.$i, $fila['red'])
        ->setCellValue('D'.$i, $fila['ip'])
        ->setCellValue('E'.$i, $fila['usuario'])
        ->setCellValue('F'.$i, $fila['password'])
        ->setCellValue('G'.$i, $fila['ssd'])
        ->setCellValue('H'.$i, $fila['clavewifi']);
    $i++;
        
    }
    for($i = 'A'; $i <= 'H'; $i++){
    $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension($i)->setAutoSize(TRUE);
}
    $objPHPExcel->getActiveSheet()->setTitle('Equipos');
      
   
    $objPHPExcel->setActiveSheetIndex(0);
      
    // Inmovilizar paneles
    $objPHPExcel->getActiveSheet(0)->freezePaneByColumnAndRow(0,3);
    
       header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
    header('Content-Disposition: attachment;filename="ReporteAntenasMG.xlsx"');
    header('Cache-Control: max-age=0');
      
    $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
    $objWriter->save('php://output');
    exit;
    }
    else{
        print_r('No hay resultados para mostrar');
    }

?>