org.apache.poi.xwpf.usermodel.XWPFTableRow Java Examples

The following examples show how to use org.apache.poi.xwpf.usermodel.XWPFTableRow. 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: ExcelMapParse.java    From jeasypoi with Apache License 2.0 6 votes vote down vote up
/**
 * 解析下一行,并且生成更多的行
 * 
 * @Author JueYue
 * @date 2013-11-18
 * @param table
 * @param listobj2
 */
public static void parseNextRowAndAddRow(XWPFTable table, int index, List<Object> list) throws Exception {
	XWPFTableRow currentRow = table.getRow(index);
	String[] params = parseCurrentRowGetParams(currentRow);
	table.removeRow(index);// 移除这一行
	int cellIndex = 0;// 创建完成对象一行好像多了一个cell
	for (Object obj : list) {
		currentRow = table.createRow();
		for (cellIndex = 0; cellIndex < currentRow.getTableCells().size(); cellIndex++) {
			currentRow.getTableCells().get(cellIndex).setText(PoiPublicUtil.getValueDoWhile(obj, params[cellIndex].split("\\."), 0).toString());
		}
		for (; cellIndex < params.length; cellIndex++) {
			currentRow.createCell().setText(PoiPublicUtil.getValueDoWhile(obj, params[cellIndex].split("\\."), 0).toString());
		}
	}

}
 
Example #2
Source File: HeaderFooterBodyContainer.java    From poi-tl with Apache License 2.0 6 votes vote down vote up
@Override
public XWPFTable insertNewTable(XWPFRun run, int row, int col) {
    XmlCursor cursor = ((XWPFParagraph) run.getParent()).getCTP().newCursor();
    XWPFTable table = insertNewTbl(cursor);
    // hack for cursor.removeXmlContents(); in XWPFHeaderFooter
    List<XWPFTableRow> rows = table.getRows();
    for (int i = 0; i < rows.size(); i++) {
        table.removeRow(i);
    }
    for (int i = 0; i < row; i++) {
        XWPFTableRow tabRow = (table.getRow(i) == null) ? table.createRow() : table.getRow(i);
        for (int k = 0; k < col; k++) {
            if (tabRow.getCell(k) == null) {
                tabRow.createCell();
            }
        }
    }
    return table;
}
 
Example #3
Source File: RawCopier.java    From M2Doc with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Updates bookmarks for the given output {@link XWPFTable} according to its input {@link XWPFTable}.
 * 
 * @param bookmarkManager
 *            the {@link BookmarkManager}
 * @param outputTable
 *            the output {@link XWPFTable}
 * @param inputTable
 *            the input {@link XWPFTable}
 */
private void updateBookmarks(BookmarkManager bookmarkManager, final XWPFTable outputTable,
        final XWPFTable inputTable) {
    final List<XWPFTableRow> inputRows = inputTable.getRows();
    final List<XWPFTableRow> outputRows = outputTable.getRows();
    for (int rowIndex = 0; rowIndex < inputRows.size(); rowIndex++) {
        final XWPFTableRow inputRow = inputRows.get(rowIndex);
        final XWPFTableRow outputRow = outputRows.get(rowIndex);
        final List<XWPFTableCell> inputCells = inputRow.getTableCells();
        final List<XWPFTableCell> outputCells = outputRow.getTableCells();
        for (int cellIndex = 0; cellIndex < inputCells.size(); cellIndex++) {
            final XWPFTableCell inputCell = inputCells.get(cellIndex);
            final XWPFTableCell outputCell = outputCells.get(cellIndex);
            final List<IBodyElement> inputBodyElements = inputCell.getBodyElements();
            final List<IBodyElement> outputBodyElements = outputCell.getBodyElements();
            for (int bodyElementIndex = 0; bodyElementIndex < inputBodyElements.size(); bodyElementIndex++) {
                final IBodyElement inputBodyElement = inputBodyElements.get(bodyElementIndex);
                if (inputBodyElement instanceof XWPFParagraph) {
                    final IBodyElement outputBodyElement = outputBodyElements.get(bodyElementIndex);
                    updateBookmarks(bookmarkManager, ((XWPFParagraph) outputBodyElement).getCTP(),
                            ((XWPFParagraph) inputBodyElement).getCTP());
                }
            }
        }
    }
}
 
Example #4
Source File: CellBodyContainer.java    From poi-tl with Apache License 2.0 6 votes vote down vote up
@Override
public XWPFTable insertNewTable(XWPFRun run, int row, int col) {
    XmlCursor cursor = ((XWPFParagraph) run.getParent()).getCTP().newCursor();
    XWPFTable table = insertNewTbl(cursor);

    // hack for cursor.removeXmlContents(); in XWPFTableCell
    List<XWPFTableRow> rows = table.getRows();
    for (int i = 0; i < rows.size(); i++) {
        table.removeRow(i);
    }
    for (int i = 0; i < row; i++) {
        XWPFTableRow tabRow = (table.getRow(i) == null) ? table.createRow() : table.getRow(i);
        for (int k = 0; k < col; k++) {
            if (tabRow.getCell(k) == null) {
                tabRow.createCell();
            }
        }
    }
    return table;
}
 
Example #5
Source File: AbstractBodyParser.java    From M2Doc with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Parses a {@link Table}.
 * 
 * @param wtable
 *            the table to parse
 * @return the created object
 * @throws DocumentParserException
 *             if a problem occurs while parsing.
 */
protected Table parseTable(XWPFTable wtable) throws DocumentParserException {
    if (wtable == null) {
        throw new IllegalArgumentException("parseTable can't be called on a null argument.");
    }
    Table table = (Table) EcoreUtil.create(TemplatePackage.Literals.TABLE);
    table.setTable(wtable);
    for (XWPFTableRow tablerow : wtable.getRows()) {
        Row row = (Row) EcoreUtil.create(TemplatePackage.Literals.ROW);
        table.getRows().add(row);
        row.setTableRow(tablerow);
        for (XWPFTableCell tableCell : tablerow.getTableCells()) {
            Cell cell = (Cell) EcoreUtil.create(TemplatePackage.Literals.CELL);
            row.getCells().add(cell);
            cell.setTableCell(tableCell);
            AbstractBodyParser parser = getNewParser(tableCell);
            cell.setBody(parser.parseBlock(null, TokenType.EOF));
        }
    }
    return table;
}
 
Example #6
Source File: CellBodyContainnerTest.java    From poi-tl with Apache License 2.0 6 votes vote down vote up
@BeforeEach
public void init() {
    XWPFTable xwpfTable = document.createTable();
    XWPFTableRow createRow = xwpfTable.createRow();
    cell = createRow.createCell();
    container = new CellBodyContainer(cell);

    // cell.addParagraph()有bug,不会更新bodyElements

    // p-t-p-t-p-t
    XWPFParagraph insertpos = cell.getParagraphArray(0);
    container.insertNewParagraph(insertpos.getCTP().newCursor());
    container.insertNewTable(insertpos.createRun(), 2, 2);
    paragraph = container.insertNewParagraph(insertpos.getCTP().newCursor());
    table = container.insertNewTable(insertpos.createRun(), 2, 2);
    container.insertNewParagraph(insertpos.getCTP().newCursor());
    container.insertNewTable(insertpos.createRun(), 2, 2);

    container.removeBodyElement(6);

}
 
Example #7
Source File: ParseWord07.java    From jeasypoi with Apache License 2.0 6 votes vote down vote up
/**
 * 解析这个表格
 * 
 * @Author JueYue
 * @date 2013-11-17
 * @param table
 * @param map
 */
private void parseThisTable(XWPFTable table, Map<String, Object> map) throws Exception {
	XWPFTableRow row;
	List<XWPFTableCell> cells;
	Object listobj;
	ExcelEntityParse excelEntityParse = new ExcelEntityParse();
	for (int i = 0; i < table.getNumberOfRows(); i++) {
		row = table.getRow(i);
		cells = row.getTableCells();
		if (cells.size() == 1) {
			listobj = checkThisTableIsNeedIterator(cells.get(0), map);
			if (listobj == null) {
				parseThisRow(cells, map);
			} else if (listobj instanceof ExcelListEntity) {
				table.removeRow(i);// 删除这一行
				excelEntityParse.parseNextRowAndAddRow(table, i, (ExcelListEntity) listobj);
			} else {
				table.removeRow(i);// 删除这一行
				ExcelMapParse.parseNextRowAndAddRow(table, i, (List) listobj);
			}
		} else {
			parseThisRow(cells, map);
		}
	}
}
 
Example #8
Source File: ExcelMapParse.java    From easypoi with Apache License 2.0 6 votes vote down vote up
/**
 * 解析下一行,并且生成更多的行
 * 
 * @Author JueYue
 * @date 2013-11-18
 * @param table
 * @param listobj2
 */
public static void parseNextRowAndAddRow(XWPFTable table, int index, List<Object> list)
                                                                                       throws Exception {
    XWPFTableRow currentRow = table.getRow(index);
    String[] params = parseCurrentRowGetParams(currentRow);
    table.removeRow(index);// 移除这一行
    int cellIndex = 0;// 创建完成对象一行好像多了一个cell
    for (Object obj : list) {
        currentRow = table.createRow();
        for (cellIndex = 0; cellIndex < currentRow.getTableCells().size(); cellIndex++) {
            currentRow
                .getTableCells()
                .get(cellIndex)
                .setText(
                    PoiPublicUtil.getValueDoWhile(obj, params[cellIndex].split("\\."), 0)
                        .toString());
        }
        for (; cellIndex < params.length; cellIndex++) {
            currentRow.createCell().setText(
                PoiPublicUtil.getValueDoWhile(obj, params[cellIndex].split("\\."), 0)
                    .toString());
        }
    }

}
 
Example #9
Source File: ExcelEntityParse.java    From jeasypoi with Apache License 2.0 6 votes vote down vote up
/**
 * 创建List之后的各个Cells
 * 
 * @param styles
 */
public void createListCells(int index, int cellNum, Object obj, List<ExcelExportEntity> excelParams, XWPFTable table) throws Exception {
	ExcelExportEntity entity;
	XWPFTableRow row;
	if (table.getRow(index) == null) {
		row = table.createRow();
		row.setHeight(getRowHeight(excelParams));
	} else {
		row = table.getRow(index);
	}
	for (int k = 0, paramSize = excelParams.size(); k < paramSize; k++) {
		entity = excelParams.get(k);
		Object value = getCellValue(entity, obj);
		if (entity.getType() == 1) {
			setCellValue(row, value, cellNum++);
		}
	}
}
 
Example #10
Source File: ExcelEntityParse.java    From easypoi with Apache License 2.0 6 votes vote down vote up
/**
 * 创建List之后的各个Cells
 * 
 * @param styles
 */
public void createListCells(int index, int cellNum, Object obj,
                            List<ExcelExportEntity> excelParams, XWPFTable table)
                                                                                 throws Exception {
    ExcelExportEntity entity;
    XWPFTableRow row;
    if (table.getRow(index) == null) {
        row = table.createRow();
        row.setHeight(getRowHeight(excelParams));
    } else {
        row = table.getRow(index);
    }
    for (int k = 0, paramSize = excelParams.size(); k < paramSize; k++) {
        entity = excelParams.get(k);
        Object value = getCellValue(entity, obj);
        if (entity.getType() == 1) {
            setCellValue(row, value, cellNum++);
        }
    }
}
 
Example #11
Source File: ParseWord07.java    From autopoi with Apache License 2.0 6 votes vote down vote up
/**
 * 解析这个表格
 * 
 * @Author JEECG
 * @date 2013-11-17
 * @param table
 * @param map
 */
private void parseThisTable(XWPFTable table, Map<String, Object> map) throws Exception {
	XWPFTableRow row;
	List<XWPFTableCell> cells;
	Object listobj;
	ExcelEntityParse excelEntityParse = new ExcelEntityParse();
	for (int i = 0; i < table.getNumberOfRows(); i++) {
		row = table.getRow(i);
		cells = row.getTableCells();
		if (cells.size() == 1) {
			listobj = checkThisTableIsNeedIterator(cells.get(0), map);
			if (listobj == null) {
				parseThisRow(cells, map);
			} else if (listobj instanceof ExcelListEntity) {
				table.removeRow(i);// 删除这一行
				excelEntityParse.parseNextRowAndAddRow(table, i, (ExcelListEntity) listobj);
			} else {
				table.removeRow(i);// 删除这一行
				ExcelMapParse.parseNextRowAndAddRow(table, i, (List) listobj);
			}
		} else {
			parseThisRow(cells, map);
		}
	}
}
 
Example #12
Source File: ExcelEntityParse.java    From autopoi with Apache License 2.0 6 votes vote down vote up
/**
 * 创建List之后的各个Cells
 * 
 * @param styles
 */
public void createListCells(int index, int cellNum, Object obj, List<ExcelExportEntity> excelParams, XWPFTable table) throws Exception {
	ExcelExportEntity entity;
	XWPFTableRow row;
	if (table.getRow(index) == null) {
		row = table.createRow();
		row.setHeight(getRowHeight(excelParams));
	} else {
		row = table.getRow(index);
	}
	for (int k = 0, paramSize = excelParams.size(); k < paramSize; k++) {
		entity = excelParams.get(k);
		Object value = getCellValue(entity, obj);
		if (entity.getType() == 1) {
			setCellValue(row, value, cellNum++);
		}
	}
}
 
Example #13
Source File: ParseWord07.java    From easypoi with Apache License 2.0 6 votes vote down vote up
/**
 * 解析这个表格
 * 
 * @Author JueYue
 * @date 2013-11-17
 * @param table
 * @param map
 */
private void parseThisTable(XWPFTable table, Map<String, Object> map) throws Exception {
    XWPFTableRow row;
    List<XWPFTableCell> cells;
    Object listobj;
    ExcelEntityParse excelEntityParse = new ExcelEntityParse();
    for (int i = 0; i < table.getNumberOfRows(); i++) {
        row = table.getRow(i);
        cells = row.getTableCells();
        if (cells.size() == 1) {
            listobj = checkThisTableIsNeedIterator(cells.get(0), map);
            if (listobj == null) {
                parseThisRow(cells, map);
            } else if (listobj instanceof ExcelListEntity) {
                table.removeRow(i);// 删除这一行
                excelEntityParse.parseNextRowAndAddRow(table, i, (ExcelListEntity) listobj);
            } else {
                table.removeRow(i);// 删除这一行
                ExcelMapParse.parseNextRowAndAddRow(table, i, (List) listobj);
            }
        } else {
            parseThisRow(cells, map);
        }
    }
}
 
Example #14
Source File: ExcelMapParse.java    From autopoi with Apache License 2.0 6 votes vote down vote up
/**
 * 解析下一行,并且生成更多的行
 * 
 * @Author JEECG
 * @date 2013-11-18
 * @param table
 * @param listobj2
 */
public static void parseNextRowAndAddRow(XWPFTable table, int index, List<Object> list) throws Exception {
	XWPFTableRow currentRow = table.getRow(index);
	String[] params = parseCurrentRowGetParams(currentRow);
	table.removeRow(index);// 移除这一行
	int cellIndex = 0;// 创建完成对象一行好像多了一个cell
	for (Object obj : list) {
		currentRow = table.createRow();
		for (cellIndex = 0; cellIndex < currentRow.getTableCells().size(); cellIndex++) {
			currentRow.getTableCells().get(cellIndex).setText(PoiPublicUtil.getValueDoWhile(obj, params[cellIndex].split("\\."), 0).toString());
		}
		for (; cellIndex < params.length; cellIndex++) {
			currentRow.createCell().setText(PoiPublicUtil.getValueDoWhile(obj, params[cellIndex].split("\\."), 0).toString());
		}
	}

}
 
Example #15
Source File: BookMarks.java    From frpMgr with MIT License 6 votes vote down vote up
/** 
 * 构造函数,用以分析文档,解析出所有的标签
 * @param document  Word OOXML document instance. 
 */
public BookMarks(XWPFDocument document) {

	//初始化标签缓存
	this._bookmarks = new HashMap<String, BookMark>();

	// 首先解析文档普通段落中的标签 
	this.procParaList(document.getParagraphs());

	//利用繁琐的方法,从所有的表格中得到得到标签,处理比较原始和简单
	List<XWPFTable> tableList = document.getTables();

	for (XWPFTable table : tableList) {
		//得到表格的列信息
		List<XWPFTableRow> rowList = table.getRows();
		for (XWPFTableRow row : rowList) {
			//得到行中的列信息
			List<XWPFTableCell> cellList = row.getTableCells();
			for (XWPFTableCell cell : cellList) {
				//逐个解析标签信息
				//this.procParaList(cell.getParagraphs(), row);
				this.procParaList(cell);
			}
		}
	}
}
 
Example #16
Source File: ExcelEntityParse.java    From easypoi with Apache License 2.0 5 votes vote down vote up
private void setCellValue(XWPFTableRow row, Object value, int cellNum) {
    if (row.getCell(cellNum++) != null) {
        row.getCell(cellNum - 1).setText(value == null ? "" : value.toString());
    } else {
        row.createCell().setText(value == null ? "" : value.toString());
    }
}
 
Example #17
Source File: TemplateResolver.java    From poi-tl with Apache License 2.0 5 votes vote down vote up
@Override
public List<MetaTemplate> resolveBodyElements(List<IBodyElement> bodyElements) {
    List<MetaTemplate> metaTemplates = new ArrayList<>();
    if (null == bodyElements) return metaTemplates;

    // current iterable templates state
    Deque<BlockTemplate> stack = new LinkedList<BlockTemplate>();

    for (IBodyElement element : bodyElements) {
        if (element == null) continue;
        if (element.getElementType() == BodyElementType.PARAGRAPH) {
            XWPFParagraph paragraph = (XWPFParagraph) element;
            RunningRunParagraph runningRun = new RunningRunParagraph(paragraph, templatePattern);
            List<XWPFRun> refactorRuns = runningRun.refactorRun();
            if (null == refactorRuns) continue;
            Collections.reverse(refactorRuns);
            resolveXWPFRuns(refactorRuns, metaTemplates, stack);
        } else if (element.getElementType() == BodyElementType.TABLE) {
            XWPFTable table = (XWPFTable) element;
            List<XWPFTableRow> rows = table.getRows();
            if (null == rows) continue;
            for (XWPFTableRow row : rows) {
                List<XWPFTableCell> cells = row.getTableCells();
                if (null == cells) continue;
                cells.forEach(cell -> {
                    List<MetaTemplate> visitBodyElements = resolveBodyElements(cell.getBodyElements());
                    if (stack.isEmpty()) {
                        metaTemplates.addAll(visitBodyElements);
                    } else {
                        stack.peek().getTemplates().addAll(visitBodyElements);
                    }
                });
            }
        }
    }

    checkStack(stack);
    return metaTemplates;
}
 
Example #18
Source File: ExcelEntityParse.java    From easypoi with Apache License 2.0 5 votes vote down vote up
private int createCells(int index, Object t, List<ExcelExportEntity> excelParams,
                        XWPFTable table, short rowHeight) throws Exception {
    ExcelExportEntity entity;
    XWPFTableRow row = table.createRow();
    row.setHeight(rowHeight);
    int maxHeight = 1, cellNum = 0;
    for (int k = 0, paramSize = excelParams.size(); k < paramSize; k++) {
        entity = excelParams.get(k);
        if (entity.getList() != null) {
            Collection<?> list = (Collection<?>) entity.getMethod().invoke(t, new Object[] {});
            int listC = 0;
            for (Object obj : list) {
                createListCells(index + listC, cellNum, obj, entity.getList(), table);
                listC++;
            }
            cellNum += entity.getList().size();
            if (list != null && list.size() > maxHeight) {
                maxHeight = list.size();
            }
        } else {
            Object value = getCellValue(entity, t);
            if (entity.getType() == 1) {
                setCellValue(row, value, cellNum++);
            }
        }
    }
    // 合并需要合并的单元格
    cellNum = 0;
    for (int k = 0, paramSize = excelParams.size(); k < paramSize; k++) {
        entity = excelParams.get(k);
        if (entity.getList() != null) {
            cellNum += entity.getList().size();
        } else if (entity.isNeedMerge()) {
            table.setCellMargins(index, index + maxHeight - 1, cellNum, cellNum);
            cellNum++;
        }
    }
    return maxHeight;
}
 
Example #19
Source File: AbstractWpfRowMapper.java    From onetwo with Apache License 2.0 5 votes vote down vote up
@Override
public List<String> mapTitleRow(XWPFTable table) {
	XWPFTableRow row = table.getRow(0);
	return row.getTableCells().stream().map(cell->{
		return StringUtils.trim(cell.getText());
	}).collect(Collectors.toList());
}
 
Example #20
Source File: ExcelMapParse.java    From easypoi with Apache License 2.0 5 votes vote down vote up
/**
 * 解析参数行,获取参数列表
 * 
 * @Author JueYue
 * @date 2013-11-18
 * @param currentRow
 * @return
 */
private static String[] parseCurrentRowGetParams(XWPFTableRow currentRow) {
    List<XWPFTableCell> cells = currentRow.getTableCells();
    String[] params = new String[cells.size()];
    String text;
    for (int i = 0; i < cells.size(); i++) {
        text = cells.get(i).getText();
        params[i] = text == null ? "" : text.trim().replace("{{", "").replace("}}", "");
    }
    return params;
}
 
Example #21
Source File: DocumentBodyContainer.java    From poi-tl with Apache License 2.0 5 votes vote down vote up
@Override
public XWPFTable insertNewTable(XWPFRun run, int row, int col) {
    XmlCursor cursor = ((XWPFParagraph) run.getParent()).getCTP().newCursor();
    XWPFTable table = insertNewTbl(cursor);
    for (int i = 0; i < row; i++) {
        XWPFTableRow tabRow = (table.getRow(i) == null) ? table.createRow() : table.getRow(i);
        for (int k = 0; k < col; k++) {
            if (tabRow.getCell(k) == null) {
                tabRow.createCell();
            }
        }
    }
    return table;
}
 
Example #22
Source File: MiniTableRenderPolicy.java    From poi-tl with Apache License 2.0 5 votes vote down vote up
public static void renderRow(XWPFTable table, int row, RowRenderData rowData) {
    if (null == rowData || rowData.size() <= 0) return;
    XWPFTableRow tableRow = table.getRow(row);
    Objects.requireNonNull(tableRow, "Row [" + row + "] do not exist in the table");

    TableStyle rowStyle = rowData.getRowStyle();
    List<CellRenderData> cellDatas = rowData.getCells();
    XWPFTableCell cell = null;

    for (int i = 0; i < cellDatas.size(); i++) {
        cell = tableRow.getCell(i);
        Objects.requireNonNull(cell, "Cell [" + i + "] do not exist at row " + row);
        renderCell(cell, cellDatas.get(i), rowStyle);
    }
}
 
Example #23
Source File: BeanWpfRowMapper.java    From onetwo with Apache License 2.0 5 votes vote down vote up
@Override
public T mapDataRow(XWPFTable sheet, List<String> names, int rowIndex) {
	XWPFTableRow row = sheet.getRow(rowIndex);
	T bean = ExcelUtils.newInstance(beanClass);
	MapperBean<T> mapperBean = tableHeaderMapper.createMapperBean(bean);
	IntStream.range(0, row.getTableCells().size()).forEach(index->{
		XWPFTableCell cell = row.getTableCells().get(index);
		mapperBean.setValue(index, StringUtils.trim(cell.getText()));
	});
	return mapperBean.getBean();
}
 
Example #24
Source File: DocPrSupport.java    From poi-tl with Apache License 2.0 5 votes vote down vote up
public static void updateDocPrId(XWPFTable table) {
    List<XWPFTableRow> rows = table.getRows();
    rows.forEach(row -> {
        List<XWPFTableCell> cells = row.getTableCells();
        cells.forEach(cell -> {
            cell.getParagraphs().forEach(DocPrSupport::updateDocPrId);
            cell.getTables().forEach(DocPrSupport::updateDocPrId);
        });
    });
}
 
Example #25
Source File: NiceXWPFDocument.java    From poi-tl with Apache License 2.0 5 votes vote down vote up
private void readTables(List<XWPFTable> tables) {
    allTables.addAll(tables);
    for (XWPFTable table : tables) {
        List<XWPFTableRow> rows = table.getRows();
        if (null == rows) continue;;
        for (XWPFTableRow row : rows) {
            List<XWPFTableCell> cells = row.getTableCells();
            if (null == cells) continue;
            for (XWPFTableCell cell : cells) {
                initAllElement(cell);
            }
        }
    }
}
 
Example #26
Source File: RowImpl.java    From M2Doc with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * 
 * @generated
 */
@SuppressWarnings("unchecked")
@Override
public void eSet(int featureID, Object newValue) {
    switch (featureID) {
        case TemplatePackage.ROW__CELLS:
            getCells().clear();
            getCells().addAll((Collection<? extends Cell>) newValue);
            return;
        case TemplatePackage.ROW__TABLE_ROW:
            setTableRow((XWPFTableRow) newValue);
            return;
    }
    super.eSet(featureID, newValue);
}
 
Example #27
Source File: RowImpl.java    From M2Doc with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * 
 * @generated
 */
public void setTableRow(XWPFTableRow newTableRow) {
    XWPFTableRow oldTableRow = tableRow;
    tableRow = newTableRow;
    if (eNotificationRequired())
        eNotify(new ENotificationImpl(this, Notification.SET, TemplatePackage.ROW__TABLE_ROW, oldTableRow,
                tableRow));
}
 
Example #28
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 #29
Source File: SingleWordXTableParser.java    From sun-wordtable-read with Apache License 2.0 5 votes vote down vote up
/**
 * 解析word中表格行
 * @param row
 * @param realRowIndex
 */
private void parseRow(XWPFTableRow row, int realRowIndex) {
	List<XWPFTableCell> cells = row.getTableCells();
	int numCells = cells.size();

	int logicColumnIndex = 0;
	int logicRowIndex = realRowIndex; //逻辑行号与实际行号一样
	for (int realColumnIndex = 0; realColumnIndex < numCells; realColumnIndex++) {
		XWPFTableCell cell = row.getCell(realColumnIndex);
		//skipColumn是否跳过多个单元格, 当列合并时候
		int skipColumn = parseCell(cell, realRowIndex, realColumnIndex, logicRowIndex, logicColumnIndex);
		logicColumnIndex = logicColumnIndex + skipColumn + 1;
	}
}
 
Example #30
Source File: ExcelEntityParse.java    From jeasypoi with Apache License 2.0 5 votes vote down vote up
private void setCellValue(XWPFTableRow row, Object value, int cellNum) {
	if (row.getCell(cellNum++) != null) {
		row.getCell(cellNum - 1).setText(value == null ? "" : value.toString());
	} else {
		row.createCell().setText(value == null ? "" : value.toString());
	}
}