ps:前两天盆友太忙,临时叫我晚上给他帮忙填下excel,都是给个text复制粘贴,我就临时想着用python来释放双手,但也没用完全释放,有一点bug,因时间问题,我也不想改了,反正影响不大。下面是我的源代码
# -*- coding: utf-8 -*- import xlwt, sys zl_lists = [] final_value = [] column_num = int(sys.argv[1]) def read_text(): open_file = open('C:\\Users\\XuanQu\\Desktop\\zl.txt','r',encoding='utf-8') zl = open_file.readlines() for i in zl: zl_lists.append(i) open_file.close() def filtering(): for i in zl_lists: filtering_results = i.split(':',1)[1] final_value.append(filtering_results) def w_excel(num): book = xlwt.Workbook(encoding='utf-8',style_compression=0) sheet = book.add_sheet('zll',cell_overwrite_ok=True) h_row=num l_row=2 for data in final_value: sheet.write(h_row,l_row,data) l_row += 1 if l_row == 11: sheet.write(h_row,l_row,data) l_row -= 9 h_row += 1 save_path = 'C:\\Users\\XuanQu\\Desktop\\zll.xls' book.save(save_path) def main(): read_text() filtering() w_excel(column_num) if __name__ == "__main__": main()