概念

描述

常规文件管理

1.逐行读取文件

with open("jira-user.txt") as f:
    line_list = [line.rstrip() for line in f]
	
print(line_list)

EXCEL管理

1.写入excel

import xlsxwriter

workbook = xlsxwriter.Workbook("user-jira.xlsx") #写到哪个文件里
head_format = workbook.add_format()
head_format.set_bg_color('#00FFFF') #颜色
head_format.set_border(1)
row_format = workbook.add_format()
row_format.set_border(1)

worksheet = workbook.add_worksheet('sheet1') #写到第一页
headings = ["账号", "密码", "备注"]  #标题
worksheet.write_row('A1', headings, head_format)

excel_row = 2
for rds_info in line_list: #循环列表写入
    row = "A" + str(excel_row) #行数增加
    worksheet.write_row(row, rds_info, row_format) #写入rds_info变量里的内容
    excel_row += 1
workbook.close()

实践

文献