"Test_Plan"という名前のフォルダが1つあります。複数のdocxファイルで構成され、各docxファイルには複数のテーブルがあります。私の質問は、どのように私はdocxファイル全体を読むことができると出力を与えるのですか?たとえば、すべてのdocxファイルは複数のテーブルを持って、私は1つのdocxファイルを選ぶと同じフォルダ内の複数のdocxファイルのテーブルをPythonで読み取る方法
(IE)のような出力が得られていますテーブルの
総数:YES自動化の52
総数:6
総数NOオートメーションの:5
このように私はその "Test_Plan"フォルダ内のファイルの数を自動化する必要があります。 あなたは私の質問を理解することを願っています。
単一のdocxファイルからの読み込みテーブルの私のコード:
#Module to retrive the word documents
from docx import Document
doc = Document("sample2.docx")
#Reading the tables in the particular docx
i = 0
for t in doc.tables:
for ro in t.rows:
if ro.cells[0].text=="ID" :
i=i+1
print("Total Number of Tables: ", i)
#Counting the values of Automation
# This will count how many yes automation
j=0
for table in doc.tables:
for ro in table.rows:
if ro.cells[0].text=="Automated Test Case" and (ro.cells[2].text=="yes" or ro.cells[2].text=="Yes"):
j=j+1
print("Total Number of YES Automations: ", j)
#This part is used to count the No automation values
k = 0
for t in doc.tables:
for ro in t.rows:
if ro.cells[0].text=="Automated Test Case" and (ro.cells[2].text=="no" or ro.cells[2].text=="No"):
k=k+1
print("Total Number of NO Automations: ", k)
出力:
うん、少し後で取り戻します。 –
こんにちはAndreas私は非常にPythonに新しいです。少し高く説明してください。 –
私の解説を私の答えに加えてください。 –