Python reads the content of the word Table (1), pythonword
1. The home page introduces the content of the word Table. An example is as follows: each table is followed by a merged cell.
2. Introduce the win32com Module
3. Specific Code
1 # http://www.jb51.net/article/70318.htm 2 # http://www.cnblogs.com/graphics/articles/2953665.html 3 # http://shouce.jb51.net/python/ 4 import win32com, re 5 from win32com. client import Dispatch, constants 6 7 8 word = win32com. client. dispatch ('word. application ') 9''' 10 sets the Word visibility to visible. By default, you cannot see the Word program. Then, sets whether the Word warning information appears. By default, it does not appear, in this way, the Word warning message is not displayed when you use python to control Word. 11 ''' 12 word. displayalerts = 013 word. visible = 014 countdoc = word. documents. count15 print (countdoc) 16 doc = word. documents. open (r 'C: \ Users \ Administrator \ Desktop \ test \ document 1 \ 1.doc ') 17 # doc. saveAs (r 'C: \ Users \ Administrator \ Desktop \ test \ document 1 \ 1.txt ') 18 ''' 19 t = doc. tables [0] 20 # print (type (t) 21 tt = str (t) 22 # print (type (tt) 23 # print ("") 24 # split string 25 strs = tt. split ('') 26 print (strs [5]) 27 ''' 28 I = 029 while I <500: 30 t = doc. tables [I] 31 tt = str (t) 32 strs = tt. split ('') 33 print (strs [5]) 34 I = I + 135 36 doc. close () 37 word. quit ()Pythonword1
4. Problems Encountered
1 ). An error is prompted when you open the word. The reason is that my Documents and Open letters are in lower case.
2 ).
I directly convert the object obtained from the table into a string for processing.