feat: word selection cursor and table com

This commit is contained in:
yu committed 2026-10-30 16:25:44 +08:00
1 parent 32269a5760
commit 23d292fdff
2 files changed
+164 -1

No files matched your search

+24 -1
View File
@@ -15,7 +15,7 @@ const node = (id: string): FlowNode => ({ id, componentId: id, position: { x: 0,
async function run(id: string, args: Record<string, unknown> = {}) { const handler = getHandler(id); expect(handler, id).toBeTruthy(); return handler!(context, node(id), args, component); }
afterEach(async () => Promise.all(directories.splice(0).map((directory) => rm(directory, { recursive: true, force: true }))));
const ids = ["Word_New_V1", "Word_GetPath", "Word_ReadAll", "Word_Replace", "Word_Enter", "Word_InsertPage", "Word_SetFontName", "Word_SetFontSize", "Word_SetFontStyle", "Word_SetFontColor", "Word_SetAlign", "Word_InsertPicture", "Word_WriteTable", "Word_Close"];
const ids = ["Word_New_V1", "Word_GetPath", "Word_ReadAll", "Word_Replace", "Word_Enter", "Word_InsertPage", "Word_SetFontName", "Word_SetFontSize", "Word_SetFontStyle", "Word_SetFontColor", "Word_SetAlign", "Word_InsertPicture", "Word_WriteTable", "Word_Close", "Word_ReadSelect", "Word_CutSelect", "Word_CopySelect", "Word_PasteSelect", "Word_DeleteSelect", "Word_SelectAll", "Word_SelectRow", "Word_SetPosition", "Word_MovePosition", "Word_PositionToSelect", "Word_ReadTable"];
describe("Word extended capabilities", () => {
it("registers automated Word operations", () => { for (const id of ids) expect(getHandler(id), id).toBeTruthy(); });
@@ -33,4 +33,27 @@ describe("Word extended capabilities", () => {
await run("Word_Enter", { objWord: handle });
expect((await readFile(path.join(directory, "extended.docx"))).byteLength).toBeGreaterThan(1000);
}, 120000);
it("uses a persistent selection and reads a Word table through COM", async () => {
if (process.platform !== "win32") return;
const directory = await mkdtemp(path.join(os.tmpdir(), "rpa-word-selection-")); directories.push(directory);
let handle = await run("Word_New_V1", { filePath: directory, name: "selection.docx" });
await run("Word_Write", { objWord: handle, text: "alpha beta gamma" });
handle = await run("Word_PositionToSelect", { objWord: handle, text: "beta", pos_index: 1, direction: "select" });
await expect(run("Word_ReadSelect", { objWord: handle })).resolves.toBe("beta");
handle = await run("Word_CopySelect", { objWord: handle });
handle = await run("Word_MovePosition", { objWord: handle, length: 1, unit: "word", direction: "right", isSelect: false });
await run("Word_PasteSelect", { objWord: handle });
handle = await run("Word_PositionToSelect", { objWord: handle, text: "gamma", direction: "select" });
handle = await run("Word_CutSelect", { objWord: handle });
await expect(run("Word_ReadSelect", { objWord: handle })).resolves.toBe("");
await run("Word_DeleteSelect", { objWord: handle });
handle = await run("Word_SetPosition", { objWord: handle, length: -2, unit: "word" });
handle = await run("Word_SelectRow", { objWord: handle, st: 1, ed: 1 });
await expect(run("Word_ReadSelect", { objWord: handle })).resolves.toContain("alpha");
handle = await run("Word_SelectAll", { objWord: handle });
await expect(run("Word_ReadSelect", { objWord: handle })).resolves.toContain("alpha beta beta");
await run("Word_WriteTable", { objWord: handle, data: [["name", "age"], ["Alice", "30"]] });
await expect(run("Word_ReadTable", { objWord: handle, find_type: "content", table_content: "Alice" })).resolves.toEqual([["name", "age"], ["Alice", "30"]]);
}, 180000);
});