I have this code which I use in python to extract errors in Word Document, It works fine but the document does not look good, I want that the document has a title and at least shows the error in table format. Here is the code
import pandas as pd import numpy as np import docx from docx import Document dfs = pd.read_excel("Excel.xlsx", sheet_name="Random1",engine="openpyxl") dfs1 = pd.read_excel("Excel.xlsx", sheet_name="Random2",engine="openpyxl") doc = Document() temp_df = dfs.iloc[3:8, 2] print(temp_df.dtypes == np.object) if (temp_df.dtypes != np.object): print("this doesnt work") doc.add_paragraph("The ramge provided doesnt have data type as object .\n") else: print("it is object") doc.add_paragraph("it is object .\n") doc.save("MyDoc.docx") doc = Document("ErrorLog.docx") temp_df = dfs22.iloc[0:9, 2] print(temp_df.dtypes == np.float) if (temp_df.dtypes != np.float): print("this doesnt work") doc.add_paragraph("Sheet Random on Range C2-C10 has error, please provide values with float values .\n") else: print("Data range is correct of (C2-C10) !") doc.add_paragraph("Data range is correct (C2-C10)! .\n") doc.save("ErrorLog.docx")
Each error would be shown in table and have Numbers. The text error to show in the description part of the table and in the end to show the range where error appears. Three columns and each error has their own row. #/Description/Range
dfs to be on first line and then the next one to be on dfs22 line.
Thank you for your help and patience. Best Regards