In my project I need to get data from MS Word tables and insert it to database. I found on the net how to open word document to get tables. But when I start to read table row by row it gives me an exeption 'Cannot access individual rows in this collection because the table has vertically merged cells'. How can I read from merged rows or maybe is there a beter way to complete this task

Reading from MS Word tables with .NET
Jes_
for example:
--------------------------------------------------
| | | 1. Some property |
| 1 | Data |2 .Some property |
| | |3.Some property |
--------------------------------------------------
in datatable will be:
-------------------------------------------------
| 1 | Data | 1.Some property |
| 1 | Data | 2.Some property |
| 1 | Data | 3.Some property |
-------------------------------------------------
Simon
Thanks everyone for this thread, it helped greatly. One little problem is that once I extract the MS word table into my VB Datatable and output it, there are what looks to me like return characters after every feild value. They output as two small squares. I tried doing replace and trim functions with no success.
What is the character code I should be looking for to remove these symbols.
Please advise.
Thanks
Chad
Borvik
Dim i As Integer
'First, Loop through each table; you may perfer to pick a table explicitly
For i = 1 To Word.ActiveDocument.Tables.Count
'Create some variables to hold row and column values
Dim x, y As Integer
'Loop through the rows in the table
For x = 1 To [WordInstance].Tables(i).Rows.Count
'Loop through the coloumns for each row
For y = 1 To [WordInstance].Tables(i).Columns.Count
'Try to read the value of cell X,Y
Try
Dim CellValue as String
CellValue = [WordInstance].Tables(i).Cell(x, y).Range.Text)
Catch ex As Exception
'If we get an error, there is no cell at X,Y because Y is merged with the cell
'above, so increase Y by 1
y+=1
End Try
Next
Next
Next
This will handle vertically merged cells. You should similarly trap the "X" loop to get horizontally merged cells.
You'd probably be better to select a range of cells within the table and enumerate the cells of the range object, but the above code will work in a simple scenario.
Kevin666
For instance:
-----------------------------------------------------
| Merge Cell 1 | Single Cell 1 | Single Cell 2 |
| (white space) |----------------|-----------------|
| (white space) | Single Cell 3 | Single Cell 4 |
-----------------------------------------------------
The code supplied above would read through this table and return:
Merge Cell 1
Single Cell 1
Single Cell 2
Single Cell 3
Single Cell 4
Gerald Hinson