Need help!

Technical support for Spire.Doc

Moderator: iceblue support

Need help!

Postby kdr13 » Fri Jun 02, 2017 9:05 am

kindly advise VB script for:
1. Extracting Font type of Word doc
2. Extracting Font color of Word doc
3. Extracting Font style (Bold/Underline/Italian) of Word doc
4. Checking whether Word doc contains tables
5. Checking whether Word doc contains headers/footers
6. Checking whether Word doc contains special characters
7. Checking whether Word doc contains hyperlinks
8. Checking whether Word doc contains bullets

Thanks!
kdr13
 
Posts: 41
Joined: Fri Apr 15, 2016 4:35 pm

Re: Need help!

Postby Betsy.jiang » Fri Jun 02, 2017 10:07 am

Dear kdr13,

Thanks for your inquiry.
We will investigate it and update you ASAP.

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

Re: Need help!

Postby Betsy.jiang » Mon Jun 05, 2017 7:47 am

Dear kdr13,

Sorry for late reply as weekend. For your questions, please refer the code below.
Code: Select all
'Question#1: Font type
Dim fontt As New List(Of String)()

'Question#2: Font Color
Dim fontColor As New List(Of String)()

'question#7 check if hytperlinks is null
Dim hyperlinks As New List(Of Field)()

Dim doc As New Document()
doc.LoadFromFile("F:\testing\doc form\original document\Sample10738.docx")

'Question#7
Dim fields As FieldCollection = doc.Fields
For Each field As Field In fields
   If field.Type = FieldType.FieldHyperlink Then
      hyperlinks.Add(field)
   End If
Next

'question#6, I take "$" as Specific character, please check if textSelection is null.
Dim textSelection As TextSelection() = doc.FindAllString("$", True, True)


For Each sec As Section In doc.Sections

   'question#4 if the tables is not null, it means the document has tables.
   Dim tables As TableCollection = sec.Tables

   'Question#2/Question#1/Question#8, traverse paragraps in tables
   For Each table As Table In tables
      For Each tr__1 As TableRow In table.Rows
         For Each cell As TableCell In tr__1.Cells
            For Each para As Paragraph In cell.Paragraphs
               'check if the lStyle is null, and could check the list type
               Dim lStyle As ListStyle = para.ListFormat.CurrentListStyle
               If lStyle IsNot Nothing Then
                  Dim listType As ListType = para.ListFormat.ListType
               End If

               For Each TObj As DocumentObject In para.ChildObjects
                  If TypeOf TObj Is TextRange Then

                     Dim TR__2 As TextRange = TryCast(TObj, TextRange)
                     'Qustion#2
                     Dim color As String = TR__2.CharacterFormat.TextColor.Name
                     If fontColor.Count = 0 Then
                        fontColor.Add(color)
                     ElseIf fontColor.Contains(color) Then
                        Continue For
                     Else
                        fontColor.Add(color)
                     End If

                     'Qustion#1
                     Dim font As String = TR__2.CharacterFormat.FontName
                     If fontt.Count = 0 Then
                        fontt.Add(font)
                     ElseIf fontt.Contains(font) Then
                        Continue For
                     Else
                        fontt.Add(font)
                     End If
                  End If
               Next
            Next
         Next
      Next
   Next

   'Question#8, check paragraphs in section
   For Each par As Paragraph In sec.Paragraphs
      'check if the lStyle is null, and could check the list type
      Dim lStyle As ListStyle = par.ListFormat.CurrentListStyle
      If lStyle IsNot Nothing Then
         Dim listType As ListType = par.ListFormat.ListType
      End If
   Next

   'question#5
   Dim header As HeaderFooter = sec.HeadersFooters.Header
   'if the HObj is not null, it means the document has the header.
   Dim HObj As DocumentObjectCollection = header.ChildObjects
        'note: some questions(1,2,3,4,8) you might need to traverse the childObjects in header/footer
        'and the code is similar to the code used to traverse object in section, like code below.

   For Each secObj As DocumentObject In sec.Body.ChildObjects
      If secObj.DocumentObjectType = DocumentObjectType.Paragraph Then
         For Each paraObj As DocumentObject In TryCast(secObj, Paragraph).ChildObjects
            If paraObj.DocumentObjectType = DocumentObjectType.TextRange Then
               Dim tr__1 As TextRange = TryCast(paraObj, TextRange)
               'Question#3
               'if the bool is true, it means the textrange is bold.
               Dim bold As Boolean = tr__1.CharacterFormat.Bold
               Dim italic As Boolean = tr__1.CharacterFormat.Italic
               ' underline style
               Dim underline As UnderlineStyle = tr__1.CharacterFormat.UnderlineStyle


               'Qustion#2
               Dim color As String = tr__1.CharacterFormat.TextColor.Name
               If fontColor.Count = 0 Then
                  fontColor.Add(color)
               ElseIf fontColor.Contains(color) Then
                  Continue For
               Else
                  fontColor.Add(color)
               End If



               'Qustion#1
               Dim font As String = tr__1.CharacterFormat.FontName
               If fontt.Count = 0 Then
                  fontt.Add(font)
               ElseIf fontt.Contains(font) Then
                  Continue For
               Else
                  fontt.Add(font)
               End If
            End If
         Next
      End If
   Next
Next

If there is any question, please describe it in detail and provide us with input file for investigation.

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

Re: Need help!

Postby Betsy.jiang » Wed Jun 07, 2017 9:27 am

Dear kdr13,

Did you test the code I provided ?
Have the issues been resolved ?

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

Re: Need help!

Postby kdr13 » Tue Jun 13, 2017 6:46 pm

The code for question#7 (checking if workd doc contains hyperlinks) does not work and gets many VS error messages - please help urgently! Need this today!

Still checking the rest.

Thanks!
kdr13
 
Posts: 41
Joined: Fri Apr 15, 2016 4:35 pm

Re: Need help!

Postby kdr13 » Tue Jun 13, 2017 7:28 pm

Same for checking whether Word doc contains headers/footers with any content - Code does not work.
kdr13
 
Posts: 41
Joined: Fri Apr 15, 2016 4:35 pm

Re: Need help!

Postby Betsy.jiang » Wed Jun 14, 2017 2:29 am

Dear kdr13,

Thanks for your feedback.
For the question#7, what is error messages ? Did you miss some references ? Such as Import Spire.Doc.Fields in your project.
For the header/footer issue, could you please provide us with the input Word document and the code you were using for investigation.

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

Re: Need help!

Postby kdr13 » Wed Jun 14, 2017 3:41 am

"Import Spire.Doc.Fields" reference WAS NOT missing in my code however "FieldCollection" was not recognized by VS.
Maybe there's another way to check if any hyperlinks within doc?

Regarding header/footer: The code should check if the header/footer IS NOT EMPTY - The output of the code provided is that header/footer exists in any scenario.

Thanks!
kdr13
 
Posts: 41
Joined: Fri Apr 15, 2016 4:35 pm

Re: Need help!

Postby Betsy.jiang » Wed Jun 14, 2017 8:42 am

Dear kdr13,

Thanks for your response.
1)The code "FieldCollection" worked fine on my side, and what is the detailed information of the error showing in VS ? Did you Import Spire.Doc.Collections ? In addition, there is another way to check the hyperlink.
https://www.e-iceblue.com/Tutorials/Spi ... ument.html

2) Sorry to hear that the code doesn't work for you, please try to use following code.
Code: Select all
bool value = sec.HeadersFooters.IsEmpty;

If there are still issues, please offer me the input Word document and the code you were trying.

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

Re: Need help!

Postby Betsy.jiang » Tue Jun 20, 2017 8:13 am

Dear kdr13,

How is the issue now ?
Could you please give us some feedback at your convenience ?

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