AODL.Document.Content.Text.Indexes.TableOfContents.InsertEntry C# (CSharp) Method

InsertEntry() public method

Insert the given text as an Table of contents entry. e.g. You just insert a Headline 1. My headline to the document and want this text also as an Table of contents entry, so you can simply add the text using this method.
public InsertEntry ( string textEntry, int outLineLevel ) : void
textEntry string The text entry.
outLineLevel int The outline level possible 1-10.
return void
		public void InsertEntry(string textEntry, int outLineLevel)
		{
			Paragraph paragraph				= new Paragraph(
				((TextDocument)this.Document), "P1_Toc_Entry"+outLineLevel.ToString());
			((ParagraphStyle)paragraph.Style).ParentStyle =
				this._contentStyleName+outLineLevel.ToString();
			if (this.UseHyperlinks)
			{
				int firstWhiteSpace			= textEntry.IndexOf(" ");
				System.Text.StringBuilder sb = new System.Text.StringBuilder(textEntry);
				sb							= sb.Remove(firstWhiteSpace, 1);
				string link					= "#"+sb.ToString()+"|outline";
				XLink xlink					= new XLink(this.Document, link, textEntry);
				xlink.XLinkType				= "simple";
				paragraph.TextContent.Add(xlink);
				paragraph.TextContent.Add(new TabStop(this.Document));
				paragraph.TextContent.Add(new SimpleText(this.Document, "1"));
			}
			else
			{
				//add the tabstop and the page number, the number is
				//always set to 1, but will be updated by the most
				//word processors immediately to the correct page number.
				paragraph.TextContent.Add(new SimpleText(this.Document, textEntry));
				paragraph.TextContent.Add(new TabStop(this.Document));
				paragraph.TextContent.Add(new SimpleText(this.Document, "1"));
			}
			//There is a bug which deny to add new simple ta
//			this.TitleParagraph.ParagraphStyle.ParagraphProperties.TabStopStyleCollection =
//				this.GetTabStopStyle(TabStopLeaderStyles.Dotted, ".", 16.999);
			paragraph.ParagraphStyle.ParagraphProperties.TabStopStyleCollection =
				this.GetTabStopStyle(TabStopLeaderStyles.Dotted, ".", 16.999);

			this.Content.Add(paragraph);
		}

Usage Example

Beispiel #1
0
		public void TableOfContentsTest()
		{
		//Create new Document
		TextDocument textDocument		= new TextDocument();
		textDocument.New();
		//Create a new Table of contents
		TableOfContents tableOfContents	= new TableOfContents(
			textDocument, "Table_Of_Contents", false, false, "Table of Contents");
		//Add the toc
		textDocument.Content.Add(tableOfContents);
		//Create a new heading, there's no need of the chapter number
		string sHeading					= "A first headline";
		//The corresponding text entry, here you need to set the
		//chapter number
		string sTocEntry				= "1. A first headline";
		Header header					= new Header(
			textDocument, Headings.Heading_20_1);
		header.OutLineLevel				= "1";
		header.TextContent.Add(new SimpleText(textDocument,  sHeading));
		//add the header to the content
		textDocument.Content.Add(header);
		//add the toc entry text as entry to the Table of contents
		tableOfContents.InsertEntry(sTocEntry, 1);
		//Add some text to this chapter
		Paragraph paragraph				= ParagraphBuilder.CreateStandardTextParagraph(textDocument);
		paragraph.TextContent.Add(new SimpleText(textDocument, "I'm the text for the first chapter!"));
		textDocument.Content.Add(paragraph);
		//Add a sub header to the first chapter
		//Create a new heading, there's no need of the chapter number
		sHeading						= "A first sub headline";
		//The corresponding text entry, here you need to set the
		//chapter number
		sTocEntry						= "1.1. A first sub headline";
		header							= new Header(
			textDocument, Headings.Heading_20_2);
		header.OutLineLevel				= "2";
		header.TextContent.Add(new SimpleText(textDocument,  sHeading));
		//add the header to the content
		textDocument.Content.Add(header);
		//add the toc entry text as entry to the Table of contents
		tableOfContents.InsertEntry(sTocEntry, 2);
		//Add some text to this sub chapter
			paragraph				= ParagraphBuilder.CreateStandardTextParagraph(textDocument);
			paragraph.TextContent.Add(new SimpleText(textDocument, "I'm the text for the subchapter chapter!"));
		textDocument.Content.Add(paragraph);
//		ListStyle listStyle				= new ListStyle(textDocument, "TOC_LIST");
//		listStyle.AutomaticAddListLevelStyles(ListStyles.Number);
//		textDocument.Styles.Add(listStyle);
		//Save it
		textDocument.SaveTo(AARunMeFirstAndOnce.outPutFolder+"toc.odt");
		}