Install
openclaw skills install @183347986/word-cursor-insert写报告时,把选中的一段话或 Excel/CSV 文件等内容,直接插进当前打开的 Word 光标处。文本和表格都能插,我会根据光标处语境判断该填成数字、文字还是表格,一次就插到位,重复执行也不会多插,几乎瞬间完成。告别手动复制粘贴。
openclaw skills install @183347986/word-cursor-insert⚡ 手写报告利器:把一段话、一个 Excel/CSV 表格,精准塞进 Word 光标所在位置。连接你正在编辑的 Word,读懂光标处语境,单调用完成插入,重复执行也不会多插——快、准、稳。
用 managed venv 的 python 直接跑脚本,文本走 --text,表格走文件路径:
~/.workbuddy/binaries/python/envs/default/Scripts/python.exe scripts/word_cursor_insert.py --text "要插的内容" [--newline]--file 路径.txt... word_cursor_insert.py 表.xlsx [--no-title](或 .csv)--no-idempotent一条命令插完,信任返回即停。不要先读脚本、不要插完另跑校验、不要为长中文额外写临时 py——那都是多出来的往返。
Insert data into the cursor of the Word document the user currently has open. Two modes: (1) a CSV/list becomes a formatted Word table (title + bold header + borders + autofit); (2) a short value becomes inline plain text (e.g. filling a blank inside a sentence). The workflow is context-aware (it inspects the cursor surroundings before inserting) and fast (Python + pywin32, bounded-window context read, single tool call).
doc.Range(0, sel.Start). Cost must stay O(window), independent of doc size.--text "中文内容" 走命令行(managed python 在 Windows 下吃中文 argv 没问题)。临时文件只是中文万一乱码的兜底(用 --file 路径.txt),非必做步骤——别为每次插入都先写个 py,那多一趟往返。0. Decide the result SHAPE first (this drives every later step, and is where over-engineering creeps in):
7) → inline TEXT mode. Do NOT export to
CSV; just compute the value and pass it via --text "...". This is the
common, fast path.word_cursor_insert.py 表.xlsx [--no-title] (or 表.csv [--no-title]).
Format is auto-detected by extension, so there is ONE table-insert path; no
CSV export, no second flag.
(Text mode skips this step entirely — no file, no temp.)sel.Information(12)). Do NOT run a
separate context-inspection call beforehand; that just duplicates a Word
COM round trip. One call = inspect + insert.scripts/word_cursor_insert.py (run with the managed venv python):
word_cursor_insert.py <csv_path> [--no-title]word_cursor_insert.py --text "内容" [--newline](长文本用 --file 路径.txt)--no-idempotent。
The script prints a short result (SKIP / OK + 字数). Trust it and stop — do
NOT run a separate verification read of the document; that is a redundant round
trip. Do not re-run.When writing reports you typically drop ONE of these at the cursor: (A) a paragraph of text / a single value → inline TEXT (B) an Excel table → a Word TABLE Collapse read-source + insert into a SINGLE call. Fixed skeleton — you only fill the marked line:
import win32com.client, time
t0=time.time()
# === fill THIS one line with what goes at the cursor ===
val = 7 # (A) 标量/文本;或 val = sum(...) / "段落…"
# val = read_table(r"X:\表.xlsx") # (B) 表格:read_table 自动识别 xlsx/csv
# =======================================================
word = win32com.client.GetActiveObject("Word.Application")
doc = word.ActiveDocument; sel = word.Selection
# 有界窗口整段判重(脚本已内置: 长文本整段比对, 短文本带边界, 不会"17"误判"7")
win=60; s=sel.Start; e=sel.End; dend=doc.Content.End
before = doc.Range(max(s-win,0), s).Text if s>0 else ""
after = doc.Range(e, min(e+win,dend)).Text if e<dend else ""
if str(val) in (before + after):
act = "SKIP(已存在, 幂等)" # 防重复: 不预检、不盲清, 同一次调用内判重
else:
sel.TypeText(str(val)); act = f"INSERTED {val}"
print("elapsed_s:", round(time.time()-t0,3), "|", act) # 1 call: 算+查上下文+插
--text "..." [--newline](长文本用 --file 路径.txt 读文件);临时文件只是兜底,默认直接 --text。word_cursor_insert.py 表.xlsx [--no-title] (or
表.csv) reads the file and inserts it as a Word table (bold header + borders
pywin32 must be installed in the managed venv:
~/.workbuddy/binaries/python/envs/default/Scripts/pip install pywin32
Run scripts with ~/.workbuddy/binaries/python/envs/default/Scripts/python.exe.
--newline to force
one).len(text) 一次得出,不要为计数去读整篇文档或逐字遍历;报数写 ~N字 即可,精确与否无所谓,快最重要。