Вопрос

I'm using JODReports to generate ODT files from templates. I want to fill a table with data so I used a JOOScript with Freemarker directives. Now I want to conditionally format each row depending on my data:

@table:table-row
[#list rows as row]
[#if row.bar = "ipsum"]
    [#assign rowcolor="#0000AA"]
[#else]
    [#assign rowcolor="#000000"]
[/#if]

@/table:table-row
[/#list]

@#table:table-cell
<What_Should_I_Put_Here_To_Color_The_Cell_Background_With_rowcolor?>

As you can see, if row.bar == "ipsum" I want the entire row be background-colored with #0000AA. Do you know a way (or an acceptable workaround) to achieve that?

Thank you.

Это было полезно?

Решение

We usually create table(say named MyStyleTable) in section and hide it. What we do with that table is set it's properties, for instance set background color for each cell, say A1 red, B1 green. And then assign appropriate MyStyleTable cell to your table(the one with data) cell properties:

@table:table-row
[#if row.bar = "ipsum"]
    [#assign rowcolor='MyStyleTable.A1']
[#else]
    [#assign rowcolor='MyStyleTable.B1']
[/#if]
@/table:table-row

@#table:table-cell 
table:style-name=${rowcolor}

I believe I've read there is a way to export style from contex.xml, and then assign style to whatever table or cell, but i haven't tried that.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top