Wie können wir iter_rows () im Python openpyxl-Paket verwenden?
Ich benutzeopenpyxl
Paket inPython(Canopy)
, um Excel-Dateien zu verwenden. Wir haben dieses Tutorial in diesem Link:VERKNÜPFUN
you can also use the openpyxl.worksheet.Worksheet.iter_rows() method:
>>> tuple(ws.iter_rows('A1:C2'))
((<Cell Sheet1.A1>, <Cell Sheet1.B1>, <Cell Sheet1.C1>),
(<Cell Sheet1.A2>, <Cell Sheet1.B2>, <Cell Sheet1.C2>))
>>> for row in ws.iter_rows('A1:C2'):
... for cell in row:
... print cell
<Cell Sheet1.A1>
<Cell Sheet1.B1>
<Cell Sheet1.C1>
<Cell Sheet1.A2>
<Cell Sheet1.B2>
<Cell Sheet1.C2>
Wie wir importieren könnenopenpyxl.worksheet.Worksheet.iter_rows()
Methode in Python? Ich habe diesen Code benutzt:
import openpyxl as op
ms = op.load_workbook('mtest.xlsx')
ws = ms.active
op.worksheet.Worksheet.iter_rows()
Dieser Code gibt Folgendes zurück:
type object 'Worksheet' has no attribute 'iter_rows'
Worin besteht das Problem