Get the App
SLTechnology News&Howtos  ›  Development  › 

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

Shulou Source: shulou.com Published: 2022-06-02 15:19:11 09月21日 Update

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!

Tags: Content tables files processes positioning analysis data more knowledge statements practicality precision learning and then code units only factors dilemmas reality. Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Redmi Linux Docker NVidia macOS