Page 1 of 1

how to fill table header cell color

PostPosted: Mon Feb 10, 2014 11:33 pm
by rrr
can any one tell me please how to fill table header cell with color with java code

thanks in advance...

Re: how to fill table header cell color

PostPosted: Tue Feb 11, 2014 6:39 am
by jason
The webapp (linked in the menu above) is your friend.

Here's what it generated for me when I uploaded a docx with a coloured header row ... the colour is a table cell property ..

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
import java.math.BigInteger;
import org.docx4j.wml.CTShd;
import org.docx4j.wml.P;
import org.docx4j.wml.TblWidth;
import org.docx4j.wml.Tc;
import org.docx4j.wml.TcPr;


public class Foo {
public JAXBElement createIt() {

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

Tc tc = wmlObjectFactory.createTc();
JAXBElement<org.docx4j.wml.Tc> tcWrapped = wmlObjectFactory.createCTSdtContentCellTc(tc);
    // Create object for tcPr
    TcPr tcpr = wmlObjectFactory.createTcPr();
    tc.setTcPr(tcpr);
        // Create object for tcW
        TblWidth tblwidth = wmlObjectFactory.createTblWidth();
        tcpr.setTcW(tblwidth);
            tblwidth.setType( "dxa");
            tblwidth.setW( BigInteger.valueOf( 4788) );
        // Create object for shd
        CTShd shd = wmlObjectFactory.createCTShd();
        tcpr.setShd(shd);
            shd.setVal(org.docx4j.wml.STShd.CLEAR);
            shd.setColor( "auto");
            shd.setFill( "FFFF00");
    // Create object for p
    P p = wmlObjectFactory.createP();
    tc.getContent().add( p);

return tcWrapped;
}
}

 
Parsed in 0.017 seconds, using GeSHi 1.0.8.4


I'll leave it as an exercise for you to adapt the method so you pass in the tc and the color.

Re: how to fill table header cell color

PostPosted: Tue Feb 11, 2014 11:09 pm
by rrr
thank you very much for your reply..

issue is solved.. :D :D

Re: how to fill table header cell color

PostPosted: Tue Feb 11, 2014 11:15 pm
by rrr
but i have one doubt in previous header cell color code:
i.e.,

Code: Select all
tblwidth.setType( "dxa");
            tblwidth.setW( BigInteger.valueOf( 4788) );


what is setType("dxa") and what is 4788 in this code ??

please provide solution..

Re: how to fill table header cell color

PostPosted: Wed Feb 12, 2014 9:27 am
by jason
The online webapp also provides documentation, both for the specific element you clicked on, or via http://webapp.docx4java.org/OnlineDemo/ ... index.html

Please use that as a starting point, and at least post a link to the relevant page before asking a question (showing you've made at least a minimal effort to help yourself).

Re: how to fill table header cell color

PostPosted: Wed Feb 12, 2014 11:11 pm
by rrr
i didnt get why "dxa" only written, if i write anything instead of dxa, i'm not getting proper result,

Code: Select all
tblwidth.setType( "dxa");
                tblwidth.setW( BigInteger.valueOf( 4788) );


I didnt understand what i have to do after click on the webapp(which is their on the menubar)

please tell me clearly..
thanks in advance..