How update Fields from referenced Bookmarks?

Technical support for Spire.Doc

Moderator: iceblue support

How update Fields from referenced Bookmarks?

Postby sklaiber » Wed Feb 22, 2012 9:33 pm

Hello. My Word template has many Bookmarks and many Fields which are related to those Bookmarks. I have figured out how to use the "ReplaceBookmarkContent()" method in order to set the content of the Bookmarks, but now I do not know how to update the related Fields with the same content. It was just a simple document.Fields.Update() call when I used the Microsoft Word API, but I cannot for the life of me see how to do it using Spire.Doc API.

I see there's a property "IsUpdateFields" on "document". What does that do? If I set to true, what do I do next to actually update the fields?

Any suggestions? Thank you in advance!
sklaiber
 
Posts: 5
Joined: Mon Feb 20, 2012 7:34 pm

Re: How update Fields from referenced Bookmarks?

Postby Suvi.Wu » Thu Feb 23, 2012 8:32 am

Hello sklaiber,

Thanks for evaluating Spire.Doc.

We attached you a sample demonstrates how to update the related Fields with the same content. Please have a look.

Hoing for it can help you.

If you still have this question,please send us your doc file to help ue better resolve it.

Have a great day.

BR
Suvi
e-iceblue support
You do not have the required permissions to view the files attached to this post.
User avatar
Suvi.Wu
 
Posts: 156
Joined: Thu Oct 20, 2011 2:53 am

Re: How update Fields from referenced Bookmarks?

Postby sklaiber » Thu Feb 23, 2012 5:06 pm

Dear Suvi, thank you very much for the code sample. However this doesn't work for me, since the Fields in my document do not have names; they are merely cross-references to existing Bookmarks in the document. Is there a method to update fields that reference bookmarks? I will continue searching the Spire.Doc API documentation, but I hope you can help me with this. Thank you very much.
You do not have the required permissions to view the files attached to this post.
sklaiber
 
Posts: 5
Joined: Mon Feb 20, 2012 7:34 pm

Re: How update Fields from referenced Bookmarks?

Postby Suvi.Wu » Fri Feb 24, 2012 2:22 am

Hi sklaiber,

Thanks for your feedback and the doc template, it helps us a lot.

If you want to update the related field using the content of the bookmark, you can use a BookmarksNavigator to navigate the bookmark,and then replace the content of the bookmark using the method "navigator.ReplaceBookmarkContent(the content you want to place,true)". I also attached a demo in which I updated the field using the related bookmark's comtent. Hoping this is what you want.

If you still have any other problems,please don't hesitate to contact us at any time.
Have a nice day.

BR
Suvi
e-iceblue support
You do not have the required permissions to view the files attached to this post.
User avatar
Suvi.Wu
 
Posts: 156
Joined: Thu Oct 20, 2011 2:53 am

Re: How update Fields from referenced Bookmarks?

Postby sklaiber » Fri Feb 24, 2012 4:03 pm

Hi, Suvi. I'm glad you used my file, because now we can be specific. Your code here loops through just the Bookmarks in my file, replacing their content. That is not what I am asking help for. Let me try to explain better:

The very first Bookmark (named "NameSchoolDist") is on Page 1 of my file, found immediately below the line "On behalf of:". Now, there are 2 REF Fields on Page 2 that I would like to figure out how to have them update to display the exact same content of the "NameSchoolDist" Bookmark. As you can see in your result.doc file, these 2 fields still read "NameSchoolDist" when I would expect them to read "Contentof the bookmark[0]" after being updated (but updated how???). These fields have a FieldType of "FieldRef" which means they reference something else in the document, which in my document, they happen to reference a Bookmark. In fact, if you right-click on either of these Fields, you will get a pop-up menu (at least I do while using Word 2007) and you can "Update Field" or "Edit Field..." or "Toggle Field Codes". So, if you choose to "Update Field" the content WILL update to read "Contentof the bookmark[0]", but I want my code to do this automatically, as a last step before saving the document.

I know that if a user does a Print Preview of this document, all referenced fields DO get updated nicely, but there has to be a way to update all referenced fields automatically (via code).

Again, my question is: How do I update fields that reference bookmarks? Using the Word API, this was done simply by "selecting" the entire document, and then calling an Update() method, as such:

Code: Select all
objWord.Selection.WholeStory();  // Select the entire document.
objDoc.Fields.Update();    // Update all Word Fields that are linked to the Word Bookmarks.
objWord.Selection.Collapse();     // De-select entire document; returning to beginning.


Also, here's an example of how to do it using VBA macro within Word:

Code: Select all
 Dim aStory As Range
        Dim aField As Field
        For Each aStory In ActiveDocument.StoryRanges
           For Each aField In aStory.Fields
              aField.Update
           Next aField
        Next aStory


Again, I see by reading the Spire.Doc API documentation that there's a property called "IsUpdateFields" on "document". What does that do? If I set to true, what do I do next to actually update the fields?
Thank you!
sklaiber
 
Posts: 5
Joined: Mon Feb 20, 2012 7:34 pm

Re: How update Fields from referenced Bookmarks?

Postby Suvi.Wu » Mon Feb 27, 2012 8:38 am

Hi sklaiber,

Thanks for your feedback and sorry for the inconvenience caused by us.

So sorry that our product doesn't support this feature at this stage. At present, Spire.Doc can only support formField and mergeField.We will consider adding the field in our future upgrade. Have a gerat day!

Sorry again.

BR
Suvi
e-iceblue support
User avatar
Suvi.Wu
 
Posts: 156
Joined: Thu Oct 20, 2011 2:53 am

Re: How update Fields from referenced Bookmarks?

Postby sklaiber » Tue Feb 28, 2012 4:18 pm

OK, thank you, Suvi.
sklaiber
 
Posts: 5
Joined: Mon Feb 20, 2012 7:34 pm


Return to Spire.Doc

Who is online

Users browsing this forum: No registered users and 0 guests

cron