From 9fdc1408b8ea55ae4a5f2d1cf2c46e4d71d51f4b Mon Sep 17 00:00:00 2001 From: qiuxiang <394405259@qq.com> Date: Tue, 6 Oct 2026 17:26:23 +0800 Subject: [PATCH] =?UTF-8?q?=E6=80=BB=E8=B4=A6=E5=A4=87=E6=B3=A8=E6=98=A0?= =?UTF-8?q?=E5=B0=84=E5=AF=BC=E5=85=A5=E6=94=AF=E6=8C=81=20--sheet=20?= =?UTF-8?q?=E9=80=89=E6=8B=A9=E5=B7=A5=E4=BD=9C=E8=A1=A8=EF=BC=88=E8=A1=A5?= =?UTF-8?q?=E4=BA=AC=E4=B8=9C=E7=BD=91=E9=93=B6=E9=92=B1=E5=8C=85/?= =?UTF-8?q?=E6=B7=98=E7=B3=BB=E5=BE=AE=E4=BF=A1=E4=B8=A4=E5=A4=84=E7=A9=BA?= =?UTF-8?q?=E5=88=97=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - account-ledger-remarks:import 新增 --sheet(序号或名称),默认仍读第一个工作表 - 用于导入分表2:京东 33 条(钱包页签项目)+ 天猫 25 条(wx… 微信项目),导入后两处空列即可按平台匹配出值 --- .../Commands/ImportAccountLedgerRemarks.php | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/app/Console/Commands/ImportAccountLedgerRemarks.php b/app/Console/Commands/ImportAccountLedgerRemarks.php index 190b092e..bcfc18c3 100644 --- a/app/Console/Commands/ImportAccountLedgerRemarks.php +++ b/app/Console/Commands/ImportAccountLedgerRemarks.php @@ -13,7 +13,7 @@ use Throwable; */ class ImportAccountLedgerRemarks extends Command { - protected $signature = 'account-ledger-remarks:import {path : xlsx/csv 文件} {--replace : 先清空再导入(默认按平台+账单项目覆盖)}'; + protected $signature = 'account-ledger-remarks:import {path : xlsx/csv 文件} {--sheet=1 : 工作表序号(从 1 开始)或名称} {--replace : 先清空再导入(默认按平台+账单项目覆盖)}'; protected $description = '导入账单项目对应的总账备注映射表'; @@ -89,7 +89,20 @@ class ImportAccountLedgerRemarks extends Command if ($readerType === 'Csv') { $reader->setInputEncoding('UTF-8'); } - $sheet = $reader->load($path)->getActiveSheet(); + $book = $reader->load($path); + $sheetOption = trim((string) $this->option('sheet')); + if ($sheetOption !== '' && ctype_digit($sheetOption)) { + $index = (int) $sheetOption - 1; + if ($index < 0 || $index >= $book->getSheetCount()) { + throw new \InvalidArgumentException('工作表序号超出范围:' . $sheetOption); + } + $sheet = $book->getSheet($index); + } else { + $sheet = $sheetOption === '' ? $book->getActiveSheet() : $book->getSheetByName($sheetOption); + if ($sheet === null) { + throw new \InvalidArgumentException('找不到工作表:' . $sheetOption); + } + } $rows = []; $header = null;