Page 1 of 1

dynamic coloring cell and row

PostPosted: Fri Aug 11, 2017 6:03 am
by prakhar211
Hi Jason,

Could you please provide sample code for the below questions

1. I have a table and i want to color rows in the table based on the value of one cell in that row. Please refer 1st table in the attached document.
Column4 value true should make row1 to appear in one color and value false makes it appear in different color.
First 2 column are static and present in the word template and the 3rd and 4th column added using docx4j api.

2. I want to fill color in one cell based on the value in that cell. If the column4 has value less than 5 then highlight that cell with different color. Please refer 2nd table in the attached document.

Re: dynamic coloring cell and row

PostPosted: Fri Aug 11, 2017 8:41 pm
by jason
prakhar211 wrote:Could you please provide sample code for the below questions


Sorry, no. I support docx4j, but you are presumably paid a salary to write code. Similar to StackOverflow, after you've written some code, I can provide some help if you are still having problems.

For both your questions, you need to test the column 4 value, and then set appropriate row or cell properties. Look at the OpenXML of a suitably formatted table to understand what you need to set. You can generate corresponding code.

Re: dynamic coloring cell and row

PostPosted: Mon Aug 21, 2017 11:23 pm
by prakhar211
Hi Jason,

Actually the way i put my question may not be right but i have tried things and since those didn't work i thought of taking some suggestion.

Anyway i achieved these two cases.

I am having issues setting the text/font color for the data in the table cell.

CTShd ctShd = Context.getWmlObjectFactory().createCTShd();
ctShd.setColor("FFFFFF");
ctShd.setFill("yellow");
TcPr tcPr = new TcPr();
tcPr.setShd(ctShd);

setcolor have no effect. Please suggest how can i set text color.

Re: dynamic coloring cell and row

PostPosted: Tue Aug 22, 2017 8:40 am
by jason
Assuming CTShd is the correct property (I haven't checked), the obvious thing to check first: did you set TcPr on the Tc to your tcPr?

Re: dynamic coloring cell and row

PostPosted: Tue Aug 22, 2017 2:12 pm
by prakhar211
Yes, i set tcpr on tc. Doesn't seem to work.

Re: dynamic coloring cell and row

PostPosted: Tue Aug 22, 2017 10:21 pm
by jason
It will work if you do it right.

To figure out where you are going wrong, compare your XML (ie marshall your JAXB, or just save the docx) to what you find in a suitable Word docx, then correct yours to match.