1

I am writing this simple code like so

import prettytable

# open csv file
a = open("dash", 'r')

# read the csv file 
a = a.readlines()

# headers for table 
t = prettytable.PrettyTable(field_names=["Test", "Status"], title="Test Report",
                            header_style="title", header=True,
                            hrules=prettytable.ALL, vrules=prettytable.ALL)

# Adding the data 
for i in range(len(a)):
    row = a[i].split(',')
    t.add_row([row[0], row[1]])
    t.add_row(["",""])

code = t.get_html_string()
html_file = open('Table.html', 'w')
html_file = html_file.write(code)

But I get output like this

Test Report
Test    Status
test1   pass
test2   fail

Why am I not able to see the table borders?

user3865019
  • 45
  • 1
  • 6

1 Answers1

2

Hope this isn't too late! Just ran in to this issue myself and in my searching found this question and found the solution here (example #3).

In this case, where you are have the command

code = t.get_html_string()

Change it to

code = t.get_html_string(attributes={'border': 1, 'style': 'border-width: 1px; border-collapse: collapse;'})

Once that is changed, the borders should be added in the HTML.

Ben G
  • 21
  • 3
  • 1
    Can you please add a affiliation disclosure for the link you posted? – Ekadh Singh - Reinstate Monica Oct 07 '21 at 16:10
  • 1
    @EkadhSingh-ReinstateMonica I did not know about affiliation disclosure, but I have now edited the link to instead point to the official documentation on the subject. Let me know if there's a problem with that! – Ben G Oct 07 '21 at 17:19