Problems generating Excel report with PHP

0

I am trying to generate a report from ORACLE using PHP. By clicking on the "generate excel" button, you have no problem bringing me an .xls.

The problem is that the .xls file does not bring the columns separated by cells.

This is the code:

?php 

    if(isset($_POST['generar_reporte'])){

        try{
            $conn = new PDO('oci:dbname=192.168.1.95:1521/orcl;charset=UTF8', 'bi_src', 'bi_src');
        }catch(Exception $e){
            echo($e->getMessage());
        }

        //NOMBRE DEL ARCHIVO Y CHARSET
        header('Content-type: application/vnd.ms-excel');
        header("Content-Disposition: attachment; filename=reporte.xls");
        header("Pragma: no-cache");
        header("Expires: 0");

        //SALIDA DEL ARCHIVO
        $salida=fopen('php://output', 'w');

        //ENCABEZADOS
        fputcsv($salida, array('Cuenta', 'Cliente', 'Aliado / Ejecutivo'));

        //QUERY PARA CREAR EL REPORTE
        $stid = $conn->prepare("SELECT M000.NBCLI000, M000.G300CTA, U000.NBUSUF000 FROM MRCJ000 M000, USEJE000 U000 WHERE M000.CUUID000 = U000.CUUID000");
        $stid->execute();

        foreach($stid as $row){
            fputcsv($salida, array($row['NBCLI000'],
                                   $row['G300CTA'],
                                   $row['NBUSUF000']));
        }

    }

?>

<form action="reporte.php" method="POST">
     <input type="submit" class="btn" value="Generar Excel" name="generar_reporte">
 </form>
    
asked by Víctor Álvarez 27.12.2018 в 16:09
source

0 answers