您好,我正在从论坛中的几个答案中逐行重复,并使用row_offset = 1,但它不会跳过标题,请检查并提供帮助。
> import openpyxl
>
> Owb= openpyxl.load_workbook("E:\\First.xlsx") Ows = Owb.worksheets[0]
>
> row_counter=1
>
> for row in Ows.iter_rows(row_offset=1):
>
> policy_number=Ows.cell(row=row_counter,column=1).value
> print policy_number
> Ows.cell(row=row_counter, column=2).value = "test value"
>
> row_counter = row_counter + 1
> Owb.save("E:\\First.xlsx")
答案 0 :(得分:1)
您的代码有几个问题:
为什么不从第二行开始。
import openpyxl
Owb= openpyxl.load_workbook("E:\\First.xlsx")
Ows = Owb.worksheets[0]
for rowno, rowval in enumerate(Ows.iter_rows(min_row=2, max_row=Ows.max_row), start=2):
for cell in rowval:
policy_number=Ows.cell(row=rowno,column=1).value
print policy_number
Ows.cell(row=rowno, column=2).value = "test value"
Owb.save("E:\First.xlsx")