#encoding:utf-8
'''
日期:2017.6.12
作者:静的学习日志
功能: 从word中读取数据,写入excel
'''
import xlrd
import xlwt
from docx import Document
doc1=Document(u'D:\Python27_Test\D1.docx')
file=xlwt.Workbook(u'D:\Python27_Test\Test.xls')
table1=file.add_sheet(u'test1')
tables = [table for table in doc1.tables]
i=0
j=0
for table in tables:
#标题
T1=table.rows[0].cells[0].text.encode('gb2312')
#版本号
T2=table.rows[1].cells[1].text.encode('gb2312')
#步骤
T3=table.rows[3].cells[0].text.encode('gb2312')
#期望结果
T4=table.rows[4].cells[0].text.encode('gb2312')
#需求编号
T5=table.rows[5].cells[1].text.encode('gb2312')
#最终结果
T6=table.rows[6].cells[1].text.encode('gb2312')
#执行时间
T7=table.rows[7].cells[1].text.encode('gb2312')
#执行者
T8=table.rows[8].cells[1].text.encode('gb2312')
#测试备注
T9=table.rows[9].cells[1].text.encode('gb2312')
list=[T1,T2,T3,T4,T5,T6,T7,T8,T9]
for j in range(9):
table1.write(i,j,list[j].decode('gb2312'))
i=i+1
file.save(u'TEST.xls')