Remove Result from FormField in a way that it behaves as if it was just created in word

Dear support,

in our application we receive word documents that contain text input FormFields. We access those fields, read the result value and set the result value to empty.

Reading the Result value works fine. But setting the Result to String.Empty does not behave in the same way as a form field that was just created.

Just for reference, a new form field looks like this in word document [ooooo] and when the document is protected and you click in the field then the whole area gets selected. When typing the empty characters vanish.

In my case (setting the Result to String.Empty) the form field looks like this ][ and the user cannot click into it.

This is how a new empty form field looks in the document.xml from a word document:

<w:fldChar w:fldCharType="begin">
	<w:ffData>
		<w:name w:val="Text3" />
		<w:enabled />
		<w:calcOnExit w:val="0" />
		<w:textInput />
	</w:ffData>
</w:fldChar>
</w:r>
<w:bookmarkStart w:id="2" w:name="Text3" />
<w:r>
	<w:instrText xml:space="preserve">FORMTEXT </w:instrText>
</w:r>
<w:r>
	<w:fldChar w:fldCharType="separate" />
</w:r>
<w:r w:rsidR="00F44A52">
	<w:t> </w:t>
</w:r>
<w:r w:rsidR="00F44A52">
	<w:t> </w:t>
</w:r>
<w:r w:rsidR="00F44A52">
	<w:t> </w:t>
</w:r>
<w:r w:rsidR="00F44A52">
	<w:t> </w:t>
</w:r>
<w:r w:rsidR="00F44A52">
	<w:t> </w:t>
</w:r>
<w:r>
	<w:fldChar w:fldCharType="end" />

You can see that there are 5 empty characters (hex code 2002) in separate runs.

Is there a way in Aspose to remove the Result from a FormField and make it so that word behaves as if the field was a new empty FormField?

We are using .net 4.0 and Aspose.Words 11.4.0.0.

This is how the code looks like:

FormFieldCollection formFields = doc.Range.FormFields;
foreach(FormField formField in formFields)
{
    string res = formField.Result;
    formField.Result = String.Empty;
}

Thank you
Bernd

Hi Bernd,

Thanks for your inquiry. I am working over your query and will get back to you soon.

Best regards,

Hi Bernd,

Thanks for being patient. You can simply achieve this by using the following code:

Document doc = new Document(@"C:\Temp\FormFields.docx");
FormFieldCollection formFields = doc.Range.FormFields;
foreach(FormField formField in formFields)
{
    formField.Result = "\u2002\u2002\u2002\u2002\u2002";
}
doc.Save(@"C:\Temp\out.docx");

I hope, this helps.

Best regards,

Thank you for your answer.

This is a step in the right direction, but it does not solve the issue completly.

The result of your approach is that the “look” is now the same between our processed form field and a new empty one.

But the “feel” is still different for the user. It would be nice if they behaved exactly the same.

Attached is another word file that demonstrates the issue:
When clicking in the processed field the cursor will jump to the point. When clicking in a new empty field the whole empty area gets selected.

I fear that our customers might be irritated by the different behaviour…

When iterating over the fields, is there a way to remove the field and insert a field at the same spot without changing the layout of the document? Maybe that would be an approach to solve the issue.

Hi Bernd,

Thanks for the additional information. I am checking with this scenario and will get back to you soon.

Best regards,

Hi Bernd,

Thanks for being patient. We have logged a new feature request to write an empty value to form fields in the same way like Microsoft Word does. Your request has been linked to the appropriate issue (WORDSNET-9567) and you will be notified as soon as it is supported. Sorry for the inconvenience.

Best regards,

The issues you have found earlier (filed as WORDSNET-9567) have been fixed in this .NET update and this Java update.

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