试试这个:
import openpyxl
wb = load_workbook(filename='xxxx.xlsx')
ws = wb.worksheets[0]
ws['A1'] = 1
ws.cell(row=2, column=2).value = 2
ws.cell(coordinate="C3").value = 3 # 'coordinate=' is optional here
这将分别将单元格A1,B2和C3设置为1,2和3(在工作表中设置单元格值的三种不同方式).
第二种方法(指定行和列)对您的情况最有用:
import openpyxl
wb = load_workbook(filename='xxxxx.xlsx')
for ws in wb.worksheets:
for index, row in enumerate(ws.rows, start=1):
print row
x1 = ucr(row[0].value)
ws.cell(row=index, column=2).value = x1