We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy.
Unfortunately, activation email could not send to your email. Please try again.

Filling text form fields identified by bookmarks

Thread ID:

Created:

Updated:

Platform:

Replies:

119062 May 7,2015 08:43 PM May 20,2015 12:28 AM WPF 6
loading
Tags: DocIO
Igor
Asked On May 7, 2015 08:43 PM

Hi,

I am really new to Syncfusion DOCIO, and tried to find info in this forum but with no luck.
Here is my problem:
I have a word template file with text form fields identified with bookmark names as placeholders for my data, but I am having problems filling them.
I tried to use BookmarksNavigator as a fast way to find a form field, and fill it with my data but it doesn't work as I expected.
If I use InsertText, the data is appended to the end of the form field not replacing it.
I tried with ReplaceBookmarkContent also, but I am getting index out of range error.
Obviously, I am missing something...


Divyalakshmi Vasudevan [Syncfusion]
Replied On May 8, 2015 04:43 AM

Hi Igor,

Thank you for your interest in Syncfusion Products.

On further analyzing your requirement, you can also fill your data in the text form field text by using Text property of WTextFormField. Text property is used to set the text of the text form field. Kindly make use of below code snippet to update the text value to the text form field in order to meet your requirement .
Code snippet:
formfield.Text = "Fill your data";

Kindly refer the below UG documentation link to get more information on WTextFormField:


http://help.syncfusion.com/ug/wpf/Documents/text2.htm

Please let us know in case of any other questions.

Regards,
Divyalakshmi V



Igor
Replied On May 8, 2015 11:08 AM

Hi,

I know that I can set the value of the form field with
formfield.Text = "Fill your data";


But, sorry for my ignorance as all of this is very new for me, what I don't know is how to get the formfield from the bookmark I found with the BookmarksNavigator.
Something like:
formfield = bm.Something()

Thx

Divyalakshmi Vasudevan [Syncfusion]
Replied On May 11, 2015 04:41 AM



Hi Igor,

Thank you for your update.

We have prepared the sample to achieve your requirement to identify the TextFormField using Bookmark by iterating the TextBodyPart items from BookmarkNavigator.
Please do find the sample from the below link. Try running this sample and let us know if this helps you.
http://www.syncfusion.com/downloads/support/forum/119062/GenerateWord_WPF_Bookmark-1643418567.zip


You can also use the Public API to access TextFormField without using Bookmark which is more preferable compared to iterating the TextBodyPart items from BookmarkNavigator. We have prepared the sample to illustrate the same. Please do find the sample from the below link.
http://www.syncfusion.com/downloads/support/forum/119062/GenerateWord_WPF-278250223.zip


Please let us know in case of any concern
Regards,
Divyalakshmi V


Divyalakshmi Vasudevan [Syncfusion]
Replied On May 11, 2015 02:46 PM

Hi Igor,

Kindly ignore our previous update.

Regarding Bookmark Navigator:

In order to meet your requirement with Bookmark navigator, the following steps are need to be follow in your sample.

1. Load the template document

2. Create a Bookmark navigator

3. Navigate to the corresponding bookmark which has the TextFormField.

4. Get the bookmark content as TextBodyPart using GetBookmarkContent() method of BookmarkNavigator.

5. Update TextFormField text by iterating the text form field from the TextBodyPart of the bookmark content.

6. Replace the bookmark content again to the document with updated TextBodyPart contents.

7. Save the Word document to the file system.
Currently we are having an ArgumentOutOfRange Exception issue with the above steps using BookmarkNavigator and the fix for this issue will be included in our 2015 Volume 2 release which will be available in end of June, 2015. In order to meet your requirement, kindly make use of FormFields collection from TextBody class to get and update the particular form field data into the Word document without using BookmarkNavigator which is more preferable compared to iterating the TextBodyPart items from BookmarkNavigator. We have prepared the sample to illustrate the same. Please do find the sample from the below link.

Sample link:
http://www.syncfusion.com/downloads/support/forum/119062/GenerateWord_WPF-735354883.zip


Please let us know in case of any other questions.

Regards,
Divyalakshmi V



Igor
Replied On May 18, 2015 03:22 AM

Hi Divyalakshmi,

Sorry for the late answer, was away for a few days.

You last comment/sample made me reconsider my logic of filling the form fields, so I changed the logic to use the FormFields collection, based on your last sample.
My first tests show its working great. Thanks.


Ayswarya Krishna Kumar [Syncfusion]
Replied On May 20, 2015 12:28 AM

Hi Igor,

Thank you for updating us.

Let us know if you have any other questions.

Regards,

Ayswarya



CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.

;