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

Free Support Forum - aspose.com

Remove SET

Hi There,

I am trying to remove SET fields from my word document.

It removes if SET field is a single line of text.

It is not removing if SET field is a multi line of text (Paragraphs or Table in it).

I have attached my test project for your reference. I am using 14.5.0.0 version of Aspose.Words.dll

Thanks for your help in advance.

  • John

Hi John,

Thanks for your inquiry. Please use the Field.Remove method to remove the field from the document. See the following highlighted code below. Please let us know if you have any more queries.


List<Person> persons = new List<Person>();

persons.Add(new Person

{

Name = "John Done",

Age = "35",

Address = "123 Main St, Houston, TX 77002"

});

persons.Add(new Person

{

Name = "Bill Gates",

Age = "65",

Address = "8484 59 Hwy, Houston, TX 77002"

});

persons.Add(new Person

{

Name = "Will Smith",

Age = "45",

Address = "95959 Hollywood St, Houston, TX 77002"

});

var dt = new DataTable("Person");

dt.Columns.Add("Name");

dt.Columns.Add("Age");

dt.Columns.Add("Address");

foreach (var item in persons)

{

var dr = dt.NewRow();

dr[0] = item.Name;

dr[1] = item.Age;

dr[2] = item.Address;

dt.Rows.Add(dr);

}

DataSet ds = new DataSet();

ds.Tables.Add(dt);

Document doc = new Document(MyDir + "TableSet.docx");

doc.MailMerge.ExecuteWithRegions(ds);

NodeCollection starts = doc.GetChildNodes(NodeType.FieldStart, true);

//Loop though all field starts

foreach (FieldStart start in starts)

{

if (start.FieldType == FieldType.FieldSet)

{

start.GetField().Remove();

}

}

//Remove SET Fields

//RemoveUnwantedField(doc, FieldType.FieldSet);

doc.UpdateFields();

doc.Save(MyDir + "TableSet - Output.docx");


Awesome!
Thank you Tahir.. That worked.



Hi John,

Thanks for your feedback. Please feel free to ask if you have any question about Aspose.Words, we will be happy to help you.