python操作word表格单元格分割_Python解析Word文档中的表格

该脚本使用Python的win32com库操作Word文档,解析表格内容,将表格数据转换为Robot Framework的测试用例。首先,打开Word文档并获取表格对象,然后读取配置文件,遍历每个表格,提取列名和数据类型信息,生成测试用例文件。测试用例包括列检查和列匹配部分,文件以表格名为后缀的txt格式保存。
摘要由CSDN通过智能技术生成

'''Created on Jan 15, 2013

@author: dongdong.zhang'''

#Install Python for Windows Extension from http://sourceforge.net/projects/pywin32/

importwin32com.client as win32importosimportreimportsysimportgetopt#Load MS Word document and return the document object

defload_word_document(wordFile):

word= win32.Dispatch("Word.Application")

word.Visible=0

word.Documents.Open(wordFile)

doc=word.ActiveDocumentreturndoc#The config file is plain text lines#Each line has two fields separated by white spaces, the first field is index, the second field is the db table name#

#Example:#3 cap_floor#4 coll_grp#5 coll_grp_delinq_hist#6 coll_grp_loan_hist#

#Read each line and store it in a dictionary with the index as key and the table name as value.

defparse_config(configFile):

file_object=open(configFile)

all_lines=file_object.readlines()

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值