Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Table Cell should use the supplied style even if it's in a header row #956

Closed
tfenne opened this issue Oct 13, 2023 · 2 comments · Fixed by #979
Closed

Table Cell should use the supplied style even if it's in a header row #956

tfenne opened this issue Oct 13, 2023 · 2 comments · Fixed by #979

Comments

@tfenne
Copy link

tfenne commented Oct 13, 2023

Describe the bug:

I waffled on whether to call this a bug or feature request. I think it would be ideal to use the style provided when building a table Cell, if given, even when the cell is in a header row. As far as I can tell, the header style is always used. This makes it impossible (I think?) to have multiple header rows, but with different styles. I want to be able to do this because I want borders underneath each header line, but I want to style the two header rows differently.

Minimal code

from fpdf import FPDF

pdf = FPDF()
pdf.add_page()
pdf.set_font(family="helvetica", size=11)

with pdf.table(headings_style=FontFace("helvetica, "B", 16)) as table:
    table.row("Big Heading", col_span=2)
    second_header = table.row()
    second_header_style = FontFace("helvetica, "I", 13)
    second_header.cell("First", style=second_header_style)
    second_header.cell("Second", style=second_header_style)
    table.row(("Some", "Data"))

Environment
Please provide the following information:

  • Operating System: Mac OSX
  • Python version: 3.10.6
  • fpdf2 version used: 2.7.6
@gmischler
Copy link
Collaborator

Welcome @tfenne,

Thanks for this enhancement suggestion. (I've removed the "bug" label, since it currently seems to be working as documented.)

The possibility to have multiple header lines was just recently added, and the formatting method has not been updated at that point.
I agree that your suggestion would make a lot of sense. If the style supplied to an individual cell always overrides the more general settings, then that gives the user additional and more flexible options. Varying eg. the background color of heading cells depending on row and/or column can be quite helpful in terms of readability.

If you think you're up to it, you're welcome to submit a PR with a fix.

@tfenne
Copy link
Author

tfenne commented Oct 15, 2023

Thanks @gmischler I'd be happy to at least attempt a PR for this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants