Page 1 of 1

How to customize a cell's borders

PostPosted: Thu Apr 18, 2013 1:03 pm
by lazywednesday
i have a table that should have a singel cell with a border so i tried using the TcBorders, CTBorder, and STBorder to set a TcPr (table cell property) to a cell. so i made a table and made a cell and set a border on it. but it didnt work. what might be the problem? and how do you properly set a border or set a border to none in case you put a border to a table? here's a sample code for the cell that is supposed to have a border.

Code: Select all
Tc tcTAF = factory.createTc();
TcPr sample = new TcPr();
TcBorders tcb = factory.createTcPrInnerTcBorders();
CTBorder ctb = factory.createCTBorder();
STBorder stb = STBorder.SINGLE;
ctb.setVal(stb);
tcb.setBottom(ctb);
tcb.setRight(ctb);
tcb.setLeft(ctb);
tcb.setTop(ctb);
sample.setTcBorders(tcb);
tcTAF.setTcPr(sample);
setGrid(tcTAF, 3, factory);
tcTAF.getContent().add(
wordMLPackage.getMainDocumentPart().createParagraphOfText("sample cell with a border "));


i have set a table and other cells normally. the overall code runs well but the borders of this cell doesnt show.

Re: How to customize a cell's borders

PostPosted: Thu Apr 18, 2013 2:37 pm
by jason
What XML does your code produce? Try XmlUtils.marshaltoString and compare this to what Word produces (unzip a docx and look at document.xml)

Have a look at the spec, or at least the "Open XML Explained" free PDF by Wouter Van Vugt which contains a page on this.

Once you know what XML you are trying to produce, please feel free to post again if you are having difficulty getting the code right.

Re: How to customize a cell's borders

PostPosted: Thu Apr 18, 2013 4:32 pm
by lazywednesday
it works fine now. and i learned how to unzip a document and see the xml content. turns out that i set another tcpr to the table cell so the tcpr with the set table borders was replaced. thank you and sorry for the inconvenience. you can delete this topic for i think this will not help other users. or should i delete this? btw thanks again and more power to docx4j