python - 如何访问以编辑已打开的 DOCX(在 python 中使用 win32com.client)
问题描述
我想在以前打开的 MS Docx (如 VS 脚本)中制作一些“魔法”,但我不知道该怎么做。在 Dispatch 之后,我只看到了像“word.Documents.Open”这样的例子。
我可以用 excel 来做(我可以“即时”访问打开的 MS Excel 文件),例如:
from win32com.client import Dispatch
xl = Dispatch("Excel.application")
xl.Visible = True
xl.Sheets["Action"].Select
current=xl.Sheets["Action"]
...
我如何在 MS Word 中也能做到这一点?
我希望我是可以理解的。谢谢,
解决方案
最后我得到了它。关键是:“word.ActiveDocument”
这是代码:
from win32com.client import Dispatch
word = Dispatch('Word.Application')
word.Visible = 1
doc=word.ActiveDocument
for word_t in doc.Words:
print(word_t)
推荐阅读
- c - printf("%.0f\n", nc) 没有打印意图信息
- reactjs - React-Loadable 与第三方反应组件不起作用
- json - Flutter 使用来自 Golang RFC3339 的 DateTime 解析 json:FormatException:无效的日期格式
- game-maker - 球在乒乓克隆中卡在桨内(游戏制作者)
- swift - 在 Swift 中,协议扩展是否允许函数体?
- r - ggplot2中的中值回归线
- php - 计算更换零件的运行小时数
- r - 在 r 中拆分分组的二项式数据
- scala - 如何更改 Rocket Chip 中非阻塞数据缓存的缓存行大小?
- laravel - 检测到 Laravel 全局中间件但未更改模型记录