[reportlab-users] Format cells inside table

Andy Robinson andy at reportlab.com
Tue Aug 18 07:03:17 EDT 2015


Hi Jakob,

That's true, it's based on positions.

In Report Markup Language, we allow things like
  <td textColor="green">99</td>
but we implemented it by scanning the markup and generating extra
table style commands for that particular table as we parsed the input.

Your best bet would be to write a function which looks at the data and
generates a new table style, based on the original one but adding
extra block commands to colour each cell that needs colouring.  It
could be quite short and reusable.  If it's not clear what to do, one
of us could try to help in the next few days.

- Andy




On 18 August 2015 at 09:23, Jakob Damgaard Møller <jakobdo at gmail.com> wrote:
> Hello, this is my first post to this list, so i hope i do it right.
>
> I try to create a table in reportlab.
>
> data = [
>   ['Firstname', 'Lastname', 'Points'],
>   ['Jakob', 'Møller', '5'],
>   ['Anna', 'Møller', '10'],
> etc...
> ]
>
> I want to format cell in colors based on result.
> F.ex:
> if points > 5:
>   cell_color = "green"
> elif point < 5:
>   cell_color = "red"
> else:
>   cell_color = "yellow"
>
> I have looked at this:
> http://www.blog.pythonlibrary.org/2010/09/21/reportlab-tables-creating-tables-in-pdfs-with-python/
> But as i understand it, the color is defined on coordinates. Cant i assign a
> color when i create "data" ?
>
> _______________________________________________
> reportlab-users mailing list
> reportlab-users at lists2.reportlab.com
> https://pairlist2.pair.net/mailman/listinfo/reportlab-users
>


More information about the reportlab-users mailing list