fix: Excel_WriteRange 对齐目录键名 cellPos/data/isSave
- 支持 cellPos(如 B2)定位起始单元格,与 column/row 双兼容 - 数据字段兼容 data 键(目录定义),保存字段兼容 isSave 键 - 新增 Excel_WriteRange 目录键名回归测试
This commit is contained in:
parent
877dab703f
commit
c5ac0ebc31
@ -49,4 +49,12 @@ describe("common Excel aliases", () => {
|
||||
const created = await run("Excel_NewExcel", { filePath: directory, name: "open-me.xlsx" }) as { path: string };
|
||||
await expect(run("Excel_OpenExcel", { filePath: created.path })).resolves.toMatchObject({ path: created.path });
|
||||
});
|
||||
|
||||
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 };
|
||||
await run("Excel_WriteRange", { objExcel: created, sheet: "Sheet1", cellPos: "B2", data: [[1, "壹"], [2, "贰"]], isSave: "True" });
|
||||
const reopened = await run("Excel_OpenExcel", { filePath: created.path }) as { id: string };
|
||||
await expect(run("Excel_Cs_ReadContentV2", { workbook: reopened, sheet: "Sheet1", excelRng: "B2:C3" })).resolves.toEqual([[1, "壹"], [2, "贰"]]);
|
||||
});
|
||||
});
|
||||
|
||||
@ -153,14 +153,18 @@ const writeCell: CapabilityHandler = async (_ctx, node, args) => {
|
||||
const writeRange: CapabilityHandler = async (_ctx, node, args) => {
|
||||
const { handle, workbook } = await resolveWorkbook(args, node.id, node.componentId);
|
||||
const sheet = sheetOf(workbook, text(args, ["sheet", "sheetName"]));
|
||||
const start = `${text(args, ["column"], "A")}${text(args, ["row"], "1")}`;
|
||||
const cellPos = text(args, ["cellPos"]);
|
||||
const cellMatch = cellPos.match(/^([A-Za-z]+)(\d+)$/);
|
||||
const column = cellMatch ? cellMatch[1] : text(args, ["column"], "A");
|
||||
const row = cellMatch ? cellMatch[2] : text(args, ["row"], "1");
|
||||
const start = `${column}${row}`;
|
||||
const startCell = sheet.getCell(start);
|
||||
const startRow = startCell.row;
|
||||
const startColumn = startCell.col;
|
||||
for (const [rowIndex, row] of rowsFrom(value(args, ["contents", "table"])).entries()) {
|
||||
for (const [rowIndex, row] of rowsFrom(value(args, ["contents", "data", "table"])).entries()) {
|
||||
for (const [columnIndex, cell] of row.entries()) sheet.getCell(startRow + rowIndex, startColumn + columnIndex).value = cell as ExcelJS.CellValue;
|
||||
}
|
||||
if (bool(value(args, ["save"]), true)) await workbook.xlsx.writeFile(handle.path);
|
||||
if (bool(value(args, ["save", "isSave"]), true)) await workbook.xlsx.writeFile(handle.path);
|
||||
return handle;
|
||||
};
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user