Unlink Fields (Form Fields)

Hi,

In Word you can use

Selection.WholeStory

Selection.Fields.Unlink

to remove all Form Fields from a document. Is there an equivalent in Aspose Words (4.0.2.0) please? I've tried the documentation with no success.

Cheers

Adrian

Hi Adrian,

It occupies 2 times less lines of code Smile [:)]

doc.Range.FormFields.Clear();

Hi Dmitry,

doc.Range.FormFields.Clear() is great but it also removes the text within the FormField which is not quite the effect we were seeking. Fields.Unlink removes the FormFields but leaves the text they contained on the screen. Thats the function we after.

Thanks

Adrian

Hmm it will be slightly harder then... Please try the following code:

[TestMethod]

public void TestRemoveFormField()

{

Document doc = TestUtil.Open("TestRemoveFormField.doc");

NodeList fieldStarts = doc.SelectNodes("//FieldStart");

foreach (FieldStart fieldStart in fieldStarts)

{

switch (fieldStart.FieldType)

{

case FieldType.FieldFormCheckBox:

case FieldType.FieldFormTextInput:

case FieldType.FieldFormDropDown:

RemoveFormField(fieldStart);

break;

}

}

TestUtil.SaveShow(doc, "TestRemoveFormField Out.doc");

}

private void RemoveFormField(FieldStart fieldStart)

{

bool isInFieldResult = false;

Node node = fieldStart;

Node nextSibling = null;

while (true)

{

nextSibling = node.NextSibling;

if ((node.NodeType == NodeType.BookmarkStart) && (node.NodeType == NodeType.BookmarkEnd))

{

node = nextSibling;

continue;

}

if (node.NodeType == NodeType.FieldSeparator)

isInFieldResult = true;

if (!isInFieldResult || (node.NodeType != NodeType.Run))

node.Remove();

if (node.NodeType == NodeType.FieldEnd)

break;

if (nextSibling != null)

{

node = nextSibling;

}

else

{

CompositeNode nodeParentSibling = (CompositeNode)node.ParentNode.NextSibling;

node = nodeParentSibling.FirstChild;

while (node == null)

{

nodeParentSibling = (CompositeNode)nodeParentSibling.NextSibling;

node = nodeParentSibling.FirstChild;

}

}

}

}

Keep me posted if it works.

Excellent stuff! That works perfectly (had to put RemoveFormField(fieldStart); etc under FieldType.FieldFormTextInput: as well). Many thanks for the help. You guys have to be the most responsive and knowledgeable support team I've ever used.

Thanks again

Adrian

The issues you have found earlier (filed as WORDSNET-976) have been fixed in this Aspose.Words for .NET 16.10.0 update and this Aspose.Words for Java 16.10.0 update.


This message was posted using Notification2Forum from Downloads module by aspose.notifier.
(7)