Python小工具—txt转excel和word
创始人
2025-01-09 08:05:56
0

1.txt转excel

import openpyxl  # 创建一个新的Excel工作簿 wb = openpyxl.Workbook() sheet = wb.active  # 题干和答案的标题 sheet['A1'] = '题干' sheet['B1'] = '答案'  # 打开txt文件并读取内容 with open('xiti.txt', 'r', encoding='utf-8') as file:     lines = file.readlines()  # 初始变量 current_question = [] current_answer = '' row = 2  # 从第二行开始写入数据  # 遍历文件内容 for line in lines:     line = line.strip()  # 去除每行的两端空白字符     if line.startswith('答案'):         # 遇到答案关键字,保存当前题干         if current_question:             question_text = '\n'.join(current_question)             sheet.cell(row=row, column=1).value = question_text             # 保存当前答案,并重置current_answer             sheet.cell(row=row, column=2).value = current_answer             row += 1         # 保存答案文本,并重置current_question         current_answer = line[len('答案'):].strip()   

相关内容

热门资讯

透视挂透视!wpk有脚本吗(透... 透视挂透视!wpk有脚本吗(透视)详细辅助解密教程(一贯真的是有挂);wpk有脚本吗辅助器中分为三种...
透视美元局!wepokerh5... 自定义wepokerh5破解系统规律,只需要输入自己想要的开挂功能,一键便可以生成出微扑克专用辅助器...
透视好牌!wepoke辅助技巧... 透视好牌!wepoke辅助技巧,wepoke德扑之星,详细透视可靠技巧1、首先打开wepoke辅助技...
透视有挂(WEPOKE)wop... 1、透视有挂(WEPOKE)wopoker分析器(透视)详细辅助教你攻略;详细教程。2、wopoke...
透视科技!hhpoker透视方... 透视科技!hhpoker透视方法(透视)详细辅助爆料教程(原来是有挂)1、hhpoker透视方法ai...
透视系统!德州透视插件(透视)... 透视系统!德州透视插件(透视)素来真的有挂(详细辅助可靠教程)1、许多玩家不知道德州透视插件辅助软件...
透视美元局!wepoke有挂,... 透视美元局!wepoke有挂,wopoker外挂,详细透视靠谱教程1、下载好wepoke有挂辅助软件...
透视科技(WepOke)线上德... 透视科技(WepOke)线上德州辅助工具(透视)详细辅助透明挂教程;支持多人共享记分板与复盘,通过邀...
透视好友房!wpk有脚本吗(透... 透视好友房!wpk有脚本吗(透视)详细辅助wpk教程(一直真的是有挂)1、下载好wpk有脚本吗辅助软...
透视ai!wepoke有挂,w... 透视ai!wepoke有挂,wepork私人局有挂吗,详细透视微扑克教程1、不需要AI权限,帮助你快...