pytablewriter icon indicating copy to clipboard operation
pytablewriter copied to clipboard

Header cells ignore style

Open shawalli opened this issue 3 years ago • 2 comments

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 |

shawalli avatar Apr 12 '21 18:04 shawalli

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

shawalli avatar Apr 12 '21 18:04 shawalli

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.

thombashi avatar May 02 '21 10:05 thombashi

pytablewriter 1.2.0 or later can apply styles to headers by style filters.

thombashi avatar Oct 08 '23 13:10 thombashi