From f0df43e2f2f1714fc6a3f813d36c09a2afa30b75 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E8=8B=8F=E6=9C=A8?= <594326199@qq.com>
Date: Thu, 26 Nov 2026 15:31:21 +0800
Subject: [PATCH] =?UTF-8?q?fix(=E5=AF=B9=E8=B4=A6=E5=8D=95):=20=E4=BF=AE?=
=?UTF-8?q?=E5=A4=8D=20Excel=20=E7=A9=BA=E8=A1=8C=E5=AF=BC=E8=87=B4?=
=?UTF-8?q?=E4=B8=8A=E4=BC=A0=E5=8D=A1=E6=AD=BB?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
自闭合空行现在会正确推进 XMLReader,避免同一空行无限重复读取。
Co-authored-by: 苏木 <594326199@qq.com>
Co-committed-by: 苏木 <594326199@qq.com>
---
.../Services/PayablesWorkbookStreamReader.php | 4 +++
.../PayablesFinalImportRunnerTest.php | 26 +++++++++++++++++++
2 files changed, 30 insertions(+)
diff --git a/modules/EcommerceFinance/Services/PayablesWorkbookStreamReader.php b/modules/EcommerceFinance/Services/PayablesWorkbookStreamReader.php
index d038b11d..3e0e29e3 100644
--- a/modules/EcommerceFinance/Services/PayablesWorkbookStreamReader.php
+++ b/modules/EcommerceFinance/Services/PayablesWorkbookStreamReader.php
@@ -136,6 +136,10 @@ class PayablesWorkbookStreamReader
$depth = $reader->depth;
$empty = $reader->isEmptyElement;
if ($empty) {
+ // A self-closing
must be consumed before the outer loop
+ // evaluates the current node again, otherwise this row repeats forever.
+ $reader->read();
+
return $cells;
}
diff --git a/tests/Feature/Business/PayablesFinalImportRunnerTest.php b/tests/Feature/Business/PayablesFinalImportRunnerTest.php
index 33f95624..bef09864 100644
--- a/tests/Feature/Business/PayablesFinalImportRunnerTest.php
+++ b/tests/Feature/Business/PayablesFinalImportRunnerTest.php
@@ -66,6 +66,27 @@ class PayablesFinalImportRunnerTest extends FeatureTestCase
}
}
+ public function test_stream_reader_advances_past_self_closing_empty_xlsx_rows(): void
+ {
+ $path = $this->makeXlsxFile([
+ self::HEADER,
+ ['2026-10', 'RK-1', '921979', '2026-10-10', '亿之航', 'DSG004820', 'DSG004820N1019V01', '款式四', '30', '83.5', '2505'],
+ [],
+ ['2026-10', 'RK-2', '941828', '2026-10-10', '亿之航', 'DSG004820', 'DSG004820N1019V01', '款式四', '30', '83.5', '2505'],
+ ]);
+
+ try {
+ $reader = PayablesWorkbookStreamReader::forFile($path, 'xlsx');
+ $rows = iterator_to_array($reader->rows(0), true);
+
+ $this->assertSame([1, 2, 3, 4], array_keys($rows));
+ $this->assertSame([], $rows[3]);
+ $this->assertSame('RK-2', $rows[4][1]);
+ } finally {
+ @unlink($path);
+ }
+ }
+
public function test_stream_reader_reads_gbk_csv(): void
{
$content = mb_convert_encoding(implode(',', self::HEADER) . "\n2026-09,RK-9,CG-9,2026-09-08,供应商九,X-9,P-9,规格甲,2,10,20,9,18,SC-1,备注甲,华东仓,顺丰,SF-9,未发出,对账人甲\n", 'GBK', 'UTF-8');
@@ -246,6 +267,11 @@ class PayablesFinalImportRunnerTest extends FeatureTestCase
$sheet = '';
foreach ($rows as $rowIndex => $row) {
+ if ($row === []) {
+ $sheet .= '
';
+ continue;
+ }
+
$sheet .= '';
foreach ($row as $columnIndex => $value) {
$cell = chr(65 + $columnIndex) . ($rowIndex + 1);