本文整理汇总了Java中org.apache.poi.xwpf.usermodel.XWPFTable.getRow方法的典型用法代码示例。如果您正苦于以下问题:Java XWPFTable.getRow方法的具体用法?Java XWPFTable.getRow怎么用?Java XWPFTable.getRow使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.poi.xwpf.usermodel.XWPFTable
的用法示例。
在下文中一共展示了XWPFTable.getRow方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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);
// }
}
示例2: 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();
}
}
}
示例3: 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++);
}
}
}
示例4: 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;//删除之后要往上挪一行,然后加上跳过新建的行数
}
}
}
示例5: 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());
}
}
}
示例6: 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++);
}
}
}
示例7: 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);
}
}
}
示例8: main
import org.apache.poi.xwpf.usermodel.XWPFTable; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception
{
XWPFDocument document = new XWPFDocument();
// New 2x2 table
XWPFTable tableOne = document.createTable();
XWPFTableRow tableOneRowOne = tableOne.getRow(0);
tableOneRowOne.getCell(0).setText("Hello");
tableOneRowOne.addNewTableCell().setText("World");
XWPFTableRow tableOneRowTwo = tableOne.createRow();
tableOneRowTwo.getCell(0).setText("This is");
tableOneRowTwo.getCell(1).setText("a table");
// Add a break between the tables
document.createParagraph().createRun().addBreak();
// New 3x3 table
XWPFTable tableTwo = document.createTable();
XWPFTableRow tableTwoRowOne = tableTwo.getRow(0);
tableTwoRowOne.getCell(0).setText("col one, row one");
tableTwoRowOne.addNewTableCell().setText("col two, row one");
tableTwoRowOne.addNewTableCell().setText("col three, row one");
XWPFTableRow tableTwoRowTwo = tableTwo.createRow();
tableTwoRowTwo.getCell(0).setText("col one, row two");
tableTwoRowTwo.getCell(1).setText("col two, row two");
tableTwoRowTwo.getCell(2).setText("col three, row two");
XWPFTableRow tableTwoRowThree = tableTwo.createRow();
tableTwoRowThree.getCell(0).setText("col one, row three");
tableTwoRowThree.getCell(1).setText("col two, row three");
tableTwoRowThree.getCell(2).setText("col three, row three");
FileOutputStream outStream = new FileOutputStream("data/Apache_CreateTable.doc");
document.write(outStream);
outStream.close();
}
示例9: main
import org.apache.poi.xwpf.usermodel.XWPFTable; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception
{
String dataPath = "src/featurescomparison/workingwithtables/createtables/data/";
XWPFDocument document = new XWPFDocument();
// New 2x2 table
XWPFTable tableOne = document.createTable();
XWPFTableRow tableOneRowOne = tableOne.getRow(0);
tableOneRowOne.getCell(0).setText("Hello");
tableOneRowOne.addNewTableCell().setText("World");
XWPFTableRow tableOneRowTwo = tableOne.createRow();
tableOneRowTwo.getCell(0).setText("This is");
tableOneRowTwo.getCell(1).setText("a table");
// Add a break between the tables
document.createParagraph().createRun().addBreak();
// New 3x3 table
XWPFTable tableTwo = document.createTable();
XWPFTableRow tableTwoRowOne = tableTwo.getRow(0);
tableTwoRowOne.getCell(0).setText("col one, row one");
tableTwoRowOne.addNewTableCell().setText("col two, row one");
tableTwoRowOne.addNewTableCell().setText("col three, row one");
XWPFTableRow tableTwoRowTwo = tableTwo.createRow();
tableTwoRowTwo.getCell(0).setText("col one, row two");
tableTwoRowTwo.getCell(1).setText("col two, row two");
tableTwoRowTwo.getCell(2).setText("col three, row two");
XWPFTableRow tableTwoRowThree = tableTwo.createRow();
tableTwoRowThree.getCell(0).setText("col one, row three");
tableTwoRowThree.getCell(1).setText("col two, row three");
tableTwoRowThree.getCell(2).setText("col three, row three");
FileOutputStream outStream = new FileOutputStream(dataPath + "Apache_CreateTable_Out.doc");
document.write(outStream);
outStream.close();
System.out.println("Process Completed Successfully");
}
示例10: mergeCellHorizon
import org.apache.poi.xwpf.usermodel.XWPFTable; //导入方法依赖的package包/类
/**
* 수평셀 병합
*
* @param table
* @param rowNum
* @param colNum
* @param span
*/
public void mergeCellHorizon(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));
}
示例11: fillTable
import org.apache.poi.xwpf.usermodel.XWPFTable; //导入方法依赖的package包/类
/**
* Fill a newly created word table with the data from an MTable.
*
* @param table
* The newly created word table
* @param mtable
* The MTable that describes the data and styles to insert
*/
private void fillTable(XWPFTable table, MTable mtable) {
List<MRow> rows = mtable.getRows();
// Iterate over the rows
for (int rowIdx = 0; rowIdx < rows.size(); rowIdx++) {
MRow mRow = rows.get(rowIdx);
// Get or create XWPF row
XWPFTableRow xwpfRow;
if (table.getNumberOfRows() > rowIdx) {
xwpfRow = table.getRow(rowIdx);
} else {
xwpfRow = table.createRow();
}
// Iterate over the columns
for (int colIdx = 0; colIdx < mtable.getColumnsCount(); colIdx++) {
// Get or create XWPF cell
XWPFTableCell xwpfCell;
if (xwpfRow.getTableCells().size() > colIdx) {
xwpfCell = xwpfRow.getCell(colIdx);
} else {
xwpfCell = xwpfRow.createCell();
}
// Populate cell
XWPFParagraph xwpfCellParagraph = xwpfCell.getParagraphs().get(0);
xwpfCellParagraph.setSpacingBefore(0);
xwpfCellParagraph.setSpacingAfter(0);
MCell mCell = null;
if (colIdx < mRow.getCells().size()) {
mCell = mRow.getCells().get(colIdx);
}
setCellContent(xwpfCell, mCell);
}
}
}
示例12: mapTitleRow
import org.apache.poi.xwpf.usermodel.XWPFTable; //导入方法依赖的package包/类
@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());
}
示例13: mapDataRow
import org.apache.poi.xwpf.usermodel.XWPFTable; //导入方法依赖的package包/类
@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();
}
示例14: addSourceTablesAppendix
import org.apache.poi.xwpf.usermodel.XWPFTable; //导入方法依赖的package包/类
private static void addSourceTablesAppendix(CustomXWPFDocument document, ETL etl) {
XWPFParagraph paragraph = document.createParagraph();
XWPFRun run = paragraph.createRun();
run.addBreak(BreakType.PAGE);
run.setText("Appendix: source tables");
run.setFontSize(18);
for (Table sourceTable : etl.getSourceDatabase().getTables()) {
paragraph = document.createParagraph();
run = paragraph.createRun();
run.setText("Table: " + sourceTable.getName());
run.setFontSize(14);
createDocumentParagraph(document, sourceTable.getComment());
XWPFTable table = document.createTable(sourceTable.getFields().size() + 1, 4);
// table.setWidth(2000);
XWPFTableRow header = table.getRow(0);
setTextAndHeaderShading(header.getCell(0), "Field");
setTextAndHeaderShading(header.getCell(1), "Type");
setTextAndHeaderShading(header.getCell(2), "Most freq. value");
setTextAndHeaderShading(header.getCell(3), "Comment");
int rowNr = 1;
for (Field sourceField : sourceTable.getFields()) {
XWPFTableRow row = table.getRow(rowNr++);
row.getCell(0).setText(sourceField.getName());
row.getCell(1).setText(sourceField.getType());
if (sourceField.getValueCounts() != null && sourceField.getValueCounts().length != 0)
row.getCell(2).setText(sourceField.getValueCounts()[0][0]);
createCellParagraph(row.getCell(3), sourceField.getComment().trim());
}
}
run.setFontSize(18);
}
示例15: mapDataRow
import org.apache.poi.xwpf.usermodel.XWPFTable; //导入方法依赖的package包/类
@Override
public T mapDataRow(XWPFTable table, List<String> names, int rowIndex) {
XWPFTableRow row = table.getRow(rowIndex);
// TODO Auto-generated method stub
return null;
}