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);