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;