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.

Fri Nov 28, 2014 11:44 am

Hi!
I can't create table of contents for my document.
I use code:
Code: Select all
          Section section = _wordDocument.AddSection();
          Paragraph p = section.AddParagraph();
          p.AppendTOC(1, 3);

but in document i see only string "TOC"
Why?

P.S. MS Word editor create table of contents for this document normally.

vladmon
 
Posts: 6
Joined: Sun Jul 06, 2014 9:05 am

Mon Dec 01, 2014 3:03 am

Hello,

Thanks for your inquiry. Please attach your document here for our testing.
Thanks in advance,
Gary
E-iceblue support team
User avatar

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

Mon Dec 01, 2014 6:54 pm

Please try to create TOC for this file

vladmon
 
Posts: 6
Joined: Sun Jul 06, 2014 9:05 am

Tue Dec 02, 2014 6:48 am

Hello,

Thanks for the information, I have noticed the issue you mentioned, which has been transferred to our Dev team, once there are any progress, we will let you know immediately.
If there are any questions or needs, welcome to get it back to us.
Sincerely,
Gary
E-iceblue support team
User avatar

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

Fri Dec 05, 2014 7:29 am

Hello,

The issue has been resolved, and there is a newest hotfix for it you could download and test the method. Here is the download link.
http://www.e-iceblue.com/downloads/hot_ ... _5.3.7.zip
Code: Select all
Document doc = new Document();
doc.LoadFromFile(filename);
Section sec = doc.Sections[0];
Paragraph para = new Paragraph(doc);
sec.Paragraphs.Insert(0, para);
para.AppendTOC(1,3);       
doc.UpdateTableOfContents();
doc.SaveToFile(resultName,FileFormat.Docx);

If there are any questions, welcome to get it back to us.
Sincerely,
Gary
E-iceblue support team
User avatar

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

Sat Dec 06, 2014 7:56 pm

Thank you,
But the next code works with mistakes:
Code: Select all
           
Spire.Doc.Document doc = new Spire.Doc.Document("C:\\SpireTest\\st.doc");
//add a copy of the document to itself
            Spire.Doc.Document doc_2 = new Spire.Doc.Document("C:\\SpireTest\\st.doc");
            foreach (Spire.Doc.Section section in doc_2.Sections)
            {
                doc.Sections.Add(section.Clone());
            }
//add TOC
            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);
            doc.UpdateTableOfContents();
            doc.SaveToFile("C:\\SpireTest\\st2.doc", Spire.Doc.FileFormat.Doc);


The result is different for Doc and Docx format: for Doc format TOC has only a part of the headers. For docx format the second part of the document has the wrong headers (and style names).

vladmon
 
Posts: 6
Joined: Sun Jul 06, 2014 9:05 am

Mon Dec 08, 2014 3:37 am

Hello,

Thanks for your feedback.
I have transferred the issue to our Dev team, as a workaround, we recommand you use the following method.
Code: Select all
Spire.Doc.Document doc = new Spire.Doc.Document("st.doc");
//add a copy of the document to itself
doc.InsertTextFromFile("st.doc", FileFormat.Doc);
//add TOC
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);
doc.UpdateTableOfContents();
doc.SaveToFile("st2.doc", Spire.Doc.FileFormat.Doc);

Sincerely,
Gary
E-iceblue support team
User avatar

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

Tue Dec 09, 2014 8:33 am

Hello,

Have you tried the workaround? Has the issue been resolved? Could you please give us some feedback if convenience?

Thanks,
Gary
E-iceblue support team
User avatar

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

Tue Dec 09, 2014 1:01 pm

Yes, your code works properly. Thanks.

vladmon
 
Posts: 6
Joined: Sun Jul 06, 2014 9:05 am

Fri Dec 12, 2014 7:51 am

Hello,

Thanks for your feedback. If there are any questions or needs, please feel free to contact us.

Sincerely,
Gary
E-iceblue support team
User avatar

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

Return to Spire.Doc