特定のヘッダー (典型的な MS Word ヘッダー/フッターのように) を追加する必要がある数百ワードの文書があります。ヘッダーを変更する必要があるわけではありません。これらのドキュメントにはヘッダーが含まれていません。Python-docx モジュールでこれを行う方法はありますか? 私は最近それを発見しました、そしてそれは有望に思えます。
4041 次
4 に答える
1
また、ユーザーが docx パッケージを持っていない場合は、これを使用して win32 でも実行できます。
..//
import win32com.client
if win32com.client.gencache.is_readonly == True:
win32com.client.gencache.is_readonly = False
win32com.client.gencache.Rebuild()
from win32com.client.gencache import EnsureDispatch
from win32com.client import constants
word = win32com.client.gencache.EnsureDispatch("Word.Application")
word.Visible = False
#tell word to open the document
word.Documents.Open (IP_Directory_Dest + "\\" + name)
#open it internally
doc = word.Documents(1)
# for changing the header information of the Document
word.Visible = True
word.ActiveDocument.Sections(1).Headers(win32com.client.constants.wdHeaderFooterPrimary).Range.Text='STUFF U WANT AS UR DOCUMENT HEADER'
word.ActiveDocument.Save()
...///
于 2013-04-16T13:09:05.063 に答える
0
ものすごく単純。
from docx import *
document = yourdocument.docx
docbody = document.xpath('/w:document/w:body',namespaces=wordnamespaces)[0]
docbody.append(heading('Your header text',1) )
于 2012-07-25T18:29:14.457 に答える