este es mi codigo
Código PHP:
Ver original
<?php $sql="select * from pvigente"; if ($registros >0){ require_once 'Classes/PHPExcel.php'; $objPHPExcel = new PHPExcel(); $i =3; $objPHPExcel->setActiveSheetIndex(0) ->setCellValue('A'.$i,$registro->id_empresa) ->setCellValue('B'.$i,$registro->nom_fantasia) ->setCellValue('c'.$i,$registro->codtra) ->setCellValue('d'.$i,$registro->cod_user_bbva) ->setCellValue('e'.$i,$registro->rut) ->setCellValue('f'.$i,$registro->nombre) ->setCellValue('g'.$i,$registro->id_cargo_funcional); $i++; } $objPHPExcel->getActiveSheet()->setCellValue('A1','PLANTILLA DE RR.HH'); $objPHPExcel->getActiveSheet()->setCellValue('A3','Id_Empresa'); $objPHPExcel->getActiveSheet()->setCellValue('B3','Nom_Fantasia (Empresa)'); $objPHPExcel->getActiveSheet()->setCellValue('C3','codtra'); $objPHPExcel->getActiveSheet()->setCellValue('D3','Cod_user_bbva(CodUsuario)'); $objPHPExcel->getActiveSheet()->setCellValue('e3','RUT'); $objPHPExcel->getActiveSheet()->setCellValue('f3','Nombre'); $objPHPExcel->getActiveSheet()->setCellValue('g3','Id_cargo_Funcional(Grupo RR.HH)'); 'bold' => true, 'rgb' => 'fffff' ) ), 'type' => PHPExcel_Style_Fill::FILL_SOLID, 'rgb' => '333399' ) ) ); $objPHPExcel->getActiveSheet()->getStyle("A1:g1")->applyFromArray($miestilo); $objPHPExcel->getActiveSheet()->getStyle("A3:g3")->applyFromArray($miestilo); $objPHPExcel->getActiveSheet()->getColumnDimension('g')->setAutoSize(true); $objPHPExcel->getActiveSheet()->getStyle('A1')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER); $objPHPExcel->getActiveSheet()->MergeCells('A1:G1'); $objPHPExcel->getActiveSheet()->getColumnDimension('b')->setWidth(28); $objPHPExcel->getActiveSheet()->getColumnDimension('c')->setWidth(7); $objPHPExcel->getActiveSheet()->getColumnDimension('d')->setWidth(26); $objPHPExcel->getActiveSheet()->getColumnDimension('f')->setWidth(40); $objPHPExcel->getActiveSheet()->getColumnDimension('e')->setWidth(12); } $objPHPExcel->getActiveSheet(0)->setTitle('RR.HH(Pvigente)'); $sql1="select usuarios,nombreusuario,grupo,nombregrupo from resultados"; $objPHPExcel2 = $objPHPExcel->createSheet(); if ($registros1 >0){ require_once 'Classes/PHPExcel.php'; $i =4; $objPHPExcel->setActiveSheetIndex(1) ->setCellValue('A'.$i,$registros1->usuarios) ->SetCellValue('B'.$i,$registros1->nombreusuario) ->SetCellValue('c'.$i,$registros1->grupo) ->SetCellValue('d'.$i,$registros1->nombregrupo); $i++; } $objPHPExcel2->setCellValue('a1','Plantilla de Racf'); $objPHPExcel2->setCellValue('A3','Usuarios'); $objPHPExcel2->setCellValue('B3','Nombre Usuario'); $objPHPExcel2->setCellValue('C3','Grupo'); $objPHPExcel2->setCellValue('d3','Nombre Grupo'); 'bold' => true, 'rgb' => 'fffff' ) ), 'type' => PHPExcel_Style_Fill::FILL_SOLID, 'rgb' => '333399' ) ) ); $objPHPExcel->getActiveSheet()->getStyle("A1:d1")->applyFromArray($miestilo); $objPHPExcel->getActiveSheet()->getStyle("A3:d3")->applyFromArray($miestilo); $objPHPExcel->getActiveSheet()->getColumnDimension('a')->setAutoSize(true); $objPHPExcel->getActiveSheet()->getColumnDimension('b')->setAutoSize(true); $objPHPExcel->getActiveSheet()->getColumnDimension('c')->setAutoSize(true); $objPHPExcel->getActiveSheet()->getColumnDimension('d')->setAutoSize(true); $objPHPExcel->getActiveSheet()->getStyle('A1')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER); $objPHPExcel->getActiveSheet()->MergeCells('A1:D1'); }