Java Code Examples for org.docx4j.wml.TcPr#setVMerge()

The following examples show how to use org.docx4j.wml.TcPr#setVMerge() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TableWithMergedCells.java    From docx4j-template with Apache License 2.0 8 votes vote down vote up
/**
 *  我们创建一个单元格和单元格属性对象.
 *  也创建了一个纵向合并对象. 如果合并值不为null, 将它设置到合并对象中. 然后将该对象添加到
 *  单元格属性并将属性添加到单元格中. 最后设置单元格内容并将单元格添加到行中.
 *  
 *  如果合并值为'restart', 表明要开始一个新行. 如果为null, 继续按前面的行处理, 也就是合并单元格.
 */
private static 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(
            wordMLPackage.getMainDocumentPart().
                createParagraphOfText(content));
    }
 
    row.getContent().add(tableCell);
}
 
Example 2
Source File: WmlElementUtils.java    From docx4j-template with Apache License 2.0 6 votes vote down vote up
/**
 * @Description: 跨行合并
 */
public static void mergeCellsVertically(Tbl tbl, int col, int fromRow, int toRow) {
    if (col < 0 || fromRow < 0 || toRow < 0) {
        return;
    }
    for (int rowIndex = fromRow; rowIndex <= toRow; rowIndex++) {
        Tc tc = getTc(tbl, rowIndex, col);
        if (tc == null) {
            break;
        }
        TcPr tcPr = getTcPr(tc);
        VMerge vMerge = tcPr.getVMerge();
        if (vMerge == null) {
            vMerge = new VMerge();
            tcPr.setVMerge(vMerge);
        }
        if (rowIndex == fromRow) {
            vMerge.setVal("restart");
        } else {
            vMerge.setVal("continue");
        }
    }
}
 
Example 3
Source File: WordprocessingMLPackageRender.java    From docx4j-template with Apache License 2.0 6 votes vote down vote up
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);  
}
 
Example 4
Source File: Docx4j_工具类_S3_Test.java    From docx4j-template with Apache License 2.0 6 votes vote down vote up
/**
 * @Description: 跨行合并
 */
public void mergeCellsVertically(Tbl tbl, int col, int fromRow, int toRow) {
    if (col < 0 || fromRow < 0 || toRow < 0) {
        return;
    }
    for (int rowIndex = fromRow; rowIndex <= toRow; rowIndex++) {
        Tc tc = getTc(tbl, rowIndex, col);
        if (tc == null) {
            break;
        }
        TcPr tcPr = getTcPr(tc);
        VMerge vMerge = tcPr.getVMerge();
        if (vMerge == null) {
            vMerge = new VMerge();
            tcPr.setVMerge(vMerge);
        }
        if (rowIndex == fromRow) {
            vMerge.setVal("restart");
        } else {
            vMerge.setVal("continue");
        }
    }
}
 
Example 5
Source File: Docx4j_替换模板.java    From docx4j-template with Apache License 2.0 6 votes vote down vote up
/** 
 * @Description: 跨行合并 
 */  
public static void mergeCellsVertically(Tbl tbl, int col, int fromRow, int toRow) {  
    if (col < 0 || fromRow < 0 || toRow < 0) {  
        return;  
    }  
    for (int rowIndex = fromRow; rowIndex <= toRow; rowIndex++) {  
        Tc tc = getTc(tbl, rowIndex, col);  
        if (tc == null) {  
            break;  
        }  
        TcPr tcPr = getTcPr(tc);  
        VMerge vMerge = tcPr.getVMerge();  
        if (vMerge == null) {  
            vMerge = factory.createTcPrInnerVMerge();  
            tcPr.setVMerge(vMerge);  
        }  
        if (rowIndex == fromRow) {  
            vMerge.setVal("restart");  
        } else {  
            vMerge.setVal("continue");  
        }  
    }  
}
 
Example 6
Source File: Docx4j_合并单元格_S4_Test.java    From docx4j-template with Apache License 2.0 6 votes vote down vote up
/** 
 * @Description: 跨行合并 
 */  
public void mergeCellsVertically(Tbl tbl, int col, int fromRow, int toRow) {  
    if (col < 0 || fromRow < 0 || toRow < 0) {  
        return;  
    }  
    for (int rowIndex = fromRow; rowIndex <= toRow; rowIndex++) {  
        Tc tc = getTc(tbl, rowIndex, col);  
        if (tc == null) {  
            break;  
        }  
        TcPr tcPr = getTcPr(tc);  
        VMerge vMerge = tcPr.getVMerge();  
        if (vMerge == null) {  
            vMerge = new VMerge();  
            tcPr.setVMerge(vMerge);  
        }  
        if (rowIndex == fromRow) {  
            vMerge.setVal("restart");  
        } else {  
            vMerge.setVal("continue");  
        }  
    }  
}
 
Example 7
Source File: DocxBuilder.java    From TranskribusCore with GNU General Public License v3.0 6 votes vote down vote up
private void applyGridSpan( final Tc cell, final int colSpan, final String rowSpan, int w, boolean mergedVertical ) {
	
    TcPr tcPr = factory.createTcPr();
    TblWidth tblWidth = factory.createTblWidth();
    tblWidth.setType( "dxa" );
    tblWidth.setW( BigInteger.valueOf( w*colSpan ) );
    tcPr.setTcW( tblWidth  );
    
    if ( colSpan > 1) {
        GridSpan gridSpan = factory.createTcPrInnerGridSpan();
        gridSpan.setVal(BigInteger.valueOf(colSpan));
        tcPr.setGridSpan(gridSpan);
    }
    
    if ( mergedVertical ) {
    	//logger.debug(" this is vertical span");
    	VMerge gridVSpan = factory.createTcPrInnerVMerge();
    	if (rowSpan != null)
    		gridVSpan.setVal(rowSpan);
        tcPr.setVMerge(gridVSpan);
                    
    }
   
    cell.setTcPr(tcPr);
}