[英]How to access for editing an ALREADY OPENED DOCX (using win32com.client in python)
I would like to make some "magic" in previously opened MS Docx (like a VS script), but I do not find how I can do it.我想在以前打开的 MS Docx (如 VS 脚本)中制作一些“魔法”,但我不知道该怎么做。 I have seen examples only like "word.Documents.Open" after Dispatch.在 Dispatch 之后,我只看到了像“word.Documents.Open”这样的例子。
I can do it with excel (I can access the opened MS Excel file on "the fly") for example:我可以使用 excel 来做到这一点(我可以“即时”访问打开的 MS Excel 文件),例如:
from win32com.client import Dispatch
xl = Dispatch("Excel.application")
xl.Visible = True
xl.Sheets["Action"].Select
current=xl.Sheets["Action"]
...
How I can do it in MS Word as well?我如何在 MS Word 中也能做到这一点?
I hope I was understandable.我希望我是可以理解的。 Thank you,谢谢,
Finally, I got it.最后我得到了它。 The key is: "word.ActiveDocument"关键是:“word.ActiveDocument”
Here is the code:这是代码:
from win32com.client import Dispatch
word = Dispatch('Word.Application')
word.Visible = 1
doc=word.ActiveDocument
for word_t in doc.Words:
print(word_t)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.