小编Nas*_*ass的帖子

apache poi 在word文档中添加表格

我有 Java 代码来使用 Apache POI 创建一个表格和一些文本到 Word 文档,但它在最后一个文档中添加了表格。我想写一些文字,然后添加表格并再次写一些文字。

目前它添加表格第一个和最后一个文档添加 2 个文本(嗨和再见)

我的代码:

public static void main(String[] args)throws Exception {
        //Blank Document
        XWPFDocument document= new XWPFDocument();

        //Write the Document in file system
        FileOutputStream out = new FileOutputStream(
        new File("create_table.docx"));

        //create table
        XWPFTable table    = document.createTable();
        XWPFParagraph para = document.createParagraph();
        XWPFRun run        = para.createRun();

        run.setText("Hi");
        //create first row
        XWPFTableRow tableRowOne = table.getRow(0);
        tableRowOne.getCell(0).setText("col one, row one");
        tableRowOne.addNewTableCell().setText("col two, row one");
        tableRowOne.addNewTableCell().setText("col three, row one");
        //create second row
        XWPFTableRow tableRowTwo = table.createRow();
        tableRowTwo.getCell(0).setText("col …
Run Code Online (Sandbox Code Playgroud)

java swing report apache-poi

5
推荐指数
1
解决办法
9876
查看次数

标签 统计

apache-poi ×1

java ×1

report ×1

swing ×1