.NET Framework Bookmark and Share   
 index > Common Language Runtime > Read a word document using c#
 

Read a word document using c#

Hi,

I've a document contains data into Table formats. I want to read the content and save as into Excel file.

I've read the document using Microsoft word library. But the problem is i want to read the content row by row and cell by cell.

So i can make a grid. Can anyone help me to read content in word document which is in table format.

Thanks,
S. Ramkumar
Smiley
Ramkumar_TPS
Hi Ramkumar_TPS,

Not too sure if this is the correct forum for this.

Anyways, in a nutshell, the following object hierarchy for each application is:

Word

Application
Documents
Document
Tables
Table

Excel

Application
Workbooks
Workbook
Worksheets
Worksheet
Range


Following is a snippet on how to find your way through the Word model. Let me know if this helps.

Dim i As Integer

For i = 1 To Application.Documents(0).Tables.Count

    Dim t As Table
    Dim colCount As Integer
    Dim rowCount As Integer
    
    t = Application.Documents(0).Tables(i)
    colCount = t.Columns.Count
    rowCount = t.rows.Count
    
    Dim cellValue As String
    cellValue = t.Cell(0, 0).Range.Text
    
    Dim row As Integer
    Dim col As Integer
    
    For row = 1 To rowCount
        For col = 1 To colCount
        
        cellValue = t.Cell(row, col).Range.Text
                
        Next
    Next
    
Next

' to load a document
Dim app As New Application
Dim doc As Document
doc = app.Documents.Open("C:\Test.doc")




Andez



Andez
  • Edited byAndez Tuesday, September 22, 2009 3:21 PMbad formatting
  •  
Andez

You can use google to search for other answers

Custom Search

More Threads

• Memory leak in timer event
• Managed Memory Leak?
• IList<double> parameter much slower than double[] parameter when function does for looping
• How to mix different languages in one application ?
• .NET Framework 2.0 runtime error
• How to find Install folder of an Assembly which is in GAC
• pass SAFEARRAY from .NET to Native
• Constructing Immutable Instances That Really Are Thread-Safe
• Memory leak in managed-unmanaged mixed mode app
• Converting form from VB 2003 to 2005