none
Read a word document using c# RRS feed

  • General discussion

  • 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
    Wednesday, September 16, 2009 9:27 AM

All replies

  • 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 by Andez Tuesday, September 22, 2009 3:21 PM bad formatting
    Tuesday, September 22, 2009 3:17 PM