我编写的代码将数据输入到网站的不同字段中,但前提是excel单元格中有数据。这是我的代码:
import openpyxl
import pyautogui
import pyperclip
import time
def copy():
pyautogui.keyDown('ctrl')
pyautogui.press('c')
pyautogui.keyUp('ctrl')
excelWorkbook = openpyxl.load_workbook('orderCodes.xlsx')
sheet = excelWorkbook.get_sheet_by_name('Sheet1')
for i in sheet.columns[1]:
info=sheet['A'+i].value
pyautogui.moveTo(305, 669, duration=0.25)
pyautogui.click()
pyautogui.typewrite(info)
pyautogui.moveTo(295, 702, duration=0.25)
pyautogui.click()
pyautogui.typewrite('100')
pyautogui.moveTo(217, 738, duration=0.25)
pyautogui.click()
time.sleep(1)
pyautogui.moveTo(1521, 515, duration=0.25)
pyautogui.dragTo(1531, 518, duration=0.25)
quantity=copy()
sheet['B'+i]=quantity
但是我收到了这个错误:
for i in sheet.columns[1]:
TypeError: 'generator' object has no attribute '__getitem__'
为什么我会这样做?
答案 0 :(得分:4)
sheet.columns是一个生成器,你不能__getitem__
它。 (使用[]获取某些内容)尝试
for i in sheet.columns: