需求:将txt文本中的数据插入到excel中的不同表中,并为每个sheet表添加表头
如果在txt文本中已经有表头,则只需要建立个list列表,将txt名写入列表中,遍历list列表,然后将txt文本写入excel中
因为文件过大,所以这里用了openpyxl,xlwt仅能插入255行,不能满足数据量大的情况
# coding=utf-8
import os
from openpyxl import Workbook
os.chdir('E:/pycharm/Test/profile/')
file_path = 'all.xlsx'#要写入的文件
wb = Workbook()
def write_excel(txt_name,sheet):
f1 = open(txt_name, 'r', encoding='utf-8')
lines = f1.readlines()
for line in lines:
split_line = line.split('\t')
sheet.append(split_line)
app_list = ['brand','cate1','cate2','app_name','uv']
attribute_list = ['category','brand','keyword','uv']
city_list = ['category','brand','city_num','cate2']
keyword_list = ['b