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.

Tue May 10, 2016 5:47 am

What is the API for adding a catalog?
Thank you !

iceblueDDX123
 
Posts: 34
Joined: Tue Apr 19, 2016 9:43 am

Tue May 10, 2016 8:13 am

Hello,

Do you want to add a table of content? I am bit confused at this point of adding a catalog.
If so, please try the below code:
Code: Select all
 Spire.Doc.Section sec = doc.Sections[0];
    Spire.Doc.Documents.Paragraph para = new Spire.Doc.Documents.Paragraph(doc);
    sec.Paragraphs.Insert(0, para);
    para.AppendTOC(1, 3);

If not, could you please elaborate your requirement to help us know it? Thank you.

Sincerely,
Caroline
E-iceblue support team
User avatar

caroline.zhang
 
Posts: 291
Joined: Mon Mar 07, 2016 9:22 am

Wed May 11, 2016 1:28 am

caroline.zhang wrote:Hello,

Do you want to add a table of content? I am bit confused at this point of adding a catalog.
If so, please try the below code:
Code: Select all
 Spire.Doc.Section sec = doc.Sections[0];
    Spire.Doc.Documents.Paragraph para = new Spire.Doc.Documents.Paragraph(doc);
    sec.Paragraphs.Insert(0, para);
    para.AppendTOC(1, 3);

If not, could you please elaborate your requirement to help us know it? Thank you.

Sincerely,
Caroline
E-iceblue support team

Yeah,I was going to add a table of content.But ,now I have a .docx file and there are already some paragraphs in it . I really want to add a table of content for the .docx file.Some APIS are available ?

iceblueDDX123
 
Posts: 34
Joined: Tue Apr 19, 2016 9:43 am

Wed May 11, 2016 2:46 am

Hi,

Thank you for reply.
Could you please provide your word file to help us for testing?

Thank you in advance.
Caroline
E-iceblue support team
User avatar

caroline.zhang
 
Posts: 291
Joined: Mon Mar 07, 2016 9:22 am

Wed May 11, 2016 5:19 am

caroline.zhang wrote:Hi,

Thank you for reply.
Could you please provide your word file to help us for testing?

Thank you in advance.
Caroline
E-iceblue support team

The file is here ,thank you .

iceblueDDX123
 
Posts: 34
Joined: Tue Apr 19, 2016 9:43 am

Wed May 11, 2016 7:09 am

Hello,

Thank you for your file.
The below code for your reference.
Code: Select all
            Document doc = new Document();
            doc.LoadFromFile("catalog.docx");
            Section sec = doc.Sections[0];
            Paragraph para = new Paragraph(doc);
            sec.Paragraphs.Insert(0, para);
            para.AppendTOC(2, 4);
            doc.UpdateTableOfContents();
            doc.SaveToFile("result.docx",FileFormat.Docx2013);
            System.Diagnostics.Process.Start("result.docx");


Sincerely,
Caroline
E-iceblue support team
User avatar

caroline.zhang
 
Posts: 291
Joined: Mon Mar 07, 2016 9:22 am

Wed May 11, 2016 9:57 am

caroline.zhang wrote:Hello,

Thank you for your file.
The below code for your reference.
Code: Select all
            Document doc = new Document();
            doc.LoadFromFile("catalog.docx");
            Section sec = doc.Sections[0];
            Paragraph para = new Paragraph(doc);
            sec.Paragraphs.Insert(0, para);
            para.AppendTOC(2, 4);
            doc.UpdateTableOfContents();
            doc.SaveToFile("result.docx",FileFormat.Docx2013);
            System.Diagnostics.Process.Start("result.docx");


Sincerely,
Caroline
E-iceblue support team

Thank you ,it works !But what is the meaning by "para.AppendTOC(2, 4);"?

iceblueDDX123
 
Posts: 34
Joined: Tue Apr 19, 2016 9:43 am

Thu May 12, 2016 2:15 am

Hello,

Thanks for your inquiry.
Firstly, glad that the code works for your scenario.
Then the method para.AppendTOC() contained two pramaters which represent lowerLevel and upperLevel. The lowerLevel is the starting heading level of table of content, and the upper level is the ending heading level of the table of content. Because the heading level starts from Heading 2 to Heading 4 in your docx file, so it should be “para.AppendTOC(2,4)”.

Sincerely,
Caroline
E-iceblue support team
User avatar

caroline.zhang
 
Posts: 291
Joined: Mon Mar 07, 2016 9:22 am

Thu May 12, 2016 2:49 am

Thank you very much for you reply.

iceblueDDX123
 
Posts: 34
Joined: Tue Apr 19, 2016 9:43 am

Thu May 12, 2016 3:58 am

Glad to help you.

If there is any question when using our products, welcome to feel free to ask us.

Sincerely,
Caroline
E-iceblue support team
User avatar

caroline.zhang
 
Posts: 291
Joined: Mon Mar 07, 2016 9:22 am

Thu May 12, 2016 6:18 am

caroline.zhang wrote:Glad to help you.

If there is any question when using our products, welcome to feel free to ask us.

Sincerely,
Caroline
E-iceblue support team

Thank you ! Now I encounter a new problem that how can I delete the table of content from the word file ?

iceblueDDX123
 
Posts: 34
Joined: Tue Apr 19, 2016 9:43 am

Thu May 12, 2016 9:28 am

Hello,

Please try the following solution:
Code: Select all
           Document doc = new Document();
            doc.LoadFromFile("test.docx");
            TableOfContent toc = doc.TOC;
            var tocObject = toc.Owner.Owner.Owner;
            tocObject.Owner.ChildObjects.Remove(tocObject);
            doc.SaveToFile("sample.docx", FileFormat.Docx2013);
            System.Diagnostics.Process.Start("sample.docx");


Sincerely,
Caroline
E-iceblue support team
User avatar

caroline.zhang
 
Posts: 291
Joined: Mon Mar 07, 2016 9:22 am

Fri May 13, 2016 2:31 am

caroline.zhang wrote:Hello,

Please try the following solution:
Code: Select all
           Document doc = new Document();
            doc.LoadFromFile("test.docx");
            TableOfContent toc = doc.TOC;
            var tocObject = toc.Owner.Owner.Owner;
            tocObject.Owner.ChildObjects.Remove(tocObject);
            doc.SaveToFile("sample.docx", FileFormat.Docx2013);
            System.Diagnostics.Process.Start("sample.docx");


Sincerely,
Caroline
E-iceblue support team

Thank you .It works .But could you explain the code "toc.Owner.Owner.Owner",so many owners confused me.

iceblueDDX123
 
Posts: 34
Joined: Tue Apr 19, 2016 9:43 am

Fri May 13, 2016 3:14 am

Hi,

OK, please refer to the below code with explanations
Code: Select all
            TableOfContent toc = doc.TOC; //defines a field as table of content
            var para = toc.Owner;        //Gets Toc Paragraph in the doc
            var con = para.Owner;        //Gets SDTContent of toc paragraph
            var tocObject = con.Owner;  //Gets StructureDocumentTag of the content


Sincerely,
Caroline
E-iceblue support team
User avatar

caroline.zhang
 
Posts: 291
Joined: Mon Mar 07, 2016 9:22 am

Tue May 17, 2016 8:30 am

Hello,

Has the issue been resolved? Could you please give us some feedback at your convenience?

Thanks in advance,
Gary
E-iceblue support team
User avatar

Gary.zhang
 
Posts: 1380
Joined: Thu Apr 04, 2013 1:30 am

Return to Spire.Doc