Exemplo n.º 1
0
        /// <summary>
        /// Add a Table of content to a document by inserting it just before a reference paragraph.
        /// </summary>
        public static void InsertTableOfContentWithReference()
        {
            Console.WriteLine("\tInsertTableOfContentWithReference()");

            // Create a document.
            using (DocX document = DocX.Create(TableOfContentSample.TableOfContentSampleOutputDirectory + @"InsertTableOfContentWithReference.docx"))
            {
                // Add a title.
                document.InsertParagraph("Insert Table of content with reference").FontSize(15d).SpacingAfter(50d).Alignment = Alignment.center;

                // Add an intro paragraph.
                var intro = document.InsertParagraph("This page will show the team rosters of the American League East Division.");
                intro.SpacingAfter(150d);

                // Create a paragraph and fill it in method AddTeams().
                var p       = document.InsertParagraph();
                var rosters = TableOfContentSample.AddTeams(p);
                document.InsertParagraph(rosters);

                // Insert a table of content with a page break just before the paragraph p.
                document.InsertTableOfContents(p,
                                               "Teams",
                                               TableOfContentsSwitches.O | TableOfContentsSwitches.U | TableOfContentsSwitches.Z | TableOfContentsSwitches.H,
                                               "Heading4");

                document.Save();
                Console.WriteLine("\tCreated: InsertTableOfContentWithReference.docx\n");
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Add a Table of content to a document.
        /// </summary>
        public static void InsertTableOfContent()
        {
            Console.WriteLine("\tInsertTableOfContent()");

            // Creates a document
            using (DocX document = DocX.Create(TableOfContentSample.TableOfContentSampleOutputDirectory + @"InsertTableOfContent.docx"))
            {
                // Add a title
                document.InsertParagraph("Insert Table of content").FontSize(15d).SpacingAfter(50d).Alignment = Alignment.center;

                // Insert a table of content with a page break.
                document.InsertTableOfContents("Teams", TableOfContentsSwitches.O | TableOfContentsSwitches.U | TableOfContentsSwitches.Z | TableOfContentsSwitches.H);
                document.InsertSectionPageBreak();

                // Create a paragraph and fill it in method AddTeams().
                var p       = document.InsertParagraph();
                var rosters = TableOfContentSample.AddTeams(p);
                document.InsertParagraph(rosters);

                document.Save();
                Console.WriteLine("\tCreated: InsertTableOfContent.docx\n");
            }
        }