Read word tables

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Rameshwari

    #1

    Read word tables


    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




  • Thomas Guettler

    #2
    Re: Read word tables

    Am Tue, 21 Dec 2004 11:24:35 +0000 schrieb Rameshwari:
    [color=blue]
    >
    > 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?[/color]

    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/Coo.../Recipe/192914

    --
    Thomas Güttler, http://www.thomas-guettler.de/


    Comment

    • Andrew Henshaw

      #3
      Re: Read word tables

      Rameshwari wrote:
      [color=blue]
      >
      > 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[/color]

      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(ro w)
      tables.append(t able)
      return tables



      --
      Andrew Henshaw
      Georgia Tech Research Institute

      Comment

      Working...