Hello
I have a webapplication that should fill in the Header and Footer with information.
It can be done by updating document properties. When the user changes and saves the record in the database the application updates custom properties in the word document. The problem is that when the user opens the word document he cannot see that the values of the fields have changed before he right-clicks on the grey fields to update them
Is there a soloution on this problem or maybe it cant be done?
I try with Bookmarks.
I added a bookmark “MyBookmark” then i do this
Aspose.Word.Word word = new Aspose.Word.Word();
Aspose.Word.Document doc = word.Open(filename);
DocumentBuilder builder = new DocumentBuilder(doc);
builder.MoveToBookmark("MyBookmark");
builder.Font.ClearFormatting();
builder.Font.Italic = true;
builder.StartBookmark("MyBookmark");
builder.Writeln(Revision);
builder.EndBookmark("MyBookmark");
doc.Save(filename);
Now when I look at the file it has written my “Revision” in the header but the bookmarks are not there. But I use StartBookmark(“MyBookmark”). Why isnt this saved in the document. I tried with differentnames on the bookmark, but it dosent help.
Aspose.Word cannot calculate and update field values. MS Word does not do this unless you print the document or update the fields explicitly. There is no other way I know of to update field values. In the future, Aspose.Word might be able to calculate and update values of some fields, but that’s some time in the future.
Using a bookmark to navigate there and insert text to avoid using a field is a good idea. But as it turns out, use of bookmarks in headers is not documented in MS Word file format and therefore Aspose.Word does not support it. Only bookmarks in the main document are supported at the moment. I will add this onto our task list and we will try to support bookmarks in the headers and footers, but that’s not guaranteed.
We also have plans to implement objects like Range in MS Word Object Model that allow easy navigation into any place in the document and inserting/deleting text there.
We are working on a feature that allows to create headers and footers in the document using DocumentBuilder. This will be released in October and might be useful to you.
Sorry if we cannot help you now. We also wish Aspose.Word supported all those features and we are working hard on it.
The way to update information in the header or footer now is to place a merge field (one or more) in the header or footer. Don’t execute mail merge for those fields, but use DocumentBuilder.MoveToMergeField and then other DocumentBuilder methods to insert content there. The field will be automatically deleted by DocumentBuilder.
The new feature of being able to simply navigate DocumentBuilder to header or footer without this workaround with merge fields should be available next week.
I cant see how this helps my problem but maybe Im missing something.
The problem we have is that we have a document and a User can Check it out and edit it. And when he check in the document again a new Edition of the document should be created. So in the Header I need an Edition number to be updated.
If a person has a template with merge field in the header. When he upload it. It will get the “Edition 1” inserted in the merge field. Someone check out the document and edit the contents in the document. The problem is now that in the header it say “Edition 1”. Thats right but its not a merge field any moore so when this person check in the document and we are going to update the edition to “Edition 2” there is no merge field to navigate to.
Hope you understand what we want.
I couldnt find a replaybutton in the forum so I writing to you here again.
Thanks, now I understand the issue. You are right, in your case the solution I proposed does not work well because DocumentBuilder removes the merge field but you need it over and over again.
The problem is complicated by the fact that you need to replace the existing edition number and replacing or deleting text is not yet possible with Aspose.Word.
I will make sure we have some features that allow to do what you want soon. I will post progress in this forum.
I dont think moving into the header and footer help us.
you wrote…
“Using a bookmark to navigate there and insert text to avoid using a field is a good idea. But as it turns out, use of bookmarks in headers is not documented in MS Word file format and therefore Aspose.Word does not support it. Only bookmarks in the main document are supported at the moment. I will add this onto our task list and we will try to support bookmarks in the headers and footers, but that’s not guaranteed.”
Do you think you are going to support this. We must have something that we can navigate to and update the “edition number” in the header, each time the person “check in” the document.
the problem is that the second time i do this. The bookmark is there (thats right) but the name “Anders” is already there and when i insert a new builder.write(“Anders”) it is going to be a dublicate. How do I delete the text in the bookmark before I write the new text.
and if i do it twice it also insert som wierd text before the bookmark.
7.tW&]@ is the text
Please get latest Aspose.Word 1.9.8 as I added setter for Bookmark.Text. You can change bookmark text now, you can set to a string or empty string “”. If you want to insert formatted text, you still can use Document.MoveToBookmark after you set bookmark text to “”. Check release notes https://docs.aspose.com/words/net/release-notes/