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

Free Support Forum - aspose.com

Aspose words preserve format Ref Field

Hi,


I am building a clean document for my client, for that reason I want to remove SET and REF once I am done processing the document.

I am able to remove SET and REF but I am not able to preserve the format of REF field.

Here, 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 FieldsHelper.ConvertFieldsToStaticText method to achieve your requirement. Please check the code of FieldsHelper class in the following article:
http://www.aspose.com/docs/display/wordsnet/How+to++Replace+Fields+with+Static+Text


// Your code...

// ....

DataSet ds = new DataSet();

ds.Tables.Add(dt);

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

doc.MailMerge.ExecuteWithRegions(ds);

// Pass the appropriate parameters to convert all IF fields encountered in the document (including headers and footers) to static text.

FieldsHelper.ConvertFieldsToStaticText(doc, FieldType.FieldRef);

//Remove SET fields

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

foreach (FieldStart start in starts)

{

if (start.FieldType == FieldType.FieldSet)

{

start.GetField().Remove();

}

}

doc.UpdateFields();

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


Thanks Tahir! That was 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.