Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Python (http://www.velocityreviews.com/forums/f43-python.html)
-   -   Read word tables (http://www.velocityreviews.com/forums/t339502-read-word-tables.html)

Rameshwari 12-21-2004 11:24 AM

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 12-21-2004 01:49 PM

Re: Read word tables
 
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/Coo.../Recipe/192914

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



Andrew Henshaw 12-21-2004 07:37 PM

Re: Read word tables
 
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



All times are GMT. The time now is 04:23 PM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.