Page 1 of 1

How to change table cell background color

PostPosted: Mon Jun 29, 2015 9:13 pm
by tariq
I’m using docx4j 3.2.1, so I can change table cell background color ?

Re: How to change table cell background color

PostPosted: Tue Jul 21, 2015 2:43 pm
by jason
From a sample docx uploaded to the docx4j webapp, you can see:

Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
                        <w:tc>
                            <w:tcPr>
                                <w:shd w:val="clear" w:color="auto" w:fill="B8CCE4" w:themeFill="accent1" w:themeFillTint="66"/>
 
Parsed in 0.000 seconds, using GeSHi 1.0.8.4



Code: Select all
Generating this object

Method 1: via ObjectFactory

import org.docx4j.wml.CTShd;


public class Foo {
public CTShd createIt() {

org.docx4j.wml.ObjectFactory wmlObjectFactory = new org.docx4j.wml.ObjectFactory();

CTShd shd = wmlObjectFactory.createCTShd();
    shd.setVal(org.docx4j.wml.STShd.CLEAR);
    shd.setColor( "auto");
    shd.setFill( "B8CCE4");
    shd.setThemeFill(org.docx4j.wml.STThemeColor.ACCENT_1);
    shd.setThemeFillTint( "66");

return shd;
}
}
Method 2

String openXML = "<w:shd w:color=\"auto\" w:fill=\"B8CCE4\" w:themeFill=\"accent1\" w:themeFillTint=\"66\" w:val=\"clear\"/ xmlns:w=\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\">";
CTShd shd = (CTShd)XmlUtils.unmarshalString(openXML);


and documentation http://webapp.docx4java.org/OnlineDemo/ ... shd_3.html

Re: How to change table cell background color

PostPosted: Mon Jul 27, 2015 11:25 pm
by tariq
Thank alot jason....