本文整理汇总了Java中org.apache.poi.xwpf.usermodel.XWPFTable类的典型用法代码示例。如果您正苦于以下问题:Java XWPFTable类的具体用法?Java XWPFTable怎么用?Java XWPFTable使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
XWPFTable类属于org.apache.poi.xwpf.usermodel包,在下文中一共展示了XWPFTable类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: copyTableStyle
import org.apache.poi.xwpf.usermodel.XWPFTable; //导入依赖的package包/类
/**
* Copy Table Style.
*
* @param inputTable
* input Table
* @param outputDoc
* outputDoc where copy style
* @throws IOException
* if the copy fails
*/
private static void copyTableStyle(XWPFTable inputTable, XWPFDocument outputDoc) throws IOException {
try (XWPFDocument inputDoc = inputTable.getBody().getXWPFDocument();) {
XWPFStyle style = inputDoc.getStyles().getStyle(inputTable.getStyleID());
if (outputDoc == null || style == null) {
return;
}
if (outputDoc.getStyles() == null) {
outputDoc.createStyles();
}
List<XWPFStyle> usedStyleList = inputDoc.getStyles().getUsedStyleList(style);
for (XWPFStyle xwpfStyle : usedStyleList) {
outputDoc.getStyles().addStyle(xwpfStyle);
}
}
}
示例2: spanCellsAcrossRow
import org.apache.poi.xwpf.usermodel.XWPFTable; //导入依赖的package包/类
/**
* 테이블의 특정 로우의 컬럼에 해당하는 부분의 셀을 나눔. 나누기는 하나.. 컬럼의 셀수가 일치하지 않고 틀어짐.
*
* @param table
* @param rowNum
* @param colNum
* @param span
*/
private static void spanCellsAcrossRow(XWPFTable table, int rowNum, int colNum, int span) {
XWPFTableRow row = table.getRow(rowNum);
XWPFTableCell cell = row.getCell(colNum);
CTDecimalNumber grdSpan = cell.getCTTc().getTcPr().getGridSpan();
if (grdSpan == null) {
grdSpan = cell.getCTTc().getTcPr().addNewGridSpan();
}
grdSpan.setVal(BigInteger.valueOf((long) span));
/*
* row가 0인경우 바로 아래래 로우의 컬럼수도 일치하도록 셀을 추가한다. 추가하지않는경우 컬럼셀의 수가 불일치한 상태로
* 문서가 만들어진다.
*/
// if (rowNum == 0)
// {
// addTableCell(DIRECTION._0, table, rowNum, span);
// } else
// {
// addTableCell(DIRECTION.UP_DOWN, table, rowNum, span);
// }
}
示例3: mergeCellsHorizonal
import org.apache.poi.xwpf.usermodel.XWPFTable; //导入依赖的package包/类
/**
* 合并行单元格
* @param table
* @param row
* @param fromCol
* @param toCol
*/
public void mergeCellsHorizonal(XWPFTable table, int row, int fromCol,
int toCol) {
for (int colIndex = fromCol; colIndex <= toCol; colIndex++) {
XWPFTableCell cell = table.getRow(row).getCell(colIndex);
CTTcPr tcPr = cell.getCTTc().getTcPr();
if (null == tcPr)
tcPr = cell.getCTTc().addNewTcPr();
CTHMerge hMerge = tcPr.addNewHMerge();
if (colIndex == fromCol) {
// The first merged cell is set with RESTART merge value
hMerge.setVal(STMerge.RESTART);
} else {
// Cells which join (merge) the first one, are set with CONTINUE
hMerge.setVal(STMerge.CONTINUE);
}
}
}
示例4: mergeCellsVertically
import org.apache.poi.xwpf.usermodel.XWPFTable; //导入依赖的package包/类
/**
* 合并列单元格
* @param table
* @param col
* @param fromRow
* @param toRow
*/
public void mergeCellsVertically(XWPFTable table, int col, int fromRow,
int toRow) {
for (int rowIndex = fromRow; rowIndex <= toRow; rowIndex++) {
XWPFTableCell cell = table.getRow(rowIndex).getCell(col);
CTTcPr tcPr = cell.getCTTc().getTcPr();
if (null == tcPr)
tcPr = cell.getCTTc().addNewTcPr();
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);
}
}
}
示例5: render
import org.apache.poi.xwpf.usermodel.XWPFTable; //导入依赖的package包/类
@Override
public void render(ElementTemplate eleTemplate, Object data,
XWPFTemplate template) {
NiceXWPFDocument doc = template.getXWPFDocument();
RunTemplate runTemplate = (RunTemplate) eleTemplate;
XWPFRun run = runTemplate.getRun();
try {
XmlCursor newCursor = ((XWPFParagraph)run.getParent()).getCTP().newCursor();
newCursor.toParent();
//if (newCursor.getObject() instanceof CTTc)
newCursor.toParent();
newCursor.toParent();
XmlObject object = newCursor.getObject();
XWPFTable table = doc.getTable((CTTbl) object);
render(table, data);
} catch (Exception e) {
logger.error("dynamic table error:" + e.getMessage(), e);
}
}
示例6: mergeCellsVertically
import org.apache.poi.xwpf.usermodel.XWPFTable; //导入依赖的package包/类
/**
* 수직셀 병합
*
* @param table
* @param col
* @param fromRow
* @param toRow
* 절대위치
*/
public void mergeCellsVertically(XWPFTable table, int col, int fromRow, int toRow) {
for (int rowIndex = fromRow; rowIndex <= toRow; rowIndex++) {
XWPFTableCell cell = table.getRow(rowIndex).getCell(col);
if (rowIndex == fromRow) {
// The first merged cell is set with RESTART merge value
cell.getCTTc().addNewTcPr().addNewVMerge().setVal(STMerge.RESTART);
} else {
// Cells which join (merge) the first one, are set with CONTINUE
cell.getCTTc().addNewTcPr().addNewVMerge().setVal(STMerge.CONTINUE);
}
}
}
示例7: addTableCell
import org.apache.poi.xwpf.usermodel.XWPFTable; //导入依赖的package包/类
private static void addTableCell(DIRECTION dir, XWPFTable table, int currentRow, int span) {
int dirRowIndex = 0;
if (DIRECTION._0 == dir) {
dirRowIndex = currentRow + 1;
} else if (DIRECTION.UP_DOWN == dir) {
dirRowIndex = currentRow - 1;
}
XWPFTableRow belowRow = table.getRow(dirRowIndex);
if (belowRow != null) {
// 병합된 span만큼 셀을 추가한다.
for (int i = 0; i < span - 1; i++) {
belowRow.createCell();
}
}
}
示例8: parseTable
import org.apache.poi.xwpf.usermodel.XWPFTable; //导入依赖的package包/类
/**
* 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.setTemplate(parser.parseTemplate());
}
}
return table;
}
示例9: createListCells
import org.apache.poi.xwpf.usermodel.XWPFTable; //导入依赖的package包/类
/**
* 创建List之后的各个Cells
* @param index
* @param cellNum
* @param obj
* @param excelParams
* @param table
* @throws Exception
*/
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++);
}
}
}
示例10: getTitleMap
import org.apache.poi.xwpf.usermodel.XWPFTable; //导入依赖的package包/类
/**
* 获取表头数据
*
* @param table
* @param index
* @return
*/
private Map<String, Integer> getTitleMap(XWPFTable table, int index, int headRows) {
if (index < headRows) {
throw new WordExportException(WordExportEnum.EXCEL_NO_HEAD);
}
Map<String, Integer> map = new HashMap<String, Integer>();
String text;
for (int j = 0; j < headRows; j++) {
List<XWPFTableCell> cells = table.getRow(index - j - 1).getTableCells();
for (int i = 0; i < cells.size(); i++) {
text = cells.get(i).getText();
if (StringUtils.isEmpty(text)) {
throw new WordExportException(WordExportEnum.EXCEL_HEAD_HAVA_NULL);
}
map.put(text, i);
}
}
return map;
}
示例11: parseThisTable
import org.apache.poi.xwpf.usermodel.XWPFTable; //导入依赖的package包/类
/**
* 解析这个表格
*
* @author JueYue
* 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;
for (int i = 0; i < table.getNumberOfRows(); i++) {
row = table.getRow(i);
cells = row.getTableCells();
listobj = checkThisTableIsNeedIterator(cells.get(0), map);
if (listobj == null) {
parseThisRow(cells, map);
} else if (listobj instanceof ExcelListEntity) {
table.removeRow(i);// 删除这一行
new ExcelEntityParse().parseNextRowAndAddRow(table, i, (ExcelListEntity) listobj);
i = i + ((ExcelListEntity) listobj).getList().size() - 1;//删除之后要往上挪一行,然后加上跳过新建的行数
} else {
ExcelMapParse.parseNextRowAndAddRow(table, i, (List) listobj);
i = i + ((List) listobj).size() - 1;//删除之后要往上挪一行,然后加上跳过新建的行数
}
}
}
示例12: parseWordSetValue
import org.apache.poi.xwpf.usermodel.XWPFTable; //导入依赖的package包/类
private void parseWordSetValue(MyXWPFDocument doc, Map<String, Object> map) throws Exception {
// 第一步解析文档
parseAllParagraphic(doc.getParagraphs(), map);
// 第二步解析页眉,页脚
parseHeaderAndFoot(doc, map);
// 第三步解析所有表格
XWPFTable table;
Iterator<XWPFTable> itTable = doc.getTablesIterator();
while (itTable.hasNext()) {
table = itTable.next();
if (table.getText().indexOf(START_STR) != -1) {
parseThisTable(table, map);
}
}
}
示例13: parseNextRowAndAddRow
import org.apache.poi.xwpf.usermodel.XWPFTable; //导入依赖的package包/类
/**
* 解析下一行,并且生成更多的行
*
* @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());
}
}
}
示例14: createListCells
import org.apache.poi.xwpf.usermodel.XWPFTable; //导入依赖的package包/类
/**
* 创建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++);
}
}
}
示例15: parseThisTable
import org.apache.poi.xwpf.usermodel.XWPFTable; //导入依赖的package包/类
/**
* 解析这个表格
*
* @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);
}
}
}