Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to read table contents in word by python

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article is about how python reads the contents of a table in word. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.

Word files look complex and not easy to structure. In fact, there are probably several kinds of content in word documents: paragraph (paragraphs), table (tables), and character (characters). The word documents I'm going to analyze now are basically paragraphs and tables. This paper mainly describes the method of analyzing the table from word and structuring the table information.

1. In order to parse word files using python, you can use the package docx, which needs to be installed in python first.

Pip install python-docx

2. After installation, you can read the word file.

Importdocxfn= rudder:\ everlasting song. Docx'doc=docx.Document (fn) # read all data by paragraph for paragraph indoc.paragraphs:print (paragraph.text) # read all data by table for table indoc.tables:for row intable.rows:for cell inrow.cells:print (cell.text) table_num=len (doc.tables) # get the number of tables print (table_num) table_0=doc.tables [0] # Select the first table table_rows = len (table_ 0.rows) # get the number of rows of the first table print (table_rows) tab=doc.tables [0] .rows [0] .cells [0] # get the first row of the first table, first column data print (tab.text) par= doc.paragraphs [2] # read the third paragraph of data print (par.text) Thank you for reading! This is the end of this article on "how python reads table contents in word". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, you can share it out for more people to see!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report