有没有大佬帮忙看一下,之前写的用openpyxl造数据的代码,现在不能运行了;
代码如下:
'''导入方法包'''
from openpyxl import load_workbook
from openpyxl import Workbook
import random
import string
'''打开文件'''
aa.save('test.xlsx')
wb = load_workbook('test.xlsx')
print(wb.sheetnames)
'''打开Sheet表格'''
sheet5 = wb['Sheet5']
max = sheet5.max_row
sheet5['A1'] = 'USERNAME'
sheet5['B1'] = 'PASWORD'
for i in range(2, 5):
num = random.randint(1, 10000)
s = str(num)
str_001 = sheet5.cell(row=i, column=1).value=("User_" + s)
for i in range(2, 5):
num = random.randint(100000, 1000000)
s = str(num)
str_001 = sheet5.cell(row=i, column=2).value=("pwd." + s)
wb.save('test.xlsx')
报错如下:
D:\MyData\ex_chencw2\AppData\Local\Programs\Python\Python39\python.exe D:/MyData/ex_chencw2/Desktop/python/接口自动化/openpyxl_造数据.py
Traceback (most recent call last):
File "D:\MyData\ex_chencw2\Desktop\python\接口自动化\openpyxl_造数据.py", line 8, in <module>
aa.save('test.xlsx')
NameError: name 'aa' is not defined
#openpyxl问题