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.

Wed Jun 25, 2014 3:42 pm

Hi,

i am trying to convert a table in word interop using vb.net to a spire table. Current code is....


For i = Document.Tables.Count To 1 Step -1
With Document.Tables(i)
r = .Rows.Count
Do While (r >= 1)
s = ""
For c = 1 To .Columns.Count Step 1
On Error Resume Next
s = s & Trim(.Cell(r, c).Range.Text)
On Error GoTo Fail
Next
If (Len(s) = (.Columns.Count * 2)) Then
.Rows(r).Delete()
Else
On Error Resume Next
.Rows(r).HeightRule = Interop.Word.WdRowHeightRule.wdRowHeightAuto
On Error GoTo Fail
End If
r = r - 1
Loop
End With
Next

How do i change this to work with spire docs?

stevenheggie
 
Posts: 60
Joined: Tue Jun 24, 2014 10:32 am

Thu Jun 26, 2014 3:28 am

Hello,

Please refer to the following codes.
Code: Select all
Dim doc As New Document()
doc.LoadFromFile("test.docx")
Dim sec As Section = doc.Sections(0)
For i As Integer = sec.Body.Tables.Count To 1 Step -1
            Dim r = sec.Body.Tables(i - 1).Rows.Count
            While r >= 1
                Dim s As String = ""
                For c As Integer = 0 To sec.Body.Tables(i - 1).Rows(r - 1).Cells.Count - 1
                    For Each para As Paragraph In sec.Body.Tables(i - 1).Rows(r - 1).Cells(c).Paragraphs
                        s += para.Text
                    Next
                    If s.Length = (sec.Body.Tables(i - 1).Rows(r - 1).Cells.Count * 2) Then
                        sec.Body.Tables(i - 1).Rows.Remove(sec.Body.Tables(i - 1).Rows(r - 1))
                        Exit For
                    End If
                Next
                r = r - 1
            End While
        Next

Feel free to contact us any time if you need further help or have some other issue or queries, we will be happy to assist you soon.
Sincerely,
Gary
E-iceblue support team
User avatar

Gary.zhang
 
Posts: 1380
Joined: Thu Apr 04, 2013 1:30 am

Tue Jul 01, 2014 9:06 am

Hello,

Has the issue been resolved? Could you please give us some feedback if convenience?

If there are any questions, welcome to get it back to us.

Thanks,
Gary
E-iceblue support team
User avatar

Gary.zhang
 
Posts: 1380
Joined: Thu Apr 04, 2013 1:30 am

Tue Jul 01, 2014 9:22 am

Hi,

Yes this is now working many thanks

stevenheggie
 
Posts: 60
Joined: Tue Jun 24, 2014 10:32 am

Tue Jul 01, 2014 9:34 am

Thanks for your response. Feel free to contact us any time if you need further help or have some other issue or queries, we will be happy to assist you soon.
Sincerely,
Gary
E-iceblue support team
User avatar

Gary.zhang
 
Posts: 1380
Joined: Thu Apr 04, 2013 1:30 am

Return to Spire.Doc