1
votes

I want to create a word document with many bookmarks. The bookmarks contains some price information that needs to be updated every year. I need to update them based on value from a database in a certain order. How do i create a bookmark with a bookmark ID or in a particular order for word?? Whats the guarantee that when i read bookmarks from c# using word object model, it will be retrieved in the same order in which it was created?

Edited: The contents of the word document is broken down by columns and each column has many bookmarks to it. I can name bookmarks by bm1c1,bm2c1.., bm1c2,bm2c2 etc...but when bookmarks are read from C#, its reading from bm1c1,bm1c2..etc.....where c1 and c2 represent column info...I want to read bookmarks in the order for a particular column, because the data i am going to replace is coming from a query that has a specific order..So if i can associate a bookmark with a specific id, then i thought it might help...I cant find a way to add a bookmark with specific id...

On further thoughts..i think i could do something like this..locate the relevant bookmark and update it..

                Object name = bmrk.Name; //this could be bm1c1 or whatever appropriate

                Microsoft.Office.Interop.Word.Range rng = doc.Bookmarks.get_Item(ref name).Range;
                rng.Text = "197.00";
                Object range = rng;
                doc.Bookmarks.Add(bmrk.Name, ref range);

but the problem with this is, if tomorrow i need to add a new bookmark in between two other existing bookmarks, it messes up the order..so if i can specify an id then i maybe able to use that to maintain the order

Thanks

1
others will be able to help you if you can share your findings and any code that you have written.Sandeep G B

1 Answers

0
votes

The word help system tells you how to create the bookmarks inside word, or , do you want to create the bookmarks from c#?

I do not follow you about the order, if you locate one of them somewhere and you call it bm1 it will always be there and if you loop on all of them and get it you can assign or render some text no matter in which order you got there. You edit your question with more details and I edit my answer :-)