use of org.docx4j.wml.Tc in project docx4j-template by vindell.
the class WordprocessingMLPackageRender method addMergedCell.
/**
* 我们创建一个单元格和单元格属性对象.
* 也创建了一个纵向合并对象. 如果合并值不为null, 将它设置到合并对象中. 然后将该对象添加到
* 单元格属性并将属性添加到单元格中. 最后设置单元格内容并将单元格添加到行中.
* 如果合并值为'restart', 表明要开始一个新行. 如果为null, 继续按前面的行处理, 也就是合并单元格.
*/
public void addMergedCell(Tr row, String content, String vMergeVal) {
Tc tableCell = factory.createTc();
TcPr tableCellProperties = new TcPr();
VMerge merge = new VMerge();
if (vMergeVal != null) {
merge.setVal(vMergeVal);
}
tableCellProperties.setVMerge(merge);
tableCell.setTcPr(tableCellProperties);
if (content != null) {
tableCell.getContent().add(wmlPackage.getMainDocumentPart().createParagraphOfText(content));
}
row.getContent().add(tableCell);
}
use of org.docx4j.wml.Tc in project docx4j-template by vindell.
the class AddingATable method addTableCell.
private static void addTableCell(Tr tableRow, String content) {
Tc tableCell = factory.createTc();
tableCell.getContent().add(wordMLPackage.getMainDocumentPart().createParagraphOfText(content));
tableRow.getContent().add(tableCell);
}
use of org.docx4j.wml.Tc in project docx4j-template by vindell.
the class DocxElementWmlRender method newCell.
public Tc newCell(Tbl table, int row, String content) {
Tc tbCell = factory.createTc();
tbCell.getContent().add(newParagraph(content));
getRow(table, row).getContent().add(tbCell);
return tbCell;
}
use of org.docx4j.wml.Tc in project TranskribusCore by Transkribus.
the class DocxBuilder method getDocxTable.
private static Tbl getDocxTable(WordprocessingMLPackage wPMLpackage, boolean isWordBased, int rows, int cols, List<HashMap<Integer, TrpTableCellType>> allRows, int tablesize, MainDocumentPart mdp) throws Exception {
int writableWidthTwips = wPMLpackage.getDocumentModel().getSections().get(0).getPageDimensions().getWritableWidthTwips();
int cellWidthTwips = new Double(Math.floor((writableWidthTwips / cols))).intValue();
Tbl table = TblFactory.createTable(0, 0, cellWidthTwips);
TblGrid tblGrid = factory.createTblGrid();
for (int i = 0; i < cols; i++) {
TblGridCol col = factory.createTblGridCol();
col.setW(BigInteger.valueOf(cellWidthTwips));
tblGrid.getGridCol().add(col);
}
table.setTblGrid(tblGrid);
int i = 0;
for (HashMap<Integer, TrpTableCellType> entry : allRows) {
Tr row = factory.createTr();
table.getContent().add(row);
i++;
int d = 0;
if (entry.keySet().size() != cols) {
logger.debug("size of entries does not match columns ");
}
for (Integer key : entry.keySet()) {
Tc cell = factory.createTc();
row.getContent().add(cell);
String rowSpan = null;
int colSpan = 1;
boolean mergedVertical = false;
int colsize = cellWidthTwips;
if (entry.get(key) != null) {
if (entry.get(key).getRowSpan() > 1) {
mergedVertical = true;
rowSpan = "restart";
}
// PageXmlUtils.buildPolygon(entry.get(key).getCoords().getPoints()).getBounds().getMaxX();
double maxX = entry.get(key).getBoundingBox().getMaxX();
// PageXmlUtils.buildPolygon(entry.get(key).getCoords().getPoints()).getBounds().getMinX();
double minX = entry.get(key).getBoundingBox().getMinX();
double colsizeRel = maxX - minX;
double colsizetmp = colsizeRel / (double) tablesize;
// logger.debug("colsizetmp " + colsizetmp);
colsize = (int) (writableWidthTwips * colsizetmp);
colSpan = entry.get(key).getColSpan();
// logger.debug("colsize " + colsize);
// logger.debug("text in this cell is " + entry.get(key).getUnicodeTextFromLines());
int colID = entry.get(key).getCol();
int rowID = entry.get(key).getRow();
} else {
// logger.debug("no cell for this column ");
mergedVertical = true;
}
applyGridSpan(cell, colSpan, rowSpan, colsize, mergedVertical);
P columnPara = factory.createP();
// P columnPara = (P) column.getContent().get(0);
cell.getContent().add(columnPara);
d++;
Text tx = factory.createText();
R run = factory.createR();
if (entry.get(key) != null) {
// old solution till now: tx.setValue(entry.get(key).getUnicodeTextFromLines());
if (entry.get(key).getUnicodeTextFromLines() != "") {
exportTextRegion(entry.get(key), isWordBased, columnPara, mdp);
}
}
run.getContent().add(tx);
columnPara.getContent().add(run);
}
}
return table;
}
use of org.docx4j.wml.Tc in project mdw-designer by CenturyLinkCloud.
the class DocxBuilder method addTable.
public Tbl addTable(String[] headers, String[][] values, int fontSize, int indent) {
ObjectFactory factory = Context.getWmlObjectFactory();
int writableWidthTwips = wordMLPackage.getDocumentModel().getSections().get(0).getPageDimensions().getWritableWidthTwips();
int cols = headers.length;
int cellWidthTwips = new Double(Math.floor((writableWidthTwips / cols))).intValue();
Tbl tbl = TblFactory.createTable(0, cols, cellWidthTwips);
Tr thead = factory.createTr();
for (int i = 0; i < headers.length; i++) {
Tc tc = factory.createTc();
tc.getContent().add(createParagraph(headers[i], fontSize, true));
thead.getContent().add(tc);
}
tbl.getContent().add(0, thead);
for (int i = 0; i < values[0].length; i++) {
Tr tr = factory.createTr();
for (int j = 0; j < headers.length; j++) {
Tc tc = factory.createTc();
tc.getContent().add(createParagraph(values[j][i], fontSize, false));
tr.getContent().add(tc);
}
tbl.getContent().add(i + 1, tr);
}
getMdp().addObject(tbl);
if (indent != 0) {
TblPr tblPr = tbl.getTblPr();
TblWidth tblIndent = factory.createTblWidth();
tblIndent.setType("dxa");
tblIndent.setW(BigInteger.valueOf(indent));
tblPr.setTblInd(tblIndent);
}
return tbl;
}
Aggregations