Removing column with jxls

2.9k views Asked by At

I am using JXLS to populate a template excel spreadsheet. I have a configuration file with defines with columns shall be included in export. I found on this homepage http://jxls.sourceforge.net/reference/tags.html the possibility to use the jx:if tag, but if I use it like this (with "<", "/>")

              A                               |     B                | C     | D | E 
jx:if test="${columnheader.b != DISABLED}"    | ${columnheader.b}    | jx:if | d | e
                                              |  b                   |       |   |

the result is

               A                               |     B                | C     | D | E 
               d                               |     e                |       |   |
                                               |     b                |       |   |

but I would like

               A                      |     B                | C     | D | E 
               d                      |     e                |       |   |
                                      |                      |       |   |

I can use the if-Tag for every cell in the column, then it works. But I also want to use if-Tags to remove rows (like this Remove template row in JXLS when input list is empty) and then it doesn't work since I have an end if-Tag in the column.

Also I found the method xlsTransformer.setColumnPropertyNamesToHide(..), but it only hides the column and does not remove them.

I would be very thankful for some help.

1

There are 1 answers

0
dchang On

Picking your example, you can do this:

                A                               |     B                | C     | D | E 
1 jx:if test="${line something...}"             |                      |       |   |  
2 jx:if test="${columnheader.b != DISABLED}"    | ${columnheader.b}    | jx:if | d | e
3 jx:if                                         |                      |       |   |  
4 jx:if test="${columnheader.b != DISABLED}"    |     b                | jx:if |   | 

That is, you put the if-tags for all column, and for the rows that you want to check, do it at the line before and after.

Note that:

  • when you place a If-tag for a row, the rows where you place the jx:if tags will always disappear (independently if the condition is true or false). At the example the cells A1, B1, C1, D1, E1 and A3, B3, C3, D3, E3 will always disappear.

  • when you place a If-tag for a column, the cell where you place the jx:if tags will always disappear. At the example, cells A2, C2 and A4, C4 will always disappear.