I'm trying to make a table showing different values in each cell, and depending on the value of cell, have a different bgcolor
.
So I have managed to do this successfully with one column by using a simple loop, but I cannot figure out a way to do this with multiple columns holding the same pattern. I am not very experienced and any help is appreciate开发者_开发百科d.
import HTML
test_results = [
70,
50,
20,
5,
]
t = HTML.Table(header_row=['test'])
for new in sorted(test_results):
#print new
if new <=50:
color = 'yellow'
elif new <=100:
color = 'blue'
elif new <=150:
color = 'green'
elif new >150:
color = 'white'
colored_result = HTML.TableCell(new, bgcolor=color)
t.rows.append([colored_result])
htmlcode = str(t)
print htmlcode
This produces a single column table but I would like to add more data and have a table of many rows and columns.
This
t.rows.append([colored_result])
appends a complete row of one cell.
This
t.rows.append([colored_result, colored_result])
would append this cell twice, hence creating a row of 2 cells (identical).
This
colored_result = HTML.TableCell(new, bgcolor=color)
colored_result2 = HTML.TableCell(new, bgcolor='white')
t.rows.append([colored_result, colored_result2])
would append those two cells as a row in your table
精彩评论