从python中的docx文件中提取数据 [英] extracting data from docx files in python

查看:504
本文介绍了从python中的docx文件中提取数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从扩展名为docx的Word文档中提取数据.本文档包含一个表格.我想从表的每一列和每一行中获取数据.

I want to extract data from a word document with extension docx. This document contains a table. I want to fetch the data from each column and row of the table.

然后我要处理数据并将其插入到其各自字段下的Excel文件中.

then I would like to process the data and insert it into an Excel file under their respective fields.

任何人都可以指导我如何在python中执行此操作.

Can anyone please guide me how to do this in python.

我在Windows 7上使用python3.(可能还想在Windows Server 2003上运行此代码).

I am using python3 on windows 7. (Might also want to run this code on windows sever 2003).

任何帮助将不胜感激.

谢谢

推荐答案

尝试类似的方法:

import win32com.client as w32c

Word = w32c.Dispatch("Word.Application")
Word.Visible=1
doc=Word.Documents.Open("C:\\docx_with_a_table.docx")
tables=doc.Tables
for t_cnt in range(tables.Count):
    table=tables[t_cnt]
    for r_cnt in range(table.Rows.Count):
        row=table.Rows[r_cnt]
        for c_cnt in range(row.Cells.Count):
            cell=row.Cells[c_cnt]
            print(cell.Range.Text)

Word文档上的ALT + F11和F2将显示VBA对象...在Perl中,上述过程得到了更好的记录.

ALT+F11 and F2 on a Word doc will show VBA objects... In Perl the above procedure is better documented.

Python3的xlrd3和xlwt3软件包很好地支持Excel的读写.

Reading and writing to Excel is well supported by Python3's packages xlrd3 and xlwt3

这篇关于从python中的docx文件中提取数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆