From 54571eff8d549eaef688a548f406c67bf195f19d Mon Sep 17 00:00:00 2001 From: yu <191972707@qq.com> Date: Wed, 28 Oct 2026 13:12:32 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20Excel=5FRenameSheet=20=E5=85=BC=E5=AE=B9?= =?UTF-8?q?=E7=9B=AE=E5=BD=95=E9=94=AE=E5=90=8D=20newSheet?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 处理器此前只读 newName/name/sheetName,而 Excel_RenameSheet 目录定义 与属性面板使用 newSheet,导致已填写新表名仍报「新 Sheet 名称为空」; 补充别名回归测试 --- src/main/capabilities/office-aliases.test.ts | 8 ++++++++ src/main/capabilities/office.ts | 2 +- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/main/capabilities/office-aliases.test.ts b/src/main/capabilities/office-aliases.test.ts index 36d7444..454c431 100644 --- a/src/main/capabilities/office-aliases.test.ts +++ b/src/main/capabilities/office-aliases.test.ts @@ -50,6 +50,14 @@ describe("common Excel aliases", () => { await expect(run("Excel_OpenExcel", { filePath: created.path })).resolves.toMatchObject({ path: created.path }); }); + it("renames a sheet through the Excel_RenameSheet newSheet key", async () => { + const directory = await mkdtemp(path.join(os.tmpdir(), "rpa-excel-rename-")); dirs.push(directory); + const created = await run("Excel_NewExcel", { filePath: directory, name: "rename-me.xlsx" }) as { path: string }; + await expect(run("Excel_RenameSheet", { objExcel: created, sheet: "Sheet1", newSheet: "库存表", isSave: "True" })).resolves.toBeTruthy(); + const reopened = await run("Excel_OpenExcel", { filePath: created.path }) as { id: string }; + await expect(run("Excel_GetSheetsName", { objExcel: reopened })).resolves.toEqual(["库存表"]); + }); + it("writes a range through the Excel_WriteRange catalog keys (objExcel/cellPos/data/isSave)", async () => { const directory = await mkdtemp(path.join(os.tmpdir(), "rpa-excel-range-")); dirs.push(directory); const created = await run("Excel_NewExcel", { filePath: directory, name: "range.xlsx" }) as { path: string }; diff --git a/src/main/capabilities/office.ts b/src/main/capabilities/office.ts index 5a8ed11..65aca16 100644 --- a/src/main/capabilities/office.ts +++ b/src/main/capabilities/office.ts @@ -197,7 +197,7 @@ register(["Excel_GetSheetsName", "Excel_GetSheetNames"], async (_ctx, node, args register(["Excel_Cs_Rename", "Excel_RenameSheet"], async (_ctx, node, args) => { const { handle, workbook } = await resolveWorkbook(args, node.id, node.componentId); const oldName = required(value(args, ["sheet", "oldName"]), "原 Sheet 名称", node.id, node.componentId); - const newName = required(value(args, ["newName", "name", "sheetName"]), "新 Sheet 名称", node.id, node.componentId); + const newName = required(value(args, ["newSheet", "newName", "name", "sheetName"]), "新 Sheet 名称", node.id, node.componentId); const sheet = sheetOf(workbook, oldName); sheet.name = newName; await workbook.xlsx.writeFile(handle.path);