Fatal error: "break" is not in the context of the "loop" or "switch" in Function.php

I try PHPExcel and I get an error in the output when I execute my script:

Fatal error: "break" is not in the context of the "loop" or "switch" in /opt/lampp/htdocs/Xlsphp/test/Classes/PHPExcel/Calculation/Functions.php on line 581

I do not know what I am doing wrong in my PHP script. Everything seems to be correct.

Does anyone know how to solve it?

Here is my PHP script:

<?php require_once 'Classes/PHPExcel.php'; require_once 'config.php'; $sql = 'SELECT * FROM tablevalues'; $result = mysqli_query($conn, $sql) or die(mysqli_error($conn)); $fileName = 'test.xls'; // initialise excel column name // currently limited to queries with less than 27 columns $columnArray = array("A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"); // Instantiate a new PHPExcel object $objPHPExcel = new PHPExcel(); // Set the active Excel worksheet to sheet 0 $objPHPExcel->setActiveSheetIndex(0); // Initialise the Excel row number $rowCount = 1; // fetch result set column information $finfo = mysqli_fetch_fields($result); // initialise columnlenght counter $columnlenght = 0; foreach ($finfo as $val) { // set column header values $objPHPExcel->getActiveSheet()->SetCellValue($columnArray[$columnlenght++] . $rowCount, $val->name); } // make the column headers bold $objPHPExcel->getActiveSheet()->getStyle($columnArray[0]."1:".$columnArray[$columnlenght]."1")->getFont()->setBold(true); $rowCount++; // Iterate through each result from the SQL query in turn // We fetch each database result row into $row in turn while ($row = mysqli_fetch_array($result, MYSQLI_NUM)) { for ($i = 0; $i < $columnlenght; $i++) { $objPHPExcel->getActiveSheet()->SetCellValue($columnArray[$i] . $rowCount, $row[$i]); } $rowCount++; } // set header information to force download header('Content-type: application/vnd.ms-excel'); header('Content-Disposition: attachment; filename="' . $fileName . '"'); // Instantiate a Writer to create an OfficeOpenXML Excel .xlsx file // Write the Excel file to filename some_excel_file.xlsx in the current directory $objWriter = new PHPExcel_Writer_Excel2007($objPHPExcel); // Write the Excel file to filename some_excel_file.xlsx in the current directory $objWriter->save('php://output'); mysqli_close($conn); ?> 
+8
php phpexcel
source share
2 answers

Just delete the break statement; "in the functions.php file. Like a break after the return statement, so it gives a fatal error.

+7
source share

The correct way to solve the incompatibility problem with third-party open source libraries:

  • Check if there is an already released updated version of the library with which you are having a problem with
  • Send the error to the library developer, and if you fixed the diff file with the fix or git transfer request

In your case, just download PHPExcel from github, unzip and overwrite the old libraries.

+1
source share

All Articles