jxls

JXLS: Colorize a line dependent on the expressions content


I'm a beginner with JXLS. I read the Documentation for formulas but am stuck.

Let's take their example with the employees: enter image description here

I want to colorize the entire row in green, when an employee is earns more than 2000 Dollars (column "payment", variable "employee.payment").

In the documentations example: enter image description here

I would want to have row 5, 6 and 8 colorized in green.

Is this possible? If yes, how? Using the comment commands? Or do I need java code? I don't have code to show as it is quite big and not from me, so I'm not perfectly familiar with it. So for the sake of the issue, we can look at the documentaries code. Mine is similar to that.

Area xlsArea;
Context context;
// construct XLS Area and set it into xlsArea var
// ...
// fill in context var with data
// ...
// apply XLS Area at A1 cell of 'Result' sheet
xlsArea.applyAt(new CellRef("Result!A1"), context);
// process area formulas
xlsArea.processFormulas();
// save excel output
// ...

EDIT:

Based on Leonids suggestion using the if-else construct, I now got this working by putting an extra "cheat line" underneath, which has the desired color:

enter image description here

but I am facing one problem now: looking at the employees example, I could have 10 of them, but also 1000 - I simply don't know, the data comes dynamically. So then this happens:

enter image description here

My "cheat line" appears at line 23. That's a problem ....... As I could have 1 million employees, I can't put it just far enough underneath, that line could always appear in the result when having too much data.


Solution

  • There are two main ways how you can achieve row highlighting in Jxls-2.

    One is to use if-command and another one is to use AreaListener.

    You can find an example of using if-command for row highlighting in EachIfCommandDemo in jxls-demo project.

    You can find an example of using AreaListener for cell highlighting in AreaListenerDemo.