写json文本字符串到excel
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 | # -*- coding: utf-8 -*- from xmindparser import xmind_to_dict import xlwt import json import pprint # 记录列数,全局变量,还原方便 columnIndex = 0 # 记录行数 rowIndex = 1 # 记录任务个数 taskCount = 0 if __name__ = = '__main__' : # 用例地址 file_path = 'json.txt' # 使用xlwt模块 wb = xlwt.Workbook(encoding = 'utf-8' ) ws = wb.add_sheet( 'task' , cell_overwrite_ok = True ) title_list = [ '任务ID' , '任务名称' ] # 用例标题写入excel首行 for j in range ( 0 , len (title_list)): ws.write( 0 , j, title_list[j]) j + = 1 # 读取文本 with open (file_path, "r" ) as f: data_json = json.loads(f.read()) print ( '-------------' ) print ( type (data_json)) pprint.pprint(data_json) for j in range ( 0 , len (data_json)): task_id = data_json[j][ 'id' ] task_name = data_json[j][ 'name' ] taskCount + = 1 #任务个数 ws.write(rowIndex, columnIndex, task_id) #写任务id ws.write(rowIndex, columnIndex + 1 , task_name) # 写任务name j + = 1 rowIndex + = 1 print ( '任务总数%s:' % taskCount) # 保存Excel文档 wb.save( 'QtaTaskList.xls' ) |
本文来自博客园,作者:ReluStarry,转载请注明原文链接:https://www.cnblogs.com/relustarry/p/16080712.html
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· Manus的开源复刻OpenManus初探
· .NET Core 中如何实现缓存的预热?
· 阿里巴巴 QwQ-32B真的超越了 DeepSeek R-1吗?
· 如何调用 DeepSeek 的自然语言处理 API 接口并集成到在线客服系统