Python reads the content of the word Table (1), pythonword

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.