|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
记录给自己写的第一个程序,也请大佬们指教改进
代码如下:
import openpyxl
workbook = openpyxl.load_workbook(r'C:\Users\Vian\Desktop\五金\五金.xlsx')
worksheet = workbook.active
a = list(range(2, 59642, 5964))
b = 59644 #加一位数是准确的
# 在B2到B10之间写入1
for i in range(a[0], a[1]):
worksheet.cell(row=i, column=2, value=0)
for i in range(a[1], a[2]):
worksheet.cell(row=i, column=2, value=1)
for i in range(a[2], a[3]):
worksheet.cell(row=i, column=2, value=2)
for i in range(a[3], a[4]):
worksheet.cell(row=i, column=2, value=3)
for i in range(a[4], a[5]):
worksheet.cell(row=i, column=2, value=4)
for i in range(a[5], a[6]):
worksheet.cell(row=i, column=2, value=5)
for i in range(a[6], a[7]):
worksheet.cell(row=i, column=2, value=6)
for i in range(a[7], a[8]):
worksheet.cell(row=i, column=2, value=7)
for i in range(a[8], a[9]):
worksheet.cell(row=i, column=2, value=8)
for i in range(a[9], b):
worksheet.cell(row=i, column=2, value=9)
# 保存Excel文件
workbook.save(r'C:\Users\Vian\Desktop\example.xlsx') |
|