Loading... ```python #!/usr/bin/python3 # -*- coding: utf-8 -*- # @Time : 2024-02-29 21:44 # @Author : Administrator # @Email : 2319866766@qq.com # @Website : www.zimopy.com # @File : 操作excel.py # @Project : 各种代码 # @describe : import openpyxl from openpyxl.utils import get_column_letter from openpyxl.styles import Font def create_or_append_excel(file_path, data): try: # 尝试加载现有的Excel文件 wb = openpyxl.load_workbook(file_path) sheet = wb.active except FileNotFoundError: # 如果文件不存在,则创建一个新的Excel文件 wb = openpyxl.Workbook() sheet = wb.active # 添加标题行 sheet.append(['邮箱', '密码']) # 设置标题行字体加粗 for cell in sheet[1]: cell.font = Font(bold=True) # 追加数据 for item in data: sheet.append(item) # 保存Excel文件 wb.save(file_path) wb.close() def read_email_data(file_path): wb = openpyxl.load_workbook(file_path) sheet = wb.active email_data = [] # 从第二行开始读取数据(跳过标题行) for row in sheet.iter_rows(min_row=2, values_only=True): email_data.append([row[0], row[1]]) # 第二列是邮箱 wb.close() return email_data ### 写入结果 def read_bankcard_data(file_path): wb = openpyxl.load_workbook(file_path) sheet = wb.active email_data = [] # 从第二行开始读取数据(跳过标题行) for row in sheet.iter_rows(min_row=2, values_only=True): email_data.append([row[0], row[1], row[2], row[3]]) wb.close() return email_data #####写入邮箱信息 # data_to_append = [ # [ 'exasdmple1@example.com', 'passwodd1'], # [ 'exasdmple2@example.com', 'pasdsdsword2'] # ] # # create_or_append_excel('example.xlsx', data_to_append) ### 读取邮箱信息 # email_data = read_email_data('邮箱.xlsx') # print(email_data) ### 读取卡信息 # bankcard_data = read_bankcard_data('卡.xlsx') # print(bankcard_data) ### 写入结果 data_to_append = [ ["2024-02-30 08:02:21", "4grr8saho@outlook.com", "QDe8140*", "4833160262790105", "02", "2028", "566", "http://www.1777186855896"], ["2024-02-30 08:02:21", "4grr8saho@outlook.com", "QDe8140*", "4833160262790105", "02", "2028", "566", "http://www.t/17771868755896"] ] create_or_append_excel('结果.xlsx', data_to_append) # 先跑,数据后插入 # 未使用邮箱_数量 # 未使用卡_数量 # 记录的报错信息,只有绑卡失败还有付款失败的情况,其他的都不要 # 导出成功只要上一次导出成功之后的 ``` 最后修改:2024 年 03 月 05 日 © 允许规范转载 打赏 赞赏作者 支付宝微信 赞 如果觉得我的文章对你有用,请随意赞赏