Spire.Doc is a professional Word .NET library specifically designed for developers to create, read, write, convert and print Word document files. Get free and professional technical support for Spire.Doc for .NET, Java, Android, C++, Python.

Sun Jun 19, 2011 8:47 pm

Hi everybody,

I want to insert a toc after the first page in my generated document.
How can I do that?

Thanks

cgueldre
 
Posts: 11
Joined: Tue Jun 14, 2011 11:00 am

Mon Jun 20, 2011 8:12 am

Dear cgueldre,
Thanks for your inquiry.
Here is a sample code to do it. But when you open the file you need to press F9, so that the TOC could be shown.
Code: Select all
//Open a blank word document as template
            Document document = new Document();

            //Get the first secition
            Section section = document.AddSection();

            //Create a new paragraph or get the first paragraph
            Paragraph paragraph = section.AddParagraph();

            //Append Text
            paragraph.AppendText("Content");
            paragraph = section.AddParagraph();
            paragraph.AppendTOC(1, 4);
            paragraph = section.AddParagraph();
            paragraph.AppendBreak(BreakType.PageBreak);

            foreach (BuiltinStyle builtinStyle in Enum.GetValues(typeof(BuiltinStyle)))
            {
                paragraph = section.AddParagraph();
                //Append Text
                paragraph.AppendText(builtinStyle.ToString());
                //Apply Style
                paragraph.ApplyStyle(builtinStyle);
            }

            //Save doc file.
            document.SaveToFile("Sample.doc", FileFormat.Doc);
            System.Diagnostics.Process.Start("Sample.doc");
Justin
Technical Support / Developer,
e-iceblue Support Team
User avatar

Justin Weng
 
Posts: 110
Joined: Mon Mar 28, 2011 5:54 am

Mon Jun 20, 2011 11:10 pm

Hi Justin,

in my generated document I have 9 styles called CDC_1 to CDC_9.
I want to create my TOC using these styles.
Thus I suppose I have to declare UseHeadingStyles = True somewhere and witch styles I want to use.
In "paragraph_Renamed.AppendTOC(lowerHeadingLevel , upperHeadingLevel )",
I don't understand how to use the integers lowerHeadingLevel and upperHeadingLevel

thanks

Regards

cgueldre
 
Posts: 11
Joined: Tue Jun 14, 2011 11:00 am

Tue Jun 21, 2011 6:53 am

Justin
Technical Support / Developer,
e-iceblue Support Team
User avatar

Justin Weng
 
Posts: 110
Joined: Mon Mar 28, 2011 5:54 am

Tue Jun 21, 2011 9:15 am

Hi Justin,

I change the name of my styles from CDC_1,CDC_2,CDC_3,CDC_4,CDC_5,CDC_6,CDC_7,CDC_8,CDC_9 to Heading 1,Heading 2,Heading 3,Heading 4,Heading 5,Heading 6,Heading 7,Heading 8,Heading 9 and the problem is solved.

Thanks

How can I mark this topic as solved?

Regards

cgueldre
 
Posts: 11
Joined: Tue Jun 14, 2011 11:00 am

Tue Jun 21, 2011 10:15 am

Dear cgueldre,
Thanks for your inquiry.
There is not a solve mark. What a shame.
But almost all questions are solved or solving.
BR
Justin
Technical Support / Developer,
e-iceblue Support Team
User avatar

Justin Weng
 
Posts: 110
Joined: Mon Mar 28, 2011 5:54 am

Return to Spire.Doc