本文整理汇总了C#中DocumentBuilder.InsertTableOfContents方法的典型用法代码示例。如果您正苦于以下问题:C# DocumentBuilder.InsertTableOfContents方法的具体用法?C# DocumentBuilder.InsertTableOfContents怎么用?C# DocumentBuilder.InsertTableOfContents使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DocumentBuilder
的用法示例。
在下文中一共展示了DocumentBuilder.InsertTableOfContents方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Main
static void Main(string[] args)
{
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
// Insert a table of contents at the beginning of the document.
builder.InsertTableOfContents("\\o \"1-3\" \\h \\z \\u");
// The newly inserted table of contents will be initially empty.
// It needs to be populated by updating the fields in the document.
doc.UpdateFields();
}
示例2: Run
public static void Run()
{
// ExStart:DocumentBuilderInsertTOC
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_WorkingWithDocument();
// Initialize document.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
// Insert a table of contents at the beginning of the document.
builder.InsertTableOfContents("\\o \"1-3\" \\h \\z \\u");
// The newly inserted table of contents will be initially empty.
// It needs to be populated by updating the fields in the document.
// ExStart:UpdateFields
doc.UpdateFields();
// ExEnd:UpdateFields
dataDir = dataDir + "DocumentBuilderInsertTOC_out.doc";
doc.Save(dataDir);
// ExEnd:DocumentBuilderInsertTOC
Console.WriteLine("\nTable of contents field inserted successfully into a document.\nFile saved at " + dataDir);
}
示例3: InsertTableOfContents
public static void InsertTableOfContents(string dataDir)
{
// ExStart:DocumentBuilderInsertTableOfContents
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
// Insert a table of contents at the beginning of the document.
builder.InsertTableOfContents("\\o \"1-3\" \\h \\z \\u");
// Start the actual document content on the second page.
builder.InsertBreak(BreakType.PageBreak);
// Build a document with complex structure by applying different heading styles thus creating TOC entries.
builder.ParagraphFormat.StyleIdentifier = StyleIdentifier.Heading1;
builder.Writeln("Heading 1");
builder.ParagraphFormat.StyleIdentifier = StyleIdentifier.Heading2;
builder.Writeln("Heading 1.1");
builder.Writeln("Heading 1.2");
builder.ParagraphFormat.StyleIdentifier = StyleIdentifier.Heading1;
builder.Writeln("Heading 2");
builder.Writeln("Heading 3");
builder.ParagraphFormat.StyleIdentifier = StyleIdentifier.Heading2;
builder.Writeln("Heading 3.1");
builder.ParagraphFormat.StyleIdentifier = StyleIdentifier.Heading3;
builder.Writeln("Heading 3.1.1");
builder.Writeln("Heading 3.1.2");
builder.Writeln("Heading 3.1.3");
builder.ParagraphFormat.StyleIdentifier = StyleIdentifier.Heading2;
builder.Writeln("Heading 3.2");
builder.Writeln("Heading 3.3");
doc.UpdateFields();
dataDir = dataDir + "DocumentBuilderInsertTableOfContents_out.doc";
doc.Save(dataDir);
// ExEnd:DocumentBuilderInsertTableOfContents
Console.WriteLine("\nTable of contents using DocumentBuilder inserted successfully into a document.\nFile saved at " + dataDir);
}
示例4: DocumentBuilderInsertTOC
public void DocumentBuilderInsertTOC()
{
//ExStart
//ExId:DocumentBuilderInsertTOC
//ExSummary:Shows how to insert a Table of Contents field into a document.
Aspose.Words.Document doc = new Aspose.Words.Document();
DocumentBuilder builder = new DocumentBuilder(doc);
// Insert a table of contents at the beginning of the document.
builder.InsertTableOfContents("\\o \"1-3\" \\h \\z \\u");
// The newly inserted table of contents will be initially empty.
// It needs to be populated by updating the fields in the document.
doc.UpdateFields();
//ExEnd
}
示例5: InsertToc
public void InsertToc()
{
//ExStart
//ExFor:DocumentBuilder.InsertTableOfContents
//ExFor:Document.UpdateFields
//ExFor:DocumentBuilder.#ctor(Document)
//ExFor:ParagraphFormat.StyleIdentifier
//ExFor:DocumentBuilder.InsertBreak
//ExFor:BreakType
//ExId:InsertTableOfContents
//ExSummary:Demonstrates how to insert a Table of contents (TOC) into a document using heading styles as entries.
// Use a blank document
Aspose.Words.Document doc = new Aspose.Words.Document();
// Create a document builder to insert content with into document.
DocumentBuilder builder = new DocumentBuilder(doc);
// Insert a table of contents at the beginning of the document.
builder.InsertTableOfContents("\\o \"1-3\" \\h \\z \\u");
// Start the actual document content on the second page.
builder.InsertBreak(BreakType.PageBreak);
// Build a document with complex structure by applying different heading styles thus creating TOC entries.
builder.ParagraphFormat.StyleIdentifier = StyleIdentifier.Heading1;
builder.Writeln("Heading 1");
builder.ParagraphFormat.StyleIdentifier = StyleIdentifier.Heading2;
builder.Writeln("Heading 1.1");
builder.Writeln("Heading 1.2");
builder.ParagraphFormat.StyleIdentifier = StyleIdentifier.Heading1;
builder.Writeln("Heading 2");
builder.Writeln("Heading 3");
builder.ParagraphFormat.StyleIdentifier = StyleIdentifier.Heading2;
builder.Writeln("Heading 3.1");
builder.ParagraphFormat.StyleIdentifier = StyleIdentifier.Heading3;
builder.Writeln("Heading 3.1.1");
builder.Writeln("Heading 3.1.2");
builder.Writeln("Heading 3.1.3");
builder.ParagraphFormat.StyleIdentifier = StyleIdentifier.Heading2;
builder.Writeln("Heading 3.2");
builder.Writeln("Heading 3.3");
// Call the method below to update the TOC.
doc.UpdateFields();
//ExEnd
doc.Save(ExDir + "DocumentBuilder.InsertToc Out.docx");
}
示例6: Run
public static void Run()
{
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_QuickStart();
// Demonstrates how to insert fields and update them using Aspose.Words.
// First create a blank document.
Document doc = new Document();
// Use the document builder to insert some content and fields.
DocumentBuilder builder = new DocumentBuilder(doc);
// Insert a table of contents at the beginning of the document.
builder.InsertTableOfContents("\\o \"1-3\" \\h \\z \\u");
builder.Writeln();
// Insert some other fields.
builder.Write("Page: ");
builder.InsertField("PAGE");
builder.Write(" of ");
builder.InsertField("NUMPAGES");
builder.Writeln();
builder.Write("Date: ");
builder.InsertField("DATE");
// Start the actual document content on the second page.
builder.InsertBreak(BreakType.SectionBreakNewPage);
// Build a document with complex structure by applying different heading styles thus creating TOC entries.
builder.ParagraphFormat.StyleIdentifier = StyleIdentifier.Heading1;
builder.Writeln("Heading 1");
builder.ParagraphFormat.StyleIdentifier = StyleIdentifier.Heading2;
builder.Writeln("Heading 1.1");
builder.Writeln("Heading 1.2");
builder.ParagraphFormat.StyleIdentifier = StyleIdentifier.Heading1;
builder.Writeln("Heading 2");
builder.Writeln("Heading 3");
// Move to the next page.
builder.InsertBreak(BreakType.PageBreak);
builder.ParagraphFormat.StyleIdentifier = StyleIdentifier.Heading2;
builder.Writeln("Heading 3.1");
builder.ParagraphFormat.StyleIdentifier = StyleIdentifier.Heading3;
builder.Writeln("Heading 3.1.1");
builder.Writeln("Heading 3.1.2");
builder.Writeln("Heading 3.1.3");
builder.ParagraphFormat.StyleIdentifier = StyleIdentifier.Heading2;
builder.Writeln("Heading 3.2");
builder.Writeln("Heading 3.3");
Console.WriteLine("Updating all fields in the document.");
// Call the method below to update the TOC.
doc.UpdateFields();
doc.Save(dataDir + "Document Field Update Out.docx");
Console.WriteLine("\nFields updated successfully.\nFile saved at " + dataDir + "Document Field Update Out.docx");
}