We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Can I add an Index?

Yes - I'm the same guy who asked last Thursday if a TOC can be built. Many thanks to Aspose Support for quickly showing me how.

Nex Question - My users were used to an option of a TOC or an index. I see there is a a FIELDINDEX but I cannot find examples of it's useage. So...is there a way for me to build an Index in a Word document?



Thanks for your inquiry. Yes, of course you can do this using INDEX field. I think that the following code snippet could be useful for you.

Document doc = new Document();

DocumentBuilder builder = new DocumentBuilder(doc);

//Insert INDEX field

builder.InsertField("INDEX \\e \"\t\"", "");

//Insert paragraph break


//Insert XE field

builder.InsertField("XE \"First entry\"", "");

//Write text

builder.Writeln("First entry");

builder.InsertField("XE \"Second entry\"", "");

builder.Writeln("Second entry");

builder.InsertField("XE \"Third entry\"", "");

builder.Writeln("Third entry");

//Save document


Also don’t forget to update field in the document (ctrl+A and F9).

Best regards.

Thanks Alexey.

I took the example and worked it into my VB.NET application. For the benefit of those interested, here is a translated VB example. "strWrite" is a variable containing my string to index. Note that the "\" options are different. You can experiment with any valid values. A Google search gives you many sites that explain how to build this string value.

Dim doc As Aspose.Words.Document = New Aspose.Words.Document()

Dim Builder As DocumentBuilder = New DocumentBuilder(doc)

Builder.InsertField("INDEX \e "" ""\h ""A""\c ""1""", "")

Builder.InsertField("XE \" & strWrite & "\", "")