Clear
FieldCollection.Clear method
从文档和此集合本身中删除此集合的所有字段。
public void Clear()
例子
展示如何从字段集合中删除字段。
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
builder.InsertField(" DATE \\@ \"dddd, d MMMM yyyy\" ");
builder.InsertField(" TIME ");
builder.InsertField(" REVNUM ");
builder.InsertField(" AUTHOR \"John Doe\" ");
builder.InsertField(" SUBJECT \"My Subject\" ");
builder.InsertField(" QUOTE \"Hello world!\" ");
doc.UpdateFields();
FieldCollection fields = doc.Range.Fields;
Assert.AreEqual(6, fields.Count);
// 以下是从字段集合中删除字段的四种方法。
// 1 - 获取要删除的字段:
fields[0].Remove();
Assert.AreEqual(5, fields.Count);
// 2 - 获取要删除的字段的集合,并将其传递给其删除方法:
Field lastField = fields[3];
fields.Remove(lastField);
Assert.AreEqual(4, fields.Count);
// 3 - 从集合中移除索引处的字段:
fields.RemoveAt(2);
Assert.AreEqual(3, fields.Count);
// 4 - 一次性从集合中删除所有字段:
fields.Clear();
Assert.AreEqual(0, fields.Count);
也可以看看
- class FieldCollection
- 命名空间 Aspose.Words.Fields
- 部件 Aspose.Words