Error generating an excel report in php and msql with PHPExcel

1

I am using PHPExcel to generate Excel reports with PHP from data obtained from a MySQL database.

This is the code I have and file shows this error:

  

Fatal error : 'break' not in the 'loop' or 'switch' context in    C: \ xampp \ htdocs \ Classroom \ Reports \ excel \ Classes \ PHPExcel \ Calculation \ Functions.php   online 581

<?php

require 'Classes/PHPExcel.php';
require 'conexion.php';

$sql = "SELECT id, nombre, precio, existencia FROM productos";
$resultado = $mysqli->query($sql);

$fila = 2;

$objPHPExcel = new PHPExcel();
$objPHPExcel->getProperties()->setCreator("C.T")->setDescription("Reporte de Productos");

$objPHPExcel->setActiveSheetIndex(0);
$objPHPExcel->getActiveSheet()->setTitle("Productos");

$objPHPExcel->getActiveSheet()->setCellValue('A1', 'ID');
$objPHPExcel->getActiveSheet()->setCellValue('B1', 'NOMBRE');
$objPHPExcel->getActiveSheet()->setCellValue('C1', 'PRECIO');
$objPHPExcel->getActiveSheet()->setCellValue('D1', 'EXISTENCIA');
$objPHPExcel->getActiveSheet()->setCellValue('E1', 'TOTAL');

while($row = $resultado->fetch_assoc())
{

    $objPHPExcel->getActiveSheet()->setCellValue('A'.$fila, $row['id']);
    $objPHPExcel->getActiveSheet()->setCellValue('B'.$fila, $row['nombre']);
    $objPHPExcel->getActiveSheet()->setCellValue('C'.$fila, $row['precio']);
    $objPHPExcel->getActiveSheet()->setCellValue('D'.$fila, $row['existencia']);
    $objPHPExcel->getActiveSheet()->setCellValue('E'.$fila, '=C'.$fila.'*D'.$fila);

    $fila++;

}

header("Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
header('Content-Disposition: attachment;filename="Productos.xlsx"');
header('Cache-Control: max-age=0');

$objWriter = new PHPExcel_Writer_Excel2007($objPHPExcel);
$objWriter->save('php://output');

?>
    
asked by Cristian Antonio Trujillo Gris 03.05.2018 в 16:53
source

1 answer

1

Apparently it is a bug in the library, version 1.8.1 works correctly. I share the url where you can download it: link

    
answered by 03.05.2018 / 19:15
source