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 Mar 29, 2022 10:11 am
We are not able to read the Table of content (Manual) value from Word documents . Please check and help me to resolve.
-
pr20080798
-
- Posts: 146
- Joined: Wed Jan 20, 2021 1:15 pm
Wed Mar 30, 2022 9:48 am
Hi,
Thanks for your inquiry.
I could use the following code to read the table of content (manual) from Word document, please have a try. If there is still the problem, please provide your Word document for further investigation. You can attach your file here or send it to us via email (
support@e-iceblue.com).
- Code: Select all
Document document = new Document();
document.LoadFromFile(fileName);
List<string> content = new List<string>();
foreach (Section sec in document.Sections)
{
//Iterate over all objects under the body
foreach (DocumentObject obj in sec.Body.ChildObjects)
{
//If the object is StructureDocumentTag
if (obj is StructureDocumentTag)
{
StructureDocumentTag sdt = obj as StructureDocumentTag;
//Look for the control object to TOC to get the content
foreach (DocumentObject sdtobj in sdt.ChildObjects)
{
if (sdtobj is Paragraph)
{
//Add content to list
Paragraph p = sdtobj as Paragraph;
content.Add(p.Text);
}
}
}
}
}
Sincerely,
Kylie
E-iceblue support team
-
kylie.tian
-
- Posts: 412
- Joined: Mon Mar 07, 2022 2:30 am
Thu Mar 31, 2022 6:05 am
Hi Team,
Given source code is not getting the full value of Manal TOC. We are facing some challenge to upload our documents here. So we have shared our document from "Raja.mohanasundaram@wipro.com" mail id with Subject Name "TOPIC REVIEW: READ MANUAL TABLE OF CONTENT FROM WORD FILE".
Please check and provide solution ASAP.
-
pr20080798
-
- Posts: 146
- Joined: Wed Jan 20, 2021 1:15 pm
Thu Mar 31, 2022 10:17 am
Hello,
Thanks for sharing your document.
Please use the following code to read the table of content from your document. If you have any further questions, please contact us.
- Code: Select all
//Load document from disk
Document document = new Document();
document.LoadFromFile("TestingToc.docx", Spire.Doc.FileFormat.Docx2013);
//Create a StringBuilder object
StringBuilder builder = new StringBuilder();
//Loop through sections
foreach (Section section in document.Sections)
{
//Loop through paragraph from section body
foreach (Paragraph paragraph in section.Body.Paragraphs)
{
//If the stylename of paragraph contains TOC word
if (paragraph.StyleName.Contains("TOC"))
{
//Append the paragraph text
builder.AppendLine(paragraph.Text);
}
}
}
File.WriteAllText("result.txt", builder.ToString());
Sincerely,
Kylie
E-iceblue support team
-
kylie.tian
-
- Posts: 412
- Joined: Mon Mar 07, 2022 2:30 am
Tue Apr 19, 2022 9:21 am
Hi,
Greetings from E-iceblue.
Has your problem been effectively solved now? Can you give us some feedback at your convenience?
Thanks in advance.
Sincerely,
Kylie
E-iceblue support team
-
kylie.tian
-
- Posts: 412
- Joined: Mon Mar 07, 2022 2:30 am