如果用户没有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()
…///