//// This code is part of Document Solutions for Word demos.// Copyright (c) MESCIUS inc. All rights reserved.//usingSystem;usingSystem.Globalization;usingGrapeCity.Documents.Word;usingGrapeCity.Documents.Word.Fields;usingGrapeCity.Documents.Word.Layout; namespaceDsWordWeb.Demos{// This sample shows how to use the INDEX and XE field options// to add an index to a DOCX Word document.publicclassIndexFieldOpts {// For this demo, we arbitrarily pick some of the 'lorem ipsum' words to include in the index:privatestaticstring[] s_indexWords = {"lorem", "ipsum", "dolor", "sit", "amet", "consectetur", "adipiscing", "elit", "mauris", "id", "volutpat","tellus", "ullamcorper", "sem", "praesent", "et", "ante", "laoreet", "lobortis", "nunc", "congue", }; publicGcWordDocumentCreateDocx() {var doc = newGcWordDocument(); // Arbitrary number of sample paragraphs in the document:constintNPARS = 30;// We add some random "lorem ipsum" paragraphs to the document,// and build the index on the arbitrarily chosen subset of words,// including pages where the indexed word appears as the first// word in a paragraph:for (int i = 0; i < NPARS; ++i) {var par = doc.Body.Paragraphs.Add();var txt = Util.LoremIpsumPar(); var words = txt.Split([' ', ',', '.'], 2);if (words.Length != 2)thrownewException("Unexpected"); var word = words[0];var xe = newXeFieldOptions(doc); xe.Entry.Content.Text = word; par.AddComplexField(xe); par.AddRun(txt); }// Add new section for the index: doc.Body.Paragraphs.Last.AddSectionBreak();var p = doc.Body.Paragraphs.Add(doc.Styles[BuiltInStyleId.Index1]);// Set up INDEX field options:var index = newIndexFieldOptions(doc);// Two column layout: index.Columns = 2;// Use headings for index entries: index.Heading = "A";// Set any additional options as needed,// then create the INDEX field with the specified options:ComplexField field = p.AddComplexField(index); // Update the index field using a specific culture: field.Update(newWordLayoutSettings() { FontCollection = Util.FontCollection, Culture = CultureInfo.GetCultureInfo("en-US") }); // Done:return doc; } }}