Forums

How to make a word document structered nice with python ?

HI Everyone,

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")

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 Thank you for your help and patience. Best Regards

We can help you here with questions related to our service. You should look at some more general forums for answers to general questions unrelated to the PythonAnywhere platform.