I am trying to put a header image in my EXCEL document but I have not succeeded, I am using the PHPEXCEL library and the CODEIGNITER framework.
I hope you can help me, I share my code when I generate the EXCEL.
public function export_excel_calls() {
$fechas = $this->session->flashdata('fechas');
//echo($fechas['date_inicio']);
//print_r($fechas['date_inicio']);
//Exportar excel
$llamadas = $this->reg_calls_model->todas_calls($fechas['date_inicio'], $fechas['date_fin']);
//print_r($llamadas);
// if(!empty($llamadas)){
//Cargamos la librería de excel.
$this->load->library('excel');
$this->excel->setActiveSheetIndex(0);
$this->excel->getActiveSheet()->setTitle('Llamadas');
//Contador de filas
$contador = 1;
//Contador de registros
$contador1 = 1;
//$contador_row = 0;
//Le aplicamos ancho las columnas.
$this->excel->getActiveSheet()->getColumnDimension('A')->setWidth(10);
$this->excel->getActiveSheet()->getColumnDimension('B')->setWidth(15);
$this->excel->getActiveSheet()->getColumnDimension('C')->setWidth(10);
$this->excel->getActiveSheet()->getColumnDimension('D')->setWidth(20);
$this->excel->getActiveSheet()->getColumnDimension('E')->setWidth(10);
$this->excel->getActiveSheet()->getColumnDimension('F')->setWidth(15);
$this->excel->getActiveSheet()->getColumnDimension('G')->setWidth(15);
//Le aplicamos negrita a los títulos de la cabecera.
$this->excel->getActiveSheet()->getStyle("A{$contador}")->getFont()->setBold(true);
$this->excel->getActiveSheet()->getStyle("B{$contador}")->getFont()->setBold(true);
$this->excel->getActiveSheet()->getStyle("C{$contador}")->getFont()->setBold(true);
$this->excel->getActiveSheet()->getStyle("D{$contador}")->getFont()->setBold(true);
$this->excel->getActiveSheet()->getStyle("E{$contador}")->getFont()->setBold(true);
$this->excel->getActiveSheet()->getStyle("F{$contador}")->getFont()->setBold(true);
$this->excel->getActiveSheet()->getStyle("G{$contador}")->getFont()->setBold(true);
//Definimos los títulos de la cabecera.
$this->excel->getActiveSheet()->setCellValue("A{$contador}", 'No');
$this->excel->getActiveSheet()->setCellValue("B{$contador}", 'Destino');
$this->excel->getActiveSheet()->setCellValue("C{$contador}", 'Origen');
$this->excel->getActiveSheet()->setCellValue("D{$contador}", 'Fecha');
$this->excel->getActiveSheet()->setCellValue("E{$contador}", 'Duración');
$this->excel->getActiveSheet()->setCellValue("F{$contador}", 'Estado');
//Definimos la data del cuerpo.
foreach($llamadas as $l){
//Incrementamos una fila más, para ir a la siguiente.
$contador++;
//Informacion de las filas de la consulta.
$this->excel->getActiveSheet()->setCellValue("A{$contador}", $contador1);
$this->excel->getActiveSheet()->setCellValue("B{$contador}", $l->src);
$this->excel->getActiveSheet()->setCellValue("C{$contador}", $l->dst);
$this->excel->getActiveSheet()->setCellValue("D{$contador}", $l->calldate);
$this->excel->getActiveSheet()->setCellValue("E{$contador}", $l->billsec);
$this->excel->getActiveSheet()->setCellValue("F{$contador}", $l->disposition);
$contador1++;
}
//Le ponemos un nombre al archivo que se va a generar.
$archivo = 'Reporte-'.time().'.xls';
header('Content-Type: application/vnd.ms-excel');
header('Content-Disposition: attachment;filename="'.$archivo.'"');
header('Cache-Control: max-age=0');
$objWriter = PHPExcel_IOFactory::createWriter($this->excel, 'Excel5');
//Hacemos una salida al navegador con el archivo Excel.
$objWriter->save('php://output');
// }else{
// redirect('login_controller/perfil_calls', 'refresh');
// }
}