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.

Mon Sep 23, 2013 8:28 pm

Hello,

I am trying to extract from a word doc based on the style of the paragraph. For instance I would like to look through all paragraphs in the document and only extract if it is bold. Is there a way to read the style off a paragraph? Here is what I was trying:

Code: Select all
Public Function GetParagraphs(byVal pstrFilepath as String)
        Dim objDoc as Document
        Dim objSection As Section
        Dim objParagraph As Paragraph
        Dim objDocumentObject As DocumentObject
        Dim objParagraphStyle As ParagraphStyle

         objDoc = New Document()
         objDoc.LoadFromFile(pstrFilePath)

'Loop through each section
        For Each objSection In mobjDoc.Sections()
            'Loop through all the document objects
            For Each objDocumentObject In objSection.Body.ChildObjects()

                'Check if this is a paragraph object
                If objDocumentObject.DocumentObjectType = DocumentObjectType.Paragraph Then

                    'Set the paragraph object
                    objParagraph = objDocumentObject

                    objParagraphStyle = objParagraph.GetStyle()

                    If objParagraphStyle.CharacterFormat.Bold Then
                                     'do something
                    End if
                 End If
             Next
          Next


karlhester
 
Posts: 1
Joined: Thu Mar 07, 2013 6:58 pm

Tue Sep 24, 2013 7:06 am

Hello,

Thanks for your inquiry.
Please refer to the following method to read the style of a paragraph.
Code: Select all
Public Function GetParagraphs(ByVal pstrFilepath As String)
        Dim objDoc As Document
        Dim objSection As Section
        Dim objParagraph As Paragraph

        objDoc = New Document()
        objDoc.LoadFromFile(pstrFilepath)

        'Loop through each section
        For Each objSection In objDoc.Sections()
            'Loop through all each paragraph
            For Each objParagraph In objSection.Paragraphs
                'Loop through all ChildObject of each paragraph
                For Each obj In objParagraph.ChildObjects
                    If TypeOf obj Is Spire.Doc.Fields.TextRange Then
                        If TryCast(obj, Spire.Doc.Fields.TextRange).CharacterFormat.Bold Then
                            'do something
                        End If
                    End If
                Next
            Next
        Next

    End Function

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

Fri Oct 04, 2013 8:18 am

Hello karlhester,

We are wondering whether your issue is fixed? Could you please update the thread if convenience?
If there are any questions, welcome to get it back to us.
Harry
Technical Support / Developer,
e-iceblue Support Team
User avatar

harry.support
 
Posts: 180
Joined: Mon Nov 08, 2010 3:11 pm

Return to Spire.Doc