fix - bug
This commit is contained in:
@ -31,7 +31,7 @@ class ExcelHelper
|
||||
* @throws \PhpOffice\PhpSpreadsheet\Exception
|
||||
* @throws \PhpOffice\PhpSpreadsheet\Writer\Exception
|
||||
*/
|
||||
public static function exportData(ResponseInterface $response, $list = [], $header = [], $filename = '', $suffix = 'xlsx', $path = '')
|
||||
public static function exportData(ResponseInterface $response, array $list = [], $header = [], $filename = '', $suffix = 'xlsx', $path = '')
|
||||
{
|
||||
if (!is_array($list) || !is_array($header)) {
|
||||
return false;
|
||||
@ -53,27 +53,29 @@ class ExcelHelper
|
||||
|
||||
// 开始写入内容
|
||||
$column = 2;
|
||||
$size = ceil(count($list) / 500);
|
||||
for ($i = 0; $i < $size; $i++) {
|
||||
$buffer = array_slice($list, $i * 500, 500);
|
||||
foreach ($list as $sheetTitle => $sheetListItem) {
|
||||
$sheet->setTitle($sheetTitle);
|
||||
$size = ceil(count($sheetListItem) / 500);
|
||||
for ($i = 0; $i < $size; $i++) {
|
||||
$buffer = array_slice($sheetListItem, $i * 500, 500);
|
||||
|
||||
foreach ($buffer as $k => $row) {
|
||||
$span = 1;
|
||||
foreach ($buffer as $k => $row) {
|
||||
$span = 1;
|
||||
|
||||
foreach ($header as $key => $value) {
|
||||
// 解析字段
|
||||
$realData = self::formatting($header[$key], trim(self::formattingField($row, $value[1])), $row);
|
||||
// 写入excel
|
||||
$sheet->setCellValueExplicit(Coordinate::stringFromColumnIndex($span) . $column, $realData, DataType::TYPE_STRING);
|
||||
// $sheet->setCellValue(Coordinate::stringFromColumnIndex($span) . $column, $realData);
|
||||
$span++;
|
||||
foreach ($header as $key => $value) {
|
||||
// 解析字段
|
||||
$realData = self::formatting($header[$key], trim(self::formattingField($row, $value[1])), $row);
|
||||
// 写入excel
|
||||
$sheet->setCellValueExplicit(Coordinate::stringFromColumnIndex($span) . $column, $realData, DataType::TYPE_STRING);
|
||||
// $sheet->setCellValue(Coordinate::stringFromColumnIndex($span) . $column, $realData);
|
||||
$span++;
|
||||
}
|
||||
|
||||
$column++;
|
||||
unset($buffer[$k]);
|
||||
}
|
||||
|
||||
$column++;
|
||||
unset($buffer[$k]);
|
||||
}
|
||||
}
|
||||
|
||||
// 清除之前的错误输出
|
||||
// ob_end_clean();
|
||||
ob_start();
|
||||
|
Reference in New Issue
Block a user