我想从excel工作簿中读取Calavi多列,然后将所有数据写入Shelda。然而它一直在给我:
for row in range(1, 2, 3, 4, 5,worksheet.max_row):
TypeError: range expected at most 3 arguments, got 6
是否完全有可能使用多列?
wb = openpyxl.load_workbook('C:\WW\CALAVI.xlsx')
first_sheet = wb.get_sheet_names()[0]
worksheet = wb.get_sheet_by_name(first_sheet)
for row in range(1, 2, 3, 4, 5,worksheet.max_row):
for column in "1, 2, 3, 4, 5":
cell_name = "{}{}".format(column, row)
worksheet[cell_name].value
for i in range(3, 8):
ws1.cell(row=i, column=5).value=temp[0]
data = [list('abcd'), list('efgh')]
wb = openpyxl.load_workbook('C:\WW\SHELDA.xlsx')
sheet = wb.active
for i, line in enumerate(data):
for k, val in enumerate(line):
sheet.cell(row=i+2, column=k+1).value = val
wb.save('C:\WW\SHELDA.xlsx')
答案 0 :(得分:0)
由于range
对象使用不当,您会看到错误消息。如果要遍历所有行号,请替换
for row in range(1, 2, 3, 4, 5,worksheet.max_row):
用这个:
for row in range(1, worksheet.max_row + 1):