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.

Wed Jun 15, 2016 1:16 pm

I have a document with three table of contents, each targeting a different header level. I would like to have all three tables displayed using the same style as a table of contents targeting a Heading 1 with a particular font. I seem to be having some trouble with both these. Here is what have. I am using SetTOCLevelStyle to try to set the level of the current table to use the Heading 1 style. I am also trying to set the font name to Calibri but neither seem to be working as expected.

Any help is realty appreciated.

Code: Select all
           
            Dim objTOC As TableOfContent
            objTOC = objDocSection.AddParagraph.AppendTOC(intLevel, intLevel)
            objTOC.SetTOCLevelStyle(intLevel, "Heading 1")
            objTOC.CharacterFormat.FontName = "Calibri"
            objTOC.IncludePageNumbers = bolShowNumbers

DSUser
 
Posts: 2
Joined: Thu Jun 09, 2016 4:08 pm

Thu Jun 16, 2016 6:20 am

Hi,

Thanks for your posting.
Please try the following solution.
Code: Select all
 Document document = new Document();
            document.LoadFromFile("test.docx");
            foreach (Section section in document.Sections)
            {
                foreach (Paragraph p in section.Paragraphs)
                {
                    if (p.Format.OutlineLevel != OutlineLevel.Body)
                    {   
                        p.ApplyStyle("Heading 1");
                        foreach (DocumentObject obj in p.ChildObjects)
                        {
                            if (obj.DocumentObjectType == DocumentObjectType.TextRange)
                            {
                                (obj as TextRange).CharacterFormat.FontName = "Calibri";
                            }
                        }
                    }
                }
            }
          document.SaveToFile(result,FileFormat.Docx2013);


If the above solution doesn't help, please share your source file and expected result so that we do a demo for you soon.
You can also send them to support@e-iceblue.com if it is inconvenience to share them here.

Best Regards,
Amy
E-iceblue support team
User avatar

amy.zhao
 
Posts: 2766
Joined: Wed Jun 27, 2012 8:50 am

Wed Jun 22, 2016 5:57 am

Hi,

Has your issue been resolved?
Thanks for your feedback in advance.

Best Regards,
Amy
E-iceblue support team
User avatar

amy.zhao
 
Posts: 2766
Joined: Wed Jun 27, 2012 8:50 am

Fri Jun 24, 2016 12:21 pm

Hi,

Thank you for the swift reply.
Your solution pointed me in the right direction and everything is working fine now.

Thank you very much.

D

DSUser
 
Posts: 2
Joined: Thu Jun 09, 2016 4:08 pm

Mon Jun 27, 2016 1:27 am

Hi,

I am glad that your issue has been resolved.
Welcome to write to us again for further problems.

Best Regards,
Amy
E-iceblue support team
User avatar

amy.zhao
 
Posts: 2766
Joined: Wed Jun 27, 2012 8:50 am

Return to Spire.Doc