Problems with PHPExcel

1

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 ...

    
asked by José Gregorio Calderón 23.05.2017 в 00:52
source

1 answer

1

It is possible that your installation of Excel requires a conversion to be able to show the file, either because the file is badly formed or because it is an old format.

The .xls extension corresponds to older versions of Excel. In the 2007 version, the .xlsx extension was introduced. Note that since then several versions have already passed, not counting the service packages. In May 2017, the current version is 2016.

    
answered by 23.05.2017 в 04:45