python将txt内容写⼊excel #!/usr/bin/env python
# -*- coding: utf-8 -*
import os
import xlrd
import xlwt
import datetime
import re
from utils.XUtils import XUtils
def create_and_write_data_to_excel(p_file_name_prefix=None, p_sheetname=None, p_data=None):变更通知书
wbk = xlwt.Workbook()
if p_sheetname is None:
二等残废p_sheetname = 'Sheet1'
sheet = wbk.add_sheet(p_sheetname, cell_overwrite_ok=True)
for i in xrange(len(p_data)):
下完这场雨后弦for j in xrange(len(p_data[i])):
sheet.write(i, j, p_data[i][j])海的女儿作者是谁
filename = p_file_name_prefix + w().strftime("%Y-%m-%d_%H-%M-%S") + ".xls"
摄影大师作品wbk.save(filename)
return wbk
if__name__ == '__main__':
module_path = os.path.dirname(__file__)
filename = module_path + '/report_db_20180301_20180302_11881.2_0_'
"""
txt 内容
gdt 20180301 -1.0000 6 2 0.3333 -0.1667 -0.5000
gdt 20180302 -1.0000 4 1 0.2500 -0.2500 -1.0000
gdt SUM 11881.2000 10 3 0.3000 1188.1200 3960.4000
all_acc=10, new_acc=3, r=0.3000 unit_price_all=1188.120000 unit_price_new=3960.400000
#新建⼀个总的列表
按照每⾏读取txt,按照空格分割成⼀个⼩的列表,append到⼤的列表,后进⾏写⼊excel生活是一本书
"""
fopen2 = open(filename, 'r')
lines = adlines()
安全文明施工标语
all_list = []
excel_title = [u'⼴点通',u'⽇期',u'收⼊',u'总激活数',u'新增激活数',u'新增激活数/总激活数',u'总激活单价',u'新增激活单价'] all_list.append(excel_title)
for line in lines:
# charts to list
l1 = re.split('[ ]+', line)
all_list.append(l1)
做什么工作工资高
create_and_write_data_to_excel(p_file_name_prefix='txt_to_excel',p_sheetname='test1',p_data=all_list)
print('success')