gpt4 book ai didi

php - fatal error : 'break' not in the 'loop' or 'switch' context in Function. PHP

转载 作者:行者123 更新时间:2023-12-02 23:36:47 24 4
gpt4 key购买 nike

我正在尝试 PHPExcel,但在执行脚本时出现输出错误:

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

我不知道我的 PHP 脚本做错了什么。看来一切都是正确的。

有人知道如何解决吗?

这是我的 PHP 脚本:

<?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);
?>

最佳答案

只需删除“break;” function.php 文件中的语句。由于break是在return语句之后,所以它会给出 fatal error 。

关于php - fatal error : 'break' not in the 'loop' or 'switch' context in Function. PHP,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35918626/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com