warning can not modify header information PhpExcel

1

When I download the excel I get this error.

  

Warning: Can not modify header information - headers already sent by (output started at C: \ xampp \ htdocs \ Unified \ view \ Load.php: 54) in C: \ xampp \ htdocs \ Unified \ model \ ProLoad.php online 921

And so I get several someone save how to fix it?

Here I leave the code.

if ($_POST['producto'] === 'Cliente') {
    if (PHP_SAPI == 'cli') {
        die('<div class="alert alert-danger" role="alert"><strong>Error!</strong> Solo se puede ejecutar desde un navegador.</div>');
    }
    $objPHPExcel = new PHPExcel();
    $objPHPExcel->getProperties()->setCreator("")
            ->setLastModifiedBy("")
            ->setTitle("Office 2010 XLSX Documento de Excel")
            ->setSubject("Office 2010 XLSX Documento de Excel")
            ->setDescription("Documento de Excel para Office 2010 XLSX.")
            ->setKeywords("office 2010 openxml php")
            ->setCategory("Archivo con resultado de Excel");

    $objPHPExcel->setActiveSheetIndex(0)->mergeCells('A1:D1');
    $objPHPExcel->setActiveSheetIndex(0)
            ->setCellValue('A1', 'USUARIOS')
            ->setCellValue('A2', 'Producto')
            ->setCellValue('B2', 'Identificacion')
            ->setCellValue('C2', 'Nombre')
            ->setCellValue('D2', 'Apellido');

    $boldArray = array('font' => array('bold' => true,), 'alignment' => array('horizontal' => PHPExcel_Style_Alignment::HORIZONTAL_CENTER));
    $objPHPExcel->getActiveSheet()->getStyle('A1:D2')->applyFromArray($boldArray);

    $objPHPExcel->getActiveSheet()->getColumnDimension('A')->setWidth(10);
    $objPHPExcel->getActiveSheet()->getColumnDimension('B')->setWidth(12);
    $objPHPExcel->getActiveSheet()->getColumnDimension('C')->setWidth(22);
    $objPHPExcel->getActiveSheet()->getColumnDimension('D')->setWidth(25);

    $sql = "SELECT * FROM usuarios WHERE Producto = 'Cliente'";
    $query = mysqli_query($conexion, $sql);
    $cel = 3;
    while ($row = mysqli_fetch_array($query)) {
        $A = $row['Producto'];
        $B = $row['Identificacion'];
        $C = $row['Nombre'];
        $D = $row['Apellido'];

        $a = "A" . $cel;
        $b = "B" . $cel;
        $c = "C" . $cel;
        $d = "D" . $cel;

        $objPHPExcel->setActiveSheetIndex(0)
                ->setCellValue($a, $A)
                ->setCellValue($b, $B)
                ->setCellValue($c, $C)
                ->setCellValue($d, $D);

        $cel += 1;
    }

    $rango = "A2:$d";
    $rango2 = "A3:$d";
    $styleArray = array('font' => array('name' => 'Calibri', 'size' => 12),
        'borders' => array('allborders' => array('style' => PHPExcel_Style_Border::BORDER_THIN, 'color' => array('argb' => '000'))));
    $objPHPExcel->getActiveSheet()->getStyle($rango)->applyFromArray($styleArray);
    $styleArray2 = array('font' => array('name' => 'Calibri', 'size' => 10),
        'borders' => array('allborders' => array('style' => PHPExcel_Style_Border::BORDER_THIN, 'color' => array('argb' => '000'))));
    $objPHPExcel->getActiveSheet()->getStyle($rango2)->applyFromArray($styleArray2);

    $objPHPExcel->getActiveSheet()->setTitle('Usuarios');
    $objPHPExcel->setActiveSheetIndex(0);

    $outputFileName = "RediferidosTG.xls";

    header("Content-Type: application/force-download");
    header("Content-Type: application/octet-stream");
    header("Content-Type: application/download");
    header('Content-Disposition:inline;filename="' . $outputFileName . '"');
    header("Content-Transfer-Encoding: binary");
    header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
    header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
    header("Pragma: no-cache");
    $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
    $objWriter->save('php://output');

    exit;

Thanks in advance.

    
asked by Kygo 21.01.2018 в 03:15
source

0 answers