python txt、excel读写

#从txt写入excel
workbook = xlsxwriter.Workbook('植保网.xlsx') #创建工作簿
sheet = workbook.add_worksheet()
r=0
for line in open('zgzbao_link.1.txt','r',encoding='utf-8'):
line=eval(line)
for m in range(2):
sheet.write(r,m,line[m])
r=r+1
workbook.close()
#从excel写入txt
xl = xlrd.open_workbook('植保网.xlsx')
table1 = xl.sheet_by_name(u"Sheet1")
nr=table1.nrows
f2= open('zgzbao_repeat.txt','w+',encoding='utf-8')
for i in range(nr):
row=table1.row_values(i)
f2.write(str(row[:2])+'\n')
f2.close()
 
 
posted @ 2019-01-07 21:30  绮梦璇玑  阅读(839)  评论(0编辑  收藏  举报