Problem with Header. Cant update field


#1

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

A similar problem is in this post.

http://www.aspose.com/forums/ShowPost.aspx?PostID=7719

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.


/Anders


#2
  1. 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.

    2. 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.

    3. 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.

    4. 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.

#3

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.


#4

Hello

Thanks for the fast replay.

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.

/Anders


#5

Hi Anders,

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.


#6

thanks a lot. Looking forward to this…


#7

Hello
are there any progress going on this topic?
We are soo needing this…


#8

Hi,

Aspose.Word 1.9 is out that allows to move the cursor into header or footer and add content there.

See DocumentBuilder.MoveToSection and MoveToHeaderFooter.


#9

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.

/Please help us
/Anders


#10

Sure, we still plan to try and support bookmarks in headers and footers.

If we cannot modify just a field in the header, I thought maybe you can recreate the whole header each time you check in the document?


#11

Sorry to say, but this dosnt help us.

We are hoping on that you can support bookmarks in Headers and Footers soon!

/Best regards
/Anders


#12

Hello
Sorry for pushing but are there any chance that you are going to support our needs in the nearest future.

sorry but all we need is to get this to work and then we are going to buy a lot of license from you.

/Anders


#13

Aspose.Word 1.9.5 is available that supports bookmarks in headers and footers and also supports retrieving text from the bookmark Bookmark.Text.

http://www.aspose.com/blogs/roman.korchagin/category/31.aspx


#14

Hello
It seems like we are on the way Smile

One problem
I do this

Aspose.Word.Document doc = word.Open(filename);

DocumentBuilder builder = new DocumentBuilder(doc);

builder.MoveToBookmark(“Author”);

builder.Write(“Anders”);
File.Delete(filename);

doc.Save(filename);

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


/Thanks a lot
/Anders


#15

I’ll try to add a way to delete bookmark text. It is technically difficult in some scenarios, but it will probably work okay for your.

The weird text is our new addition to evaluation version watermarks.


#16

Okej, great.
Seems like everything will work out for us if you add a delete function.


#17

Hello
I know you have much to do, bur do you think you will be abel to implement a delete function for the text in the bookmarks soon.

The time is running out for us.
/Anders


#18

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 http://www.aspose.com/blogs/roman.korchagin/archive/2004/11/23/257.aspx


#19

Great.
It works perfect. The only thing I dont get is the wierd text (like

T6)^za or something else) that sometimes get inserted in the document aswell. Is this only because we dont run a licensed copy.


#20

Yes, random chars are part of evaluation watermark. They were added recently.