有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

docx文档边界外的java XWPF列(Ubuntu 16.04主机)

我正在用LibreOffice v5运行一个4.10.0-42通用的Ubuntu16.04 LTS。1.6.2. 使用Oxygen Eclipse 4.7.2,通过创建一个Maven项目,添加poi和poi ooxml 3.15作为依赖项,我试图在中使用Java创建一个表。docx格式。 不用说,我找不到解决办法。我的代码片段如下所示:

public class Application {

public static void main(String[] args)throws Exception {

   FileOutputStream fos = new FileOutputStream("samplefile.docx");

   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");

    document.write(fos);
    fos.close();
    System.out.println("Success!");
   }
}

上面的代码显示以下结果: Sample picture from LibreOffice

我想知道问题是在LibreOffice还是在我的代码中


共 (1) 个答案

  1. # 1 楼答案

    当我尝试在运行Microsoft Office的虚拟Windows 10计算机上获取文件时,图形显示正确,因此我认为LibreOffice无法正确处理行,只能显示文本

    问题为我解决了——下次我在Microsoft Office和Windows下测试所有文件时