Java 以xml-apache-poi的形式获取表

Java 以xml-apache-poi的形式获取表,java,ms-word,apache-poi,Java,Ms Word,Apache Poi,我使用apache poi创建一个表,如下所示: XWPFDocument document= new XWPFDocument(); //Write the Document in file system FileOutputStream out = new FileOutputStream(new File("create_table.docx")); //create table XWPFTable table = document.c

我使用apache poi创建一个表,如下所示:

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

      //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 one, row two");
      tableRowTwo.getCell(1).setText("col two, row two");
      tableRowTwo.getCell(2).setText("col three, row two");

      //create third row
      XWPFTableRow tableRowThree = table.createRow();
      tableRowThree.getCell(0).setText("col one, row three");
      tableRowThree.getCell(1).setText("col two, row three");
      tableRowThree.getCell(2).setText("col three, row three");
现在,我希望以字符串变量的形式获取表格式和数据,如:

<w:style w:type="table"...>
<w:rPr><w:t> data </w:t> </w:rPr>

资料

我可以这样做吗?

如果是指的Office OpenXML,那么:

返回一个扩展名,该扩展名提供一个扩展名,该扩展名返回此XML对象的XML字符串

所以


不清楚您指的是什么类型的
XML
。Word表格的Office OpenXML将是:
单元格文本内容……
其中
tbl
是表格,
tr
是表格行,
tc
是表格单元格,
p
是段落,
r
是文本运行,
t
是文本。因此,您的示例
XML
有点混乱。
String tableXML = table.getCTTbl().toString();