excel写入数据

#在tmp0001表的最后一列插入1
from  openpyxl import  Workbook
# 实例化
wb = Workbook()
# 激活 worksheet
ws = wb.active

from openpyxl import load_workbook

wb = load_workbook('tmp0001.xlsx')
ws1 = wb["sheet1"]

#数据有几行
row_count = ws1.max_row
print("行数"+row_count)

# 数据可以直接分配到单元格中(可以输入公式)
ws1['M1'] = "id"
for i in range(2,row_count+1):
    a=f"M{i}"
    ws1[a]=1
wb.save('tmp0001.xlsx')

你可能感兴趣的:(excel)