本文整理汇总了Java中org.apache.poi.xwpf.usermodel.XWPFDocument.createTable方法的典型用法代码示例。如果您正苦于以下问题:Java XWPFDocument.createTable方法的具体用法?Java XWPFDocument.createTable怎么用?Java XWPFDocument.createTable使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.poi.xwpf.usermodel.XWPFDocument
的用法示例。
在下文中一共展示了XWPFDocument.createTable方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: main
import org.apache.poi.xwpf.usermodel.XWPFDocument; //导入方法依赖的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();
}
示例2: createSimpleTable
import org.apache.poi.xwpf.usermodel.XWPFDocument; //导入方法依赖的package包/类
public static void createSimpleTable() throws Exception {
@SuppressWarnings("resource")
XWPFDocument doc = new XWPFDocument();
XWPFTable table = doc.createTable(3, 3);
table.getRow(1).getCell(1).setText("EXAMPLE OF TABLE");
// table cells have a list of paragraphs; there is an initial
// paragraph created when the cell is created. If you create a
// paragraph in the document to put in the cell, it will also
// appear in the document following the table, which is probably
// not the desired result.
XWPFParagraph p1 = table.getRow(0).getCell(0).getParagraphs().get(0);
XWPFRun r1 = p1.createRun();
r1.setBold(true);
r1.setText("The quick brown fox");
r1.setItalic(true);
r1.setFontFamily("Courier");
r1.setUnderline(UnderlinePatterns.DOT_DOT_DASH);
r1.setTextPosition(100);
table.getRow(2).getCell(2).setText("only text");
FileOutputStream out = new FileOutputStream("simpleTable.docx");
doc.write(out);
out.close();
}
示例3: createTable
import org.apache.poi.xwpf.usermodel.XWPFDocument; //导入方法依赖的package包/类
public XWPFTable createTable(XWPFDocument doc) {
XWPFTable table = doc.createTable(rows, cols);
table.setCellMargins(0, 0, 0, 0);
table.setInsideHBorder(innerHBorder, 1, 0, "000000");
return table;
}
示例4: main
import org.apache.poi.xwpf.usermodel.XWPFDocument; //导入方法依赖的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");
}