怎么把数据写入特定名称的某行某列
时间: 2023-12-15 14:06:24 浏览: 136
可以使用Python中的openpyxl库来实现。下面是一些示例代码,可以帮助你将数据写入特定名称的Excel文件中的某行某列:
```python
import openpyxl
# 打开Excel文件
wb = openpyxl.load_workbook('path/to/excel/file.xlsx')
# 选择工作表
ws = wb['Sheet1']
# 将数据写入特定行列
ws.cell(row=1, column=1, value='姓名')
ws.cell(row=1, column=2, value='年龄')
ws.cell(row=2, column=1, value='张三')
ws.cell(row=2, column=2, value=20)
# 保存Excel文件
wb.save('path/to/excel/file.xlsx')
```
在上述代码中,我们首先使用openpyxl库中的load_workbook函数打开了Excel文件。然后,我们使用工作簿中的一个工作表(Sheet1)来获取一个Worksheet对象。接着,我们使用Worksheet对象的cell方法来写入数据到特定的行列。最后,我们使用工作簿的save方法将更改保存到Excel文件中。
你可以根据自己的需求,修改上述示例代码来实现你的任务。
阅读全文
相关推荐


















