Jan-09-2020, 12:39 PM
Hi Everyone,
Please help with the loop logic.
There are multiple tables available in the word docx.
I am trying to read a particular Table e.g. Table2 in a docx document.
I need to read contents only from column 3 of Table2 having column name as 'status'.
The current logic, it reads all the rows data from Table 2 till Table 3. How do I make read only column3 data from Table2.
Table1
Sr. Name Age City
1 Mr. XYZ 12 sfs
2 Mr. YDS 34 safdas
3 Mr. ZSD 20 asfd
4 Mr. BSD 50 asd
Table2
Sr. Name Status City
1 Mr. XYZ Single sfs
2 Mr. YDS Married safdas
3 Mr. ZSD Single asfd
4 Mr. BSD Divorcee asd
Table3
Sr. Name Age City State
1 Mr. XYZ 12 sfs MK
2 Mr. YDS 34 safdas JS
3 Mr. ZSD 20 asfd SD
4 Mr. BSD 50 asd WE
Please help with the loop logic.
There are multiple tables available in the word docx.
I am trying to read a particular Table e.g. Table2 in a docx document.
I need to read contents only from column 3 of Table2 having column name as 'status'.
The current logic, it reads all the rows data from Table 2 till Table 3. How do I make read only column3 data from Table2.
Table1
Sr. Name Age City
1 Mr. XYZ 12 sfs
2 Mr. YDS 34 safdas
3 Mr. ZSD 20 asfd
4 Mr. BSD 50 asd
Table2
Sr. Name Status City
1 Mr. XYZ Single sfs
2 Mr. YDS Married safdas
3 Mr. ZSD Single asfd
4 Mr. BSD Divorcee asd
Table3
Sr. Name Age City State
1 Mr. XYZ 12 sfs MK
2 Mr. YDS 34 safdas JS
3 Mr. ZSD 20 asfd SD
4 Mr. BSD 50 asd WE
import docx file2 = docx.Document("C:\\Test_Document.docx") document1 = file2 columns1=[] i = 0 j = 0 def function_verifystatus(document1): flag1 = True for (table_no,table) in enumerate(document1.tables): for (i,row) in enumerate(table.rows): for (j,cell) in enumerate(row.cells): if cell.text == "Status": k = j flag1 = False if (flag1 == False): for (i,k) in enumerate(row.cells): columns1.append(k.text) print("status value is:", k.text) flag1 = True return columns1 result1=function_verifystatus(document1)