use of org.docx4j.wml.TcPr in project Java-Tutorial by gpcodervn.
the class Docx4jUtils method setCellColor.
private void setCellColor(Tc tableCell, String color) {
if (color != null) {
TcPr tableCellProperties = tableCell.getTcPr();
if (tableCellProperties == null) {
tableCellProperties = new TcPr();
tableCell.setTcPr(tableCellProperties);
}
CTShd shd = new CTShd();
shd.setFill(color);
tableCellProperties.setShd(shd);
}
}
use of org.docx4j.wml.TcPr in project Java-Tutorial by gpcodervn.
the class NestedTable method main.
public static void main(String[] args) throws Exception {
System.out.println("Creating package..");
wordMLPackage = WordprocessingMLPackage.createPackage();
Tbl tblCredProg = factory.createTbl();
TblPr tblPr = new TblPr();
TblStyle tblStyle = new TblStyle();
tblStyle.setVal("TableGrid");
tblPr.setTblStyle(tblStyle);
tblCredProg.setTblPr(tblPr);
TblWidth width = new TblWidth();
width.setType("auto");
width.setW(new BigInteger("0"));
tblPr.setTblW(width);
// create row 1
Tr tr = factory.createTr();
// col 1 of row 1
addTc(tr, "A");
// col 2 of row 1
addTc(tr, "B");
tblCredProg.getEGContentRowContent().add(tr);
// create row 2
Tr tr2 = factory.createTr();
TrPr pr = new TrPr();
tr2.setTrPr(pr);
// col 1 of row 2
Tc tc1 = factory.createTc();
TcPr tcPr = new TcPr();
TblWidth widtha = new TblWidth();
widtha.setType("auto");
widtha.setW(new BigInteger("0"));
tcPr.setTcW(widtha);
tc1.setTcPr(tcPr);
tc1.getEGBlockLevelElts().add(XmlUtils.unmarshalString(tblXML));
// The following is important or you may get a corrupted docx file
tc1.getEGBlockLevelElts().add(wordMLPackage.getMainDocumentPart().createParagraphOfText(""));
tr2.getEGContentCellContent().add(tc1);
tblCredProg.getEGContentRowContent().add(tr2);
// col2 of row 2
addTc(tr2, "C");
wordMLPackage.getMainDocumentPart().addObject(tblCredProg);
// Now save it
wordMLPackage.save(new java.io.File("output/NestedTable.docx"));
System.out.println("Done.");
}
use of org.docx4j.wml.TcPr in project docx4j-template by vindell.
the class Docx4J_例子2 method createNormalCell.
public void createNormalCell(ObjectFactory factory, Tr tr, String content, RPr rpr, JcEnumeration jcEnumeration, boolean hasBgColor, String backgroudColor, boolean isHMerger, String mergeVal) {
Tc tableCell = factory.createTc();
P p = factory.createP();
setParagraphSpacing(factory, p, jcEnumeration, true, "0", "0", null, null, true, "240", STLineSpacingRule.AUTO);
Text t = factory.createText();
t.setValue(content);
R run = factory.createR();
// 设置表格内容字体样式
run.setRPr(rpr);
TcPr tcPr = tableCell.getTcPr();
if (tcPr == null) {
tcPr = factory.createTcPr();
}
CTVerticalJc valign = factory.createCTVerticalJc();
valign.setVal(STVerticalJc.CENTER);
tcPr.setVAlign(valign);
if (isHMerger) {
HMerge merge = new HMerge();
if (mergeVal != null) {
merge.setVal(mergeVal);
}
tcPr.setHMerge(merge);
} else {
VMerge merge = new VMerge();
if (mergeVal != null) {
merge.setVal(mergeVal);
}
tcPr.setVMerge(merge);
}
run.getContent().add(t);
p.getContent().add(run);
tableCell.getContent().add(p);
if (hasBgColor) {
CTShd shd = tcPr.getShd();
if (shd == null) {
shd = factory.createCTShd();
}
shd.setColor("auto");
shd.setFill(backgroudColor);
tcPr.setShd(shd);
}
tableCell.setTcPr(tcPr);
tr.getContent().add(tableCell);
}
use of org.docx4j.wml.TcPr in project docx4j-template by vindell.
the class Docx4jStyle_S3 method setCellColor.
public void setCellColor(Tc tableCell, String color) {
if (color != null) {
TcPr tableCellProperties = tableCell.getTcPr();
if (tableCellProperties == null) {
tableCellProperties = new TcPr();
tableCell.setTcPr(tableCellProperties);
}
CTShd shd = new CTShd();
shd.setFill(color);
tableCellProperties.setShd(shd);
}
}
use of org.docx4j.wml.TcPr in project docx4j-template by vindell.
the class Docx4jStyle_S3 method setCellBorders.
public void setCellBorders(Tc tableCell, boolean borderTop, boolean borderRight, boolean borderBottom, boolean borderLeft) {
TcPr tableCellProperties = tableCell.getTcPr();
if (tableCellProperties == null) {
tableCellProperties = new TcPr();
tableCell.setTcPr(tableCellProperties);
}
CTBorder border = new CTBorder();
// border.setColor("auto");
border.setColor("0000FF");
border.setSz(new BigInteger("20"));
border.setSpace(new BigInteger("0"));
border.setVal(STBorder.SINGLE);
TcBorders borders = new TcBorders();
if (borderBottom) {
borders.setBottom(border);
}
if (borderTop) {
borders.setTop(border);
}
if (borderLeft) {
borders.setLeft(border);
}
if (borderRight) {
borders.setRight(border);
}
tableCellProperties.setTcBorders(borders);
}
Aggregations