How do I check using openpyxl the number of rows with data in them without scanning all rows within the spreadsheet

12,235 views
Skip to first unread message

Hitesh Patel

unread,
Feb 5, 2014, 6:15:40 PM2/5/14
to openpyx...@googlegroups.com
Any help will be great.

Charlie Clark

unread,
Feb 5, 2014, 6:20:24 PM2/5/14
to openpyx...@googlegroups.com
Am .02.2014, 00:15 Uhr, schrieb Hitesh Patel <pet...@gmail.com>:

> Any help will be great.

Look at the IterableWorksheet code. Something like the following should
give you what you need.

wb = load_workbook(filename, use_iterators=True)
ws = wb[sheetname]

ws.min_col, ws.min_row, ws.max_col, ws.max_row

Charlie
--
Charlie Clark
Managing Director
Clark Consulting & Research
German Office
Kronenstr. 27a
Düsseldorf
D- 40217
Tel: +49-211-600-3657
Mobile: +49-178-782-6226

Hitesh Patel

unread,
Feb 6, 2014, 12:36:36 PM2/6/14
to openpyx...@googlegroups.com
Is there a way just to fine the last cell in the column or last row as I got the the incorrect value for ws.max_col

>>> ws.min_col, ws.min_row, ws.max_col, ws.max_row
('A', 1, 'BG', 877)

I should have got A, 1, F, 877

cheers for any help you can provide

Charlie Clark

unread,
Feb 6, 2014, 1:12:29 PM2/6/14
to openpyx...@googlegroups.com
Am .02.2014, 18:36 Uhr, schrieb Hitesh Patel <pet...@gmail.com>:

Hi Hiresh,

> Is there a way just to fine the last cell in the column or last row as I
> got the the incorrect value for *ws.max_col*
>
>>>> ws.min_col, ws.min_row, ws.max_col, ws.max_row
> ('A', 1, 'BG', 877)
> I should have got A, 1, F, 877
> cheers for any help you can provide

hm, looks very suspicious but I'd need the file to investigate.

Hitesh Patel

unread,
Feb 6, 2014, 6:46:20 PM2/6/14
to openpyx...@googlegroups.com
Ok there was something wrong with the xlsx file, cheers for helping.

Do you know how I can find the last row in a column?
Reply all
Reply to author
Forward
0 new messages