FieldXEText Property |
Namespace: Aspose.Words.Fields
Document doc = new Document(); DocumentBuilder builder = new DocumentBuilder(doc); // Create an index field which will contain all the index entries FieldIndex index = (FieldIndex)builder.InsertField(FieldType.FieldIndex, true); // Bookmark that will encompass a section that we want to index const string mainBookmarkName = "MainBookmark"; builder.StartBookmark(mainBookmarkName); index.BookmarkName = mainBookmarkName; index.CrossReferenceSeparator = ":"; index.Heading = ">"; index.LanguageId = "1033"; index.LetterRange = "a-j"; index.NumberOfColumns = "2"; index.PageNumberListSeparator = "|"; index.PageNumberSeparator = "|"; index.PageRangeSeparator = "/"; index.UseYomi = true; index.RunSubentriesOnSameLine = false; index.SequenceName = "Chapter"; index.SequenceSeparator = ":"; Assert.IsTrue(index.HasPageNumberSeparator); Assert.IsTrue(index.HasSequenceName); // Our index will take up page 1 builder.InsertBreak(BreakType.PageBreak); // Use a document builder to insert an index entry // Index entries are not added to the index manually, it will find them on its own FieldXE indexEntry = (FieldXE)builder.InsertField(FieldType.FieldIndexEntry, true); indexEntry.Text = "Index entry 1"; indexEntry.EntryType = "Type1"; indexEntry.IsBold = true; indexEntry.IsItalic = true; Assert.AreEqual(false, indexEntry.HasPageRangeBookmarkName); // We can insert a bookmark and have the index field point to it const string subBookmarkName = "MyBookmark"; builder.StartBookmark(subBookmarkName); builder.Writeln("Bookmark text contents."); builder.EndBookmark(subBookmarkName); // Put the bookmark and index entry field on different pages // Our index will use the page that the bookmark is on, not that of the index entry field, as the page number builder.InsertBreak(BreakType.PageBreak); indexEntry = (FieldXE)builder.InsertField(FieldType.FieldIndexEntry, true); indexEntry.Text = "Index entry 2"; indexEntry.EntryType = "Type1"; indexEntry.PageRangeBookmarkName = subBookmarkName; Assert.AreEqual(true, indexEntry.HasPageRangeBookmarkName); // We can use the PageNumberReplacement property to point to any page we want, even one that may not exist builder.InsertBreak(BreakType.PageBreak); indexEntry = (FieldXE)builder.InsertField(FieldType.FieldIndexEntry, true); indexEntry.Text = "Index entry 3"; indexEntry.EntryType = "Type1"; indexEntry.PageNumberReplacement = "999"; // If we are using an East Asian language, we can sort entries phonetically (using Furigana) instead of alphabetically indexEntry = (FieldXE)builder.InsertField(FieldType.FieldIndexEntry, true); indexEntry.Text = "漢字"; indexEntry.EntryType = "Type1"; // The Yomi field will contain the character looked up for sorting indexEntry.Yomi = "か"; // If we are sorting phonetically, we need to notify the index index.UseYomi = true; // For all our entry fields, we set the entry type to "Type1" // Our field index will not list those entries unless we set its entry type to that of the entries index.EntryType = "Type1"; builder.EndBookmark(mainBookmarkName); doc.UpdateFields(); doc.Save(ArtifactsDir + "Field.INDEX.XE.docx");