Accessing cell by row and column

701 views
Skip to first unread message

Tom Kuiper

unread,
Jul 15, 2015, 8:50:55 PM7/15/15
to openpyx...@googlegroups.com
I just installed openpyxl on a RPi and encountered this surprise:
In [5]: sh = wb.get_sheet_by_name('2015-161')

In [8]: sh.cell(row=1,column=1)
Out[8]: <Cell 2015-161.A1>
I expected cell B2.  Have I missed some significant changed in openpyxl?

If not and this is a bug then it probably accounts for this:
In [10]: sh.calculate_dimension()
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-10-7f6c69cce207> in <module>()
----> 1 sh.calculate_dimension()

/usr/local/lib/python2.7/dist-packages/openpyxl/worksheet/worksheet.pyc in calculate_dimension(self)
    463 
    464         return '%s%d:%s%d' % (
--> 465             get_column_letter(min_col), min_row,
    466             get_column_letter(max_col), max_row
    467         )

/usr/local/lib/python2.7/dist-packages/openpyxl/utils/__init__.pyc in get_column_letter(idx)
     99         return _STRING_COL_CACHE[idx]
    100     except KeyError:
--> 101         raise ValueError("Invalid column index {0}".format(idx))
    102 
    103 

ValueError: Invalid column index 0

The version I down-loaded was openpyxl-2.3.0.

Charlie Clark

unread,
Jul 16, 2015, 3:46:53 AM7/16/15
to openpyx...@googlegroups.com
Hiya Tom,

Am .07.2015, 02:50 Uhr, schrieb Tom Kuiper <tbhk...@gmail.com>:

> I just installed openpyxl on a RPi and encountered this surprise:
> In [5]: sh = wb.get_sheet_by_name('2015-161')
> In [8]: sh.cell(row=1,column=1)
> Out[8]: <Cell 2015-161.A1>
> I expected cell B2. Have I missed some significant changed in openpyxl?

I don't know which version you've been using but this was changed in
version 2:

See http://openpyxl.readthedocs.org/en/2.3.0-b1/changes.html#id124

We changed ws.cell to 1-indexing so that it would be orthogonal with "A1"
style lookups. The idea is to reduce "off by 1" errors when switching
between the two.

> If not and this is a bug then it probably accounts for this:
> In [10]: sh.calculate_dimension()

Not sure why you're calling that method in the first place but it looks
like the worksheet is empty, in which case an exception is a reasonable
result: what are the boundaries of an empty worksheet?

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

Tom Kuiper

unread,
Jul 16, 2015, 10:54:35 AM7/16/15
to openpyx...@googlegroups.com
Thanks for that explanation.  I have been using 1.7 which is the package available under Debian 7.  On this Pi I used pip instead of apt-get and got a newer version.  I will solve the problem for now by uninstalling the PyPI package and installing the Raspbian package.  Then I'll have time to prepare my code for the switch that is (to me) coming.



--
You received this message because you are subscribed to a topic in the Google Groups "openpyxl-users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/openpyxl-users/sjOvJ6Sa3Og/unsubscribe.
To unsubscribe from this group and all its topics, send an email to openpyxl-user...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Charlie Clark

unread,
Jul 16, 2015, 11:22:46 AM7/16/15
to openpyx...@googlegroups.com
Am .07.2015, 16:54 Uhr, schrieb Tom Kuiper <tbhk...@gmail.com>:

> Thanks for that explanation. I have been using 1.7 which is the package
> available under Debian 7. On this Pi I used pip instead of apt-get and
> got
> a newer version. I will solve the problem for now by uninstalling the
> PyPI
> package and installing the Raspbian package. Then I'll have time to
> prepare my code for the switch that is (to me) coming.

That's a bit weird because the Debian guys seem to follow the releases
quite closely. However, I am not really a fan of distros curating Python
packages. The mixing of stuff required for the system and what users need
often causes problems. If you want to run the tests you end up having to
build your own Pythons anyway.
Reply all
Reply to author
Forward
0 new messages