本文整理汇总了Java中org.apache.poi.xwpf.usermodel.XWPFTable.createRow方法的典型用法代码示例。如果您正苦于以下问题:Java XWPFTable.createRow方法的具体用法?Java XWPFTable.createRow怎么用?Java XWPFTable.createRow使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.poi.xwpf.usermodel.XWPFTable
的用法示例。
在下文中一共展示了XWPFTable.createRow方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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++);
}
}
}
示例2: 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());
}
}
}
示例3: 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++);
}
}
}
示例4: 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();
}
示例5: 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");
}
示例6: 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);
}
}
}
示例7: createCells
import org.apache.poi.xwpf.usermodel.XWPFTable; //导入方法依赖的package包/类
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;
}