Home > other >  Python processing word of the header
Python processing word of the header

Time:10-03

The code is as follows:
The import win32com
The from win32com. Client import Dispatch, constants
W=win32com. Client. DispatchEx (' Word. Application)

# to open the new file
Doc=w.D ocuments. Open (FileName='f: \ \ xx \ \ 1. Doc')
# # worddoc=w.D ocuments. The Add () to create a new document

# header text to replace
W. ctiveDocument. Sections [0]. Headers [0]. Range. The Find. ClearFormatting ()
W. ctiveDocument. Sections [0]. Headers [0]. Range. The Find. Replacement. ClearFormatting ()
W. ctiveDocument. Sections [0]. Headers [0]. Range. The Find. The Execute (' 111 ', False, False, False, False, False, True, 1, False, '222', 2)

Tips are as follows:
Traceback (the most recent call last) :
The File "F:/machine/homework/writer/try py", line 27, the in & lt; module>
W. ctiveDocument. Sections [0]. Headers [0]. Range. The Find. ClearFormatting ()
TypeError: 'Sections' object is not subscriptable

The question is: before the above code can be run, can replace the header text,
What reason be? Now use pycharm + python3.7.

CodePudding user response:

I will not encounter this error, but after the program is running, the header text without replacement, want to ask the landlord to solve back?
  • Related