Read word tables

Discussion in 'Python' started by Rameshwari, Dec 21, 2004.

  1. Rameshwari

    Rameshwari Guest

    Hi,

    I would like to read a ms-word document using python.

    Basically the word document contains number of tables and the rows
    in each table do not have same number of columns.

    Does anyone have a sample code to read a table?

    Thank you
    Best Regards,
    Rameshwari
     
    Rameshwari, Dec 21, 2004
    #1
    1. Advertising

  2. Am Tue, 21 Dec 2004 11:24:35 +0000 schrieb Rameshwari:

    >
    > Hi,
    >
    > I would like to read a ms-word document using python.
    >
    > Basically the word document contains number of tables and the rows
    > in each table do not have same number of columns.
    >
    > Does anyone have a sample code to read a table?


    Hi,

    There is a small script[1] which parses the XML produced
    by Excel. Something like this should be possible for msword, too.

    Other way: You can export to the openoffice format and unzip it.
    The read these xml files.

    HTH,
    Thomas

    [1]:http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/192914

    --
    Thomas G├╝ttler, http://www.thomas-guettler.de/
     
    Thomas Guettler, Dec 21, 2004
    #2
    1. Advertising

  3. Rameshwari wrote:

    >
    > Hi,
    >
    > I would like to read a ms-word document using python.
    >
    > Basically the word document contains number of tables and the rows
    > in each table do not have same number of columns.
    >
    > Does anyone have a sample code to read a table?
    >
    > Thank you
    > Best Regards,
    > Rameshwari


    The following code should return a list of list of lists
    (tables->table->rows->cells) for the active document in
    Microsoft Word.

    Warning! Untested code

    ########################
    import win32com.client

    def GetTables():
    app = win32com.client.Dispatch('Word.Application')
    doc = app.Documents[0]
    tables = []
    for word_table in doc.Tables:
    table = []
    for word_row in word_table.Rows:
    row = [cell.Range.Text for cell in word_row.Cells]
    table.append(row)
    tables.append(table)
    return tables



    --
    Andrew Henshaw
    Georgia Tech Research Institute
     
    Andrew Henshaw, Dec 21, 2004
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. m3ckon
    Replies:
    3
    Views:
    3,515
    m3ckon
    Aug 5, 2004
  2. nish
    Replies:
    1
    Views:
    12,400
    mthakershi
    Aug 8, 2006
  3. Peter Bassett
    Replies:
    3
    Views:
    939
    Augustus
    Aug 15, 2003
  4. Otuatail

    Tables within tables

    Otuatail, Jul 31, 2004, in forum: HTML
    Replies:
    7
    Views:
    503
  5. Chris Brat
    Replies:
    5
    Views:
    700
    =?iso-8859-1?q?Luis_M._Gonz=E1lez?=
    Aug 22, 2006
Loading...

Share This Page