Utilizzo il pacchetto openpyxl
in Python(Canopy)
per utilizzare i file excel. Abbiamo questo tutorial in questo link: LINKCome possiamo usare iter_rows() nel pacchetto Python openpyxl?
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>
Come possiamo importare openpyxl.worksheet.Worksheet.iter_rows()
metodo in Python? Ho usato questo codice:
import openpyxl as op
ms = op.load_workbook('mtest.xlsx')
ws = ms.active
op.worksheet.Worksheet.iter_rows()
questo codice:
type object 'Worksheet' has no attribute 'iter_rows'
Qual è il problema?
Non è necessario attivare iteratori nelle versioni più recenti; i fogli di lavoro standard hanno anche il metodo 'iter_rows()'. –
Grazie - Mi sembra di avere una versione abbastanza vecchia (1.8.3, l'ultima è 2.2.1) - modificherà leggermente la risposta. – DNA
Generalmente vale la pena eseguire l'aggiornamento. Spingerà presto una versione di bug 2.2.2, ma anche 2.2 è più affidabile e più veloce di 1.8 –