This commit is contained in:
zhang zhuo 2025-12-19 11:48:16 +08:00
parent 00e14c9688
commit 1096d26f14
1 changed files with 2 additions and 1 deletions

View File

@ -4,6 +4,7 @@ namespace App\Utils;
use Exception; use Exception;
use PhpOffice\PhpSpreadsheet\IOFactory; use PhpOffice\PhpSpreadsheet\IOFactory;
use PhpOffice\PhpSpreadsheet\Reader\Xlsx;
use PhpOffice\PhpSpreadsheet\Spreadsheet; use PhpOffice\PhpSpreadsheet\Spreadsheet;
use function Hyperf\Config\config; use function Hyperf\Config\config;
@ -19,7 +20,7 @@ class Excel
$file = BASE_PATH . DIRECTORY_SEPARATOR . 'runtime' . DIRECTORY_SEPARATOR . $file; $file = BASE_PATH . DIRECTORY_SEPARATOR . 'runtime' . DIRECTORY_SEPARATOR . $file;
if (!file_exists($file)) return false; if (!file_exists($file)) return false;
// 显式使用 Xlsx 读取器并配置兼容选项 // 显式使用 Xlsx 读取器并配置兼容选项
$reader = new \PhpOffice\PhpSpreadsheet\Reader\Xlsx(); $reader = new Xlsx();
// 关键配置:跳过样式/公式等兼容性陷阱 // 关键配置:跳过样式/公式等兼容性陷阱
$reader->setReadDataOnly(true); // 只读数据,忽略公式 $reader->setReadDataOnly(true); // 只读数据,忽略公式
$reader->setReadEmptyCells(false); // 跳过空单元格处理 $reader->setReadEmptyCells(false); // 跳过空单元格处理