pytablewriter
pytablewriter copied to clipboard
Header cells ignore style
It appears that the header row discards the column_styles
value. I also tried forcing a style via add_style_filter
(see snippet below), but it was ignored. I ran into this on MarkdownTableWriter
, but based on the code, I think it affects the base text writer (and subclassed writers) as well.
def force_header_style(cell, **kwargs):
if cell.row == -1:
return None
return Style(align="left", font_weight="bold")
writer = MarkdownTableWriter(
headers=["a", "b", "c"],
margin=1,
value_matrix = [
["foo bar", "bar bax", "baz qux"],
].
)
writer.add_style_filter(force_header_style)
print(writer.dumps())
Expected Output:
| **a** | **b** | **c** |
| :------ | :------ | :------ |
| foo bar | bar baz | baz qux |
Actual Output
| a | b | c |
| :------ | :------ | :------ |
| foo bar | bar baz | baz qux |
I tried to dig in to figure out where this was happening in the code, but I got a bit confused when trying to trace the writing code
Thank you for your feedback.
In the current implementation, no styles other than colors are applied to headers. In a future version, other styles might also be applicable to headers.
pytablewriter 1.2.0
or later can apply styles to headers by style filters.