# -*- coding: utf-8 -*-
import re
import xlwt
a=r'C:\Users\db307\Desktop\py\date\data.txt'
i=1
j=m=0
w = xlwt.Workbook()
ws = w.add_sheet('work')
with open(a) as f:
for line in f:
#print (line)
b=re.split('\s+', line)
while i <=len(b):
#print(b[i])
ws.write(m,1,b[i])
i=i+2
m=m+1
print(m)
m=0
print(m)
while j
<=len(b):
#print(b[j])
ws.write(m,0,b[j])
j=j+2
m=m+1
w.save('date_test.xls')
效果
张三
|
12353
|
李四
|
3241902
|
王二麻子
|
234354
|
芳芳
|
222
|
李鬼
|
333
|
狗蛋
|
2333
|
data.txt
张三 12353 李四 3241902 王二麻子 234354 芳芳 222 李鬼 333 狗蛋 2333
阅读(1641) | 评论(0) | 转发(0) |