Pyrevit.output table formatting

Hi, the kind of conttrol you need isn’t possible with the current implementation of the print_table method.
This is because it builds a markdown table that then gets converted to html, but markdown tables don’t have any control over the columns size.

One way to solve this would be create a new method to directly output the html table, and expose some parameter to let set fixed widths to each column.

Anyone wants to try to tackle this? If you’re not confident with git, you could just write a function and share it here.

It should be easy using string templates:

HEADER = '<th style="width:{width}">{title}</th>'
CELL = "<td>{}</td>"
ROW = "<tr>{}</tr>"
TABLE = "<table><theader>{}</theader><tbody>{}</tbody></table>"

def row(cells):
    return ROW.format("".join(cells))

headers = row(HEADER.format(**column) for column in header_config)
rows = "".join(row(CELL.format(data) for data in row_data) for row_data in table_data)
table = TABLE.format(headers, rows)
1 Like