Possible Duplicate:
How to search and replace in MS Word Textbox using Python
How to manuplate textbox in MS Word using Python Hello , I’m a newbie to python. I want to do some automating work in hundreds of msword files. I need to do lots of search and replace work.
I got an example from internet. So I can replace original string AAA with BBB in hundreds of msword files. But however it can not replace the strings in textbox. Almost drive me crazy and it’s hard to find the solution.
My Python version is 2.7 and I include the following libraries in my file. I still can NOT show every textbox’s text in word files
I tried the solution Python win32com - Automating Word - How to replace text in a text box? but it didn't work
canvas = word.ActiveDocument.Shapes[0]
for item in canvas.CanvasItems:
print item.TextFrame.TextRange.Text
Even i can get canvas object, but in the above "FOR loop" , i'll get the error exception. it seems it didn't have those members.
Does anyone can give me some concrete examples , Or other popular frameworks or libraries in Windows to handle MS Word/Excel. Thank you in advance…thank you very much~
Belows are the errors , it seems i tried to access non-existed attribute.
Traceback (most recent call last):
File "a.py", line 108, in <module>
main()
File "a.py", line 86, in main
AppWord = ReadWrod(docPath)
File "a.py", line 51, in ReadWrod
testTB(doc)
File "a.py", line 22, in testTB
print doc.Shapes[0].TextFrame.TestRange.Text
File "C:\Python27\lib\site-packages\win32com\client\dynamic.py", line 522, in __getattr__
raise AttributeError("%s.%s" % (self._username_, attr))
AttributeError: <unknown>.TestRange