表 (3 列と 1 行) を含む Word テンプレートがあります。Java の任意の API を使用して、このテーブルにさらに行を追加したいと考えています。Word 2010 テンプレートの既存の表に行を追加できますか?
1184 次
1 に答える
1
https://poi.apache.org/にあるJava Apache POI を使用しますが、Excel を使用していない限り、これは少し難しいかもしれません。
もう 1 つのオプションは、http: //www.aspose.com/ にある Aspose API です。
このコードは、既存のテーブルに行を追加します
Document doc = new Document(MyDir + "document.docx");
// Retrieve the first table in the document.
Table table = (Table)doc.getChild(NodeType.TABLE, 0, true);
// Clone the last row in the table.
Row clonedRow = (Row)table.getLastRow().deepClone(true);
// Remove all content from the cloned row's cells. This makes the row ready for
// new content to be inserted into.
for (Cell cell: clonedRow.getCells())
{
cell.getFirstParagraph().getRuns().clear();
cell.getFirstParagraph().appendChild(new Run(doc,"hello text"));
}
// Add the row to the end of the table.
table.appendChild(clonedRow);
doc.save(MyDir + "Table.AddCloneRowToTable Out.doc");
于 2016-04-25T11:48:06.540 に答える