want to get heading from ms word file

Technical support for Spire.Doc

Moderator: iceblue support

want to get heading from ms word file

Postby vikram$ » Wed Jul 19, 2017 5:58 am

i want to get heading from ms word file and want to buy spire .net package what is cost and is support provided by ?//
vikram$
 
Posts: 2
Joined: Mon Jul 17, 2017 2:59 pm

Re: want to get heading from ms word file

Postby Betsy.jiang » Wed Jul 19, 2017 7:12 am

Dear vikram$,

Thanks for your inquiry.
Here is sample code for your kindly reference.
Code: Select all
            Document doc = new Document(@"F:\testing\doc form\original document\11129.docx");
            List<String> headings = new List<string>();
            foreach (Section sec in doc.Sections)
            {
                foreach (DocumentObject obj in sec.Body.ChildObjects)
                {
                    // detect if there is heading in paragraph
                    if (obj is Paragraph)
                    {
                        Paragraph par = obj as Paragraph;                     
                        string style = par.StyleName;
                        if (style.Contains("Heading"))
                        {
                            headings.Add(par.Text);
                        }
                    }
                    // detect if there is heading in table
                    if (obj is Table)
                    {
                        Table table = obj as Table;
                        foreach (TableRow row in table.Rows)
                        {
                            foreach (TableCell cell in row.Cells)
                            {
                                foreach (Paragraph tp in cell.Paragraphs)
                                {
                                    Paragraph parT = tp as Paragraph;
                                    string Tstyle = parT.StyleName;
                                    if (Tstyle .Contains("Heading"))
                                    {
                                        headings.Add(parT.Text);
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }

Hope this helps. If there is still issue, please provide us with input document, we will provide corresponding code for you.

For the cost, you could refer to below link.
https://www.e-iceblue.com/Buy/Spire.Doc.html
More questions about purchse, please contact our sales team(sales@e-iceblue.com) via email.

We provide free technical support, you could post any question on our forum or send email to us(support@e-iceblue.com).

Sincerely,
Betsy
E-iceblue support team
User avatar
Betsy.jiang
 
Posts: 1628
Joined: Tue Sep 06, 2016 8:30 am

Re: want to get heading from ms word file

Postby vikram$ » Wed Jul 19, 2017 12:27 pm

is it possible to extract paragraph headings and paragraph bodies in separate variables? basically my aim is to print a paragraph depending on its heading. If heading=ENFORCEABILITY then print the paragraph. How do I achieve this object using Spire? Please refer the attachment. I am looking to purchase SPIRE for this purpose. looking forward to your reply on this.
You do not have the required permissions to view the files attached to this post.
vikram$
 
Posts: 2
Joined: Mon Jul 17, 2017 2:59 pm

Re: want to get heading from ms word file

Postby Betsy.jiang » Thu Jul 20, 2017 3:33 am

Dear vikram$,

Thanks for your feedback.
I checked the file you provided, and found the style of "heading" paragraph you mentioned is not the "heading" style, just "Nomal" like other paragraphs. So the method I provided in last post is not useful for this case. Accroding to your document, I suggest you use specific text to detect which paragrahs are what you want. Here is sample code for your reference.
Code: Select all
            Document doc = new Document(@"F:\testing\doc form\original document\readme123.docx");
            List<String> headings = new List<string>();
            List<Paragraph> paragraphs = new List<Paragraph>();
            foreach (Section sec in doc.Sections)
            {
                foreach (DocumentObject obj in sec.Body.ChildObjects)
                {
                    if (obj is Paragraph)
                    {
                        Paragraph par = obj as Paragraph;
                        //check if the paragraph is the heading you want
                        if (par.Text.Contains("ENFORCEABILITY"))
                        {
                            headings.Add(par.Text);
                            int index;
                            //get the index of the next paragraoh
                            index = sec.Body.ChildObjects.IndexOf(par) + 1;
                            for (int i = index; i < sec.Body.ChildObjects.Count; i++)
                            {
                                if (sec.Body.ChildObjects[index] is Paragraph)
                                {
                                    Paragraph Hbody = sec.Body.ChildObjects[index] as Paragraph;
                                    //check if the Hbody is the next "heading"
                                    if (!Hbody.Text.Contains("INVOICING AND PAYMENT"))
                                    {
                                        if(Hbody.Text!= String.Empty)
                                            paragraphs.Add(Hbody);                                       
                                        index++;
                                    }
                                    else
                                        break;
                                }
                            }                                                     
                        }
                    }
                }
            }
        }

Hope this helps. If there is any question, please let me know.

Sincerely,
Betsy
E-iceblue support team
User avatar
Betsy.jiang
 
Posts: 1628
Joined: Tue Sep 06, 2016 8:30 am

Re: want to get heading from ms word file

Postby Betsy.jiang » Fri Jul 21, 2017 7:18 am

Dear vikram$,

Did you try the code I provided ? Did it meet your requirement ?

Thanks,
Betsy
E-iceblue support team
User avatar
Betsy.jiang
 
Posts: 1628
Joined: Tue Sep 06, 2016 8:30 am


Return to Spire.Doc

Who is online

Users browsing this forum: No registered users and 0 guests

cron