簡體   English   中英

如何訪問以編輯已打開的 DOCX(在 python 中使用 win32com.client)

[英]How to access for editing an ALREADY OPENED DOCX (using win32com.client in python)

我想在以前打開的 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)  

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM