org.openxmlformats.schemas.wordprocessingml.x2006.main.CTTcPr Java Examples

The following examples show how to use org.openxmlformats.schemas.wordprocessingml.x2006.main.CTTcPr. 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: WordDocxTableParser.java    From SnowGraph with Apache License 2.0 6 votes vote down vote up
private static int getGridSpan(XWPFTableCell cell) {
    if (cell == null)
        return -1;
    CTTcPr tcPr = cell.getCTTc().getTcPr();

    if (tcPr == null)
        return 1;

    CTDecimalNumber number = tcPr.getGridSpan();

    if (number == null) {
        return 1;
    }
    else {
        return number.getVal().intValue();
    }
}
 
Example #2
Source File: TableTools.java    From poi-tl with Apache License 2.0 6 votes vote down vote up
/**
 * 合并列单元格
 * 
 * @param table
 *            表格对象
 * @param col
 *            列 从0开始
 * @param fromRow
 *            起始行
 * @param toRow
 *            结束行
 */
public static void mergeCellsVertically(XWPFTable table, int col, int fromRow, int toRow) {
    if (toRow <= fromRow) return;
    for (int rowIndex = fromRow; rowIndex <= toRow; rowIndex++) {
        XWPFTableCell cell = table.getRow(rowIndex).getCell(col);
        CTTcPr tcPr = getTcPr(cell);
        CTVMerge vMerge = tcPr.addNewVMerge();
        if (rowIndex == fromRow) {
            // The first merged cell is set with RESTART merge value
            vMerge.setVal(STMerge.RESTART);
        } else {
            // Cells which join (merge) the first one, are set with CONTINUE
            vMerge.setVal(STMerge.CONTINUE);
        }
    }
}
 
Example #3
Source File: WordProducer.java    From ureport with Apache License 2.0 5 votes vote down vote up
private void buildCellBorder(Border border, XWPFTableCell tableCell,int type) {
	CTTcPr cellPropertie = tableCell.getCTTc().getTcPr();
	if(cellPropertie==null){
		cellPropertie=tableCell.getCTTc().addNewTcPr();
	}
	CTTcBorders borders=cellPropertie.getTcBorders();
	if(borders==null){
		borders=cellPropertie.addNewTcBorders();;
	}
	BorderStyle borderStyle=border.getStyle();
	CTBorder ctborder=null;
	if(type==1){
		ctborder=borders.addNewLeft();
	}else if(type==2){
		ctborder=borders.addNewRight();
	}else if(type==3){
		ctborder=borders.addNewTop();
	}else if(type==4){
		ctborder=borders.addNewBottom();
	}
	if(borderStyle.equals(BorderStyle.dashed)){
		ctborder.setVal(STBorder.DASHED);
	}else if(borderStyle.equals(BorderStyle.doublesolid)){
		ctborder.setVal(STBorder.DOUBLE);
	}else{
		ctborder.setVal(STBorder.SINGLE);				
	}
	int borderWidth=border.getWidth();
	if(borderWidth>1){
		ctborder.setSz(BigInteger.valueOf(DxaUtils.points2dxa(borderWidth)));				
	}
	String color=border.getColor();
	if(StringUtils.isNotBlank(color)){
		ctborder.setColor(toHex(color.split(",")));
	}
}
 
Example #4
Source File: WordDocxTableParser.java    From SnowGraph with Apache License 2.0 5 votes vote down vote up
private static boolean isVMerge(XWPFTableCell cell) {
    if (cell == null)
        return false;
    CTTcPr tcPr = cell.getCTTc().getTcPr();
    if (tcPr == null)
        return false;

    return tcPr.isSetVMerge();
}
 
Example #5
Source File: WordDocxTableParser.java    From SnowGraph with Apache License 2.0 5 votes vote down vote up
private static boolean isVMergeRestart(XWPFTableCell cell) {
    if (cell == null)
        return false;
    CTTcPr tcPr = cell.getCTTc().getTcPr();
    if (tcPr == null || !tcPr.isSetVMerge())
        return false;

    // 如果不判断isVMerge,会getVMerge==null? NullException Alert!
    return (tcPr.getVMerge().getVal() == STMerge.RESTART);
}
 
Example #6
Source File: TableTools.java    From poi-tl with Apache License 2.0 5 votes vote down vote up
/**
 * 合并行单元格
 * 
 * @param table
 *            表格对象
 * @param row
 *            行 从0开始
 * @param fromCol
 *            起始列
 * @param toCol
 *            结束列
 */
public static void mergeCellsHorizonal(XWPFTable table, int row, int fromCol, int toCol) {
    if (toCol <= fromCol) return;
    XWPFTableCell cell = table.getRow(row).getCell(fromCol);
    CTTcPr tcPr = getTcPr(cell);
    XWPFTableRow rowTable = table.getRow(row);
    for (int colIndex = fromCol + 1; colIndex <= toCol; colIndex++) {
        rowTable.getCtRow().removeTc(fromCol + 1);
        rowTable.removeCell(fromCol + 1);
    }

    tcPr.addNewGridSpan();
    tcPr.getGridSpan().setVal(BigInteger.valueOf((long) (toCol - fromCol + 1)));
}
 
Example #7
Source File: SingleWordXTableParser.java    From sun-wordtable-read with Apache License 2.0 4 votes vote down vote up
/**
 * 解析Docx的表格,将表格相关数据映射到表格映射对象中, 用于后面的操作
 * @return
 */
public WordTable parse() {
	List<XWPFTableRow> rows;
	List<XWPFTableCell> cells;

	rows = xwpfTable.getRows();
	int realMaxRowCount = rows.size();
	//		table.setRealMaxRowCount(rows.size());

	//计算最大列数
	int realMaxColumnCount = 0;
	for (XWPFTableRow row : rows) {
		//获取行对应的单元格  
		cells = row.getTableCells();
		int _columnCountOnRow = 0;
		for (XWPFTableCell cell : cells) {
			CTTcPr tt = cell.getCTTc().getTcPr();
			if(tt.getGridSpan()!=null) {
				_columnCountOnRow += tt.getGridSpan().getVal().intValue();
			} else {
				_columnCountOnRow += 1;
			}
		}
		
		if (_columnCountOnRow > realMaxColumnCount) {
			realMaxColumnCount = _columnCountOnRow;
		}
	}

	//table.setRealMaxColumnCount(columnCount);

	_tableMemoryMapping = new WordTableMemoryMapping(realMaxRowCount, realMaxColumnCount);
	_tableMemoryMapping.setVisitor(context.getVisitor());
	for (int i = 0; i < realMaxRowCount; i++) {
		parseRow(rows.get(i), i);
	}

	//printTableMemoryMap();

	//		wordTableMap = new WordTableMap();
	//		wordTableMap.setTableMemoryMap(_tableMemoryMap);
	return context.transfer(_tableMemoryMapping);
}
 
Example #8
Source File: TableTools.java    From poi-tl with Apache License 2.0 4 votes vote down vote up
private static CTTcPr getTcPr(XWPFTableCell cell) {
    CTTcPr tcPr = cell.getCTTc().isSetTcPr() ? cell.getCTTc().getTcPr()
            : cell.getCTTc().addNewTcPr();
    return tcPr;
}