Free Support Forum - aspose.com

Aspose.words 怎么判断当前插入的行在第几页

我有100行数据,不断的在word的表格中追加内容行,表格的行高不是固定的,怎么判断当前插入的行在文档的第几页

@summer0716,

您可以在行中插入PAGE字段,然后确定它们的值。 请尝试运行以下代码:

Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);

Table table = builder.StartTable();

for (int i = 1; i <= 100; i++)
{
    builder.InsertCell();
    FieldPage fieldPage = (FieldPage)builder.InsertField(FieldType.FieldPage, true);
    builder.Write("This is row " + i + " cell 1");

    builder.InsertCell();
    builder.Write("This is row " + i + " cell 2");

    builder.EndRow();
}

builder.EndTable();

doc.UpdatePageLayout();
doc.UpdateFields();

for (int i = 0; i < table.Rows.Count; i++)
{
    Console.WriteLine("Row {0} is on Page {1}", i, table.Rows[i].Range.Fields[0].Result);
    table.Rows[i].Range.Fields[0].Remove();
}

doc.Save("C:\\temp\\20.11.docx");