How to change table cell background color
Posted: Mon Jun 29, 2015 9:13 pm
I’m using docx4j 3.2.1, so I can change table cell background color ?
forums
https://www.docx4java.org/forums/
https://www.docx4java.org/forums/docx-java-f6/how-to-change-table-cell-background-color-t2206.html
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);