V
V
vitHlJT62b7VCE22018-11-08 20:20:16
Python
vitHlJT62b7VCE2, 2018-11-08 20:20:16

How to extract the necessary data from the docx table?

I can’t figure out the docx library in any way (how to work correctly).
The table looks like this:
5be46f865dcc3909685731.png
You need to get the schedule for the group (which you specify in the condition) in this form.
Group name
%time%: %subject name% %audience% %teacher%
How to do it? I read the official documentation, but I did not understand it normally.
There are practically no examples.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
Z
Zanak, 2018-11-09
@Zanak

You need to see the code to see what exactly you are failing at. I open the documentation and see: we create a document instance by passing the path to the file, we get access to existing elements through inline_shapes, paragraphs, sections or tables, we create new ones using add_* methods. Each element on the page contains either a collection of nested elements or a text property, which is probably what you want.
In your case, the procedure should be something like this:
- read the document
- iterate through the tables (the tables property of the document) until we find the desired Table (the matching criterion can be, for example, the presence of the string "Aud." in the corresponding cells of the first row, the cell method table to help you)
- iterate through the rows of found tables, selecting from the cells the corresponding data in the case of a table header or a row with an object
- as it is found, add new data to the result
- close the document and show everything found

V
Vladimir, 2018-11-09
@vintello

1. rename the file to zip
2. unpack the archive into a folder
, we have a bunch of wonderful xml files. parsing, parsing, taking the data
in this way libraries actually work with this format, but sometimes parsing xml is much more convenient :)

S
Stormwalker, 2018-11-09
@Stormwalker

Try openpyxl or pandas.
Set the logic for bypassing the desired cells in a loop, and do what is required with the data.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question