致命错误:';中断';不在';循环';或';开关';Function.php中的上下文
我正在尝试PHPExcel,执行脚本时输出中出现错误: 致命错误:第581行/opt/lampp/htdocs/Xlsphp/test/Classes/PHPExcel/Calculation/Functions.php中的“循环”或“切换”上下文中没有“中断” 我不知道我在PHP脚本中做错了什么。看来一切都是对的 有人知道怎么解决吗 以下是我的PHP脚本:致命错误:';中断';不在';循环';或';开关';Function.php中的上下文,php,phpexcel,Php,Phpexcel,我正在尝试PHPExcel,执行脚本时输出中出现错误: 致命错误:第581行/opt/lampp/htdocs/Xlsphp/test/Classes/PHPExcel/Calculation/Functions.php中的“循环”或“切换”上下文中没有“中断” 我不知道我在PHP脚本中做错了什么。看来一切都是对的 有人知道怎么解决吗 以下是我的PHP脚本: <?php require_once 'Classes/PHPExcel.php'; require_once 'config.ph
<?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);
?>
save('php://output');
mysqli_close($conn);
?>
只需删除functions.php文件中的“break;”语句即可。
因为break在return语句之后,所以它给出了致命错误。解决与第三方开源库不兼容问题的正确方法是:
在您的情况下,只需从github下载PHPExcel,解包并覆盖旧库。PHPExcel的哪个版本?@MarkBaker,您好,我使用的是PHPExcel版本1.8.0。这是一个针对版本1.8修复的错误。1@MarkBaker,谢谢你的回复。我在phpexcel上查看过,目前还没有可用的1.8.1版本。phpexcel的主页已打开,并且已经运行了近4年。。。。。该网站已经过时了,因为主页4年来一直试图告诉人们,只是为了澄清——PHP抱怨并不是因为break statemant是在返回后发现的,但是,因为它不在开关或循环块内,这在PHP 5.x下显然不是问题,但现在在将站点升级到7.x后,出现了错误。我刚刚更新了我的PHPExcel,现在一切都正常了!:拇指支撑: