AutoNumbering


#1

Hello, I am utilizing bookmarks to try and add new "autonumber" sections to my word document.

Here is an example of what I am trying to do:

A. This section already exists.

B. This section also already exists.

C. This section exists.

D. This is a bookmark, which I will hide if I don't want anything

As you can see, A,B,C will always be in my document, but I am not sure if D should be added until runtime. So I have created the autonumber section D in my word document, and will set the book mark text="" if I don't want it.

However, when I set the bookmark text = "", it still leaves the autonumber D. in the generated document. And if I try and set the bookmark to include the line above D. - it gives me a runtime error about a node being null.

Please, can someone give me a workaround for this situation?!?!? Help! ;)

Thanks!

Brian


#2

We could help you better if you send us the templates and code snippets that you are currently using.


#3

I have attached the code snippet and document that I am using.

Thanks!


#4

Try adding the following lines to your code

DocumentBuilder builder = new DocumentBuilder(doc);

if (DynamicDealFeesSectionsAdded < 1)

{

Bookmark bk = doc.Range.Bookmarks["F_Disburse"];

bk.Text = "";

Bookmark bk2 = doc.Range.Bookmarks["G_Disburse"];

bk2.Text = "";

builder.MoveToBookmark("F_Disburse", true, false);

builder.CurrentParagraph.Remove();

builder.MoveToBookmark("G_Disburse", true, false);

builder.CurrentParagraph.Remove();

}

Instead of

if (DynamicDealFeesSectionsAdded < 1)

{

Bookmark bk = doc.Range.Bookmarks["F_Disburse"];

bk.Text = "";

Bookmark bk2 = doc.Range.Bookmarks["G_Disburse"];

bk2.Text = "";

}


#5

Thanks for the feedback! However, when I went to try it out, I discovered that my version of Aspose DocumentBuilder class doesn't have an exposed definition for the CurrentParagraph

I am using the Aspose Word version 3.1.0.0 Runtime Version 1.1.4322

Should I be using some other method/member or do I need another version of the software?

thanks!


#6

We generally recommend upgrading to the latest version of the library whenever possible. If your subscription has not expired yet you will be able to upgrade freely.

Please mind that we have changed the product name. So you will need to change namespace names from Aspose.Word to Aspose.Words everywhere in the project.