We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Aspose.Words for java 表格书签如何替换

您好,我这边有关于Aspose.Words for JAVA word表格书签变量替换的问题想要咨询

如何根据表格里的一个书签来动态的填充这个书签所在表格的行和列,并且样式和和之前保持一致。可否给出示例代码?

@ils,

请查看这些输入和输出Word文档,然后尝试运行以下代码。Docs.zip (23.9 KB)

Document doc = new Document("E:\\Temp\\table.docx");
DocumentBuilder builder = new DocumentBuilder(doc);

foreach (Bookmark bookmark in doc.Range.Bookmarks)
{
    // detect if bookmark is inside  row
    Row row = (Row)bookmark.BookmarkStart.GetAncestor(NodeType.Row);
    if (row != null)
    {
        // clone that row and remove its content
        Row clonedRow = (Row)row.Clone(true);
        foreach (Cell cell in clonedRow)
        {
            cell.RemoveAllChildren();
            cell.EnsureMinimum();
        }

        // add cloned row multiple times after the original row
        for (int i = 0; i < 5; i++)
        {
            Row clone = (Row)clonedRow.Clone(true);
            // Fill row with some values
            int j = 0;
            foreach (Cell cell in clone)
            {
                builder.MoveTo(cell.FirstParagraph);
                builder.Write("Row " + i + " Cell " + j);
                j++;
            }

            row.ParentTable.InsertAfter(clone, row);
        }
    }
}

doc.Save("E:\\Temp\\20.6.docx");