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

Analysis of the process of locating and reading python-docx files

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

Share

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

This article introduces the relevant knowledge of "python-docx file positioning reading process analysis". In the operation of actual cases, many people will encounter such a dilemma. Next, let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

The above is the beginning. After installation, the code that needs to be imported and reprinted reads the contents of all docx files and finds that the table data is not read:

From docx import Document

Def readDocx (docName): fullText = [] doc = docx.Document (docName) paras = doc.paragraphs for p in paras: fullText.append (p.text) return'\ n'.join (fullText)

Try to pinpoint the data of the first cell in the first table (only one table will be read as an array):

Doc = docx.Document ('04.docx') print doc.tables [0] .rows [0] .cells [0] .text

Replacement statement:

Pname=unicode (context.rows [4] .cells [1] .text) # use unicode or u because Chinese is not compatible

Save statement:

Resoult=doc.save (u'guochengwendang/04 DAEQP18-PS-04 work check-in form .docx')

Doc attribute doc.paragraphs fetch content (excluding special factors such as tables)

Doc.paragraphssStr1= doc.paragraphs [0] .text s=sStr1.replace (u "JKZX", unicode (context.rows [5] .cells [1] .text)) doc.paragraphs [0] .text = s

This is the end of the content of "python-docx File location Reading process Analysis". Thank you for your reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

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