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 Jun 23, 2023 10:48 am

I'm looking for vb.net code to check if a certain pargraph (by paragraph number) is bulleted (not just listed) and extract the bullet symbol.

Thank you in advance!

kdr13
 
Posts: 72
Joined: Fri Apr 15, 2016 4:35 pm

Sun Jun 25, 2023 8:58 am

Hello,

Thanks for your inquiry.
You can achieve this function through the following code:
Code: Select all
Dim doc As Document = New Document("C:\test.docx")
        Dim sb As StringBuilder = New StringBuilder()

        For Each section As Section In doc.Sections

            For Each pgh As Paragraph In section.Paragraphs

                If pgh.ListFormat.ListType = ListType.Bulleted OrElse (pgh.ListFormat.ListType = ListType.Numbered AndAlso Not pgh.StyleName.Equals("Heading1", StringComparison.OrdinalIgnoreCase)) Then

                    If pgh.ListFormat.ListType = ListType.Bulleted Then
                        sb.Append(pgh.ListFormat.CurrentListLevel.BulletCharacter & vbCrLf)
                    Else
                        Console.WriteLine("This paragraph is a numbered list")
                    End If
                End If
            Next
        Next

        Dim result As String = "result.txt"
        File.WriteAllText(result, sb.ToString())

If the above code does not meet your requirements, please provide us with a sample Word document for our reference. You could attach it here or send it to us via email ([email protected]). Thank you in advance.

Sincerely
Wenly
E-iceblue support team
User avatar

Wenly.Zhang
 
Posts: 149
Joined: Tue May 16, 2023 2:19 am

Return to Spire.Doc