I'm trying to modify a excel
with php, once I change what I need I'm supposed to save it, once I save it, then the problem arises that when I download it and open it, it tells me what next:
Being that I do not make any change I only open it and I give it to close, it is supposed that I should not show that message because when I change it I keep it. My code is as follows:
$fecha_inicial = $this->input->post ( 'date_start' );
$nombre_ruta = $this->input->post ( 'route_name' );
$archivo = str_replace(" ","_",$this->input->post ( 'name' ));
$ext = strrchr($archivo, ".");
$hoja_excel = "./plantillas_excel/".$archivo;
$this->load->library('excel');
$inputFileType = PHPExcel_IOFactory::identify($hoja_excel);
$objReader = PHPExcel_IOFactory::createReader($inputFileType);
$objPHPExcel = $objReader->load($hoja_excel);
$objPHPExcel->setActiveSheetIndex(0);
//Indicamos que se pare en la hoja uno del libro
$objWorksheet = $objPHPExcel->getActiveSheet();
$data = $objWorksheet->rangeToArray('A2:N2000');
$numeroCelda = 1;
foreach ($data as $row) {
$numeroCelda++;
if($row[0]!=null)
{
$fecha_nombre = str_replace ("-" , "" , $fecha_inicial );
//$objWorksheet->getCell('A'.$numeroCelda)->getValue()
$objWorksheet->SetCellValue('A'.$numeroCelda, $nombre_ruta." ".$fecha_nombre);
$valDateB = $objWorksheet->getCell('B'.$numeroCelda)->getValue();
if($valDateB!=null && is_numeric ( $valDateB )){
$valB= PHPExcel_Shared_Date::ExcelToPHPObject($valDateB);
$valDateB = $valB->format($fecha_inicial.' H:i:s');
$objWorksheet->SetCellValue('B'.$numeroCelda, PHPExcel_Shared_Date::PHPToExcel($valDateB));
}
$valDateN = $objWorksheet->getCell('N'.$numeroCelda)->getValue();
if($valDateN!=null && is_numeric ( $valDateN )){
$valN= PHPExcel_Shared_Date::ExcelToPHPObject($valDateN);
$valDateN = $valN->format($fecha_inicial.' H:i:s');
$objWorksheet->SetCellValue('N'.$numeroCelda, PHPExcel_Shared_Date::PHPToExcel($valDateN));
}
}
else {
break;
}
}
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, $inputFileType);
header("Content-Type: application/force-download");
header("Content-Type: application/application/vnd.ms-excel");
header("Content-Type: application/download");
header('Content-Disposition:inline;filename="'.$fecha_nombre.'.xls"');
header("Content-Transfer-Encoding: binary");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Pragma: no-cache");
$objWriter->save('php://output');
If someone knows where I'm watering it, I'd really appreciate it since I'm just getting into php in full ...