python 使用openpyxl将数据:[{"name":"li","age":18},{"name":"wang","age":24}] 写道Excel文件中
时间: 2023-08-14 11:03:36 浏览: 105
要使用openpyxl将数据写入Excel文件中,可以按照以下步骤进行操作:
1. 首先,导入openpyxl库:import openpyxl
2. 创建一个新的Excel工作簿:wb = openpyxl.Workbook()
3. 选择要操作的工作表:ws = wb.active
4. 定义要写入的数据:data = \[{"name":"li","age":18},{"name":"wang","age":24}\]
5. 遍历数据列表,逐行写入Excel表格中:for i, item in enumerate(data, start=1): ws.cell(row=i, column=1, value=item\["name"\]) ws.cell(row=i, column=2, value=item\["age"\])
6. 保存Excel文件:wb.save("filename.xlsx")
这样,数据就会被写入到名为"filename.xlsx"的Excel文件中了。请注意,这里假设你已经安装了openpyxl库。
#### 引用[.reference_title]
- *1* *3* [010 python数据结构与算法:算法概论;时间复杂度](https://blog.csdn.net/qq_34539676/article/details/106865325)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insert_down28v1,239^v3^insert_chatgpt"}} ] [.reference_item]
- *2* [快速入门(完整):Python实例100个(基于最新Python3.7版本)](https://blog.csdn.net/weixin_41084236/article/details/81564963)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insert_down28v1,239^v3^insert_chatgpt"}} ] [.reference_item]
[ .reference_list ]
阅读全文