Re: Format cells inside table

Andy Robinson <[email protected]>
Newsgroups gmane.comp.python.reportlab.user
Message-ID <CABjtApvhsafT1eMhbe5o5_BTfk_7Eyj-RsW=L==9tJP+cv70QA@mail.gmail.com>
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 <[email protected]> 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
> [email protected]
> https://pairlist2.pair.net/mailman/listinfo/reportlab-users
>
_______________________________________________
reportlab-users mailing list
[email protected]
https://pairlist2.pair.net/mailman/listinfo/reportlab-users
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.