Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #95402 > unrolled thread
| Started by | Sven Boden <sven.boden@gmail.com> |
|---|---|
| First post | 2015-08-16 09:53 -0700 |
| Last post | 2015-08-16 17:39 -0400 |
| Articles | 5 — 5 participants |
Back to article view | Back to comp.lang.python
-2146826246 in win32com.client for empty #N/A cell in Excel Sven Boden <sven.boden@gmail.com> - 2015-08-16 09:53 -0700
Re: -2146826246 in win32com.client for empty #N/A cell in Excel Chris Angelico <rosuav@gmail.com> - 2015-08-17 04:41 +1000
Re: -2146826246 in win32com.client for empty #N/A cell in Excel Laura Creighton <lac@openend.se> - 2015-08-16 21:49 +0200
Re: -2146826246 in win32com.client for empty #N/A cell in Excel Nobody <nobody@nowhere.invalid> - 2015-08-16 22:37 +0100
Re: -2146826246 in win32com.client for empty #N/A cell in Excel random832@fastmail.us - 2015-08-16 17:39 -0400
| From | Sven Boden <sven.boden@gmail.com> |
|---|---|
| Date | 2015-08-16 09:53 -0700 |
| Subject | -2146826246 in win32com.client for empty #N/A cell in Excel |
| Message-ID | <29fb0de6-2d4a-4392-9c85-8f1633ad5454@googlegroups.com> |
Anyone know how to handle "#N/A" in Excel from win32com.client.
I'm extracting data from an Excel file using win32com.client. Everything works fine except for when the value "#N/A" is entered in excel. An empty cell. I assumed I do something as
if ws.Cells(r, c).Value is None:
...
But that doesn't seem to work. When I debug the piece of code while handling #N/A in a cell the type of the cell according to win32com.client is int and the value in the cell is -2146826246. Chances are small just this number will appear in Excel, but it looks dirty to depend on that value to decide if a cell is empty. Looked around the net for a solution, but nothing came up so far.
Anyone knows how to handle a "#N/A" cell in Excel in the proper way?
Regards,
Sven
[toc] | [next] | [standalone]
| From | Chris Angelico <rosuav@gmail.com> |
|---|---|
| Date | 2015-08-17 04:41 +1000 |
| Message-ID | <mailman.41.1439750470.4764.python-list@python.org> |
| In reply to | #95402 |
On Mon, Aug 17, 2015 at 3:27 AM, Albert-Jan Roskam <sjeik_appie@hotmail.com> wrote: > Does that number happen to be -1 * sys.maxint? No, it's -1 * 0x7ff5f806. As a signed 32-bit integer, it's 0x800a07fa. Does either of those numbers mean anything? Sven, you might do better to ask on a dedicated Python + Win32 mailing list; I haven't used Python on Windows much for a while. ChrisA
[toc] | [prev] | [next] | [standalone]
| From | Laura Creighton <lac@openend.se> |
|---|---|
| Date | 2015-08-16 21:49 +0200 |
| Message-ID | <mailman.43.1439754568.4764.python-list@python.org> |
| In reply to | #95402 |
For what it's worth, I use xlrd for this. http://www.python-excel.org/ Laura
[toc] | [prev] | [next] | [standalone]
| From | Nobody <nobody@nowhere.invalid> |
|---|---|
| Date | 2015-08-16 22:37 +0100 |
| Message-ID | <pan.2015.08.16.21.37.51.335000@nowhere.invalid> |
| In reply to | #95402 |
On Sun, 16 Aug 2015 09:53:32 -0700, Sven Boden wrote: > Anyone knows how to handle a "#N/A" cell in Excel in the proper way? 0x800A07FA is how xlErrNA (error 2042) is marshalled. This isn't specific to Python; you'll get the same value using e.g C# or VB.NET. There's a fairly thorough article on this topic at: https://xldennis.wordpress.com/2006/11/22/ https://xldennis.wordpress.com/2006/11/29/
[toc] | [prev] | [next] | [standalone]
| From | random832@fastmail.us |
|---|---|
| Date | 2015-08-16 17:39 -0400 |
| Message-ID | <mailman.46.1439761174.4764.python-list@python.org> |
| In reply to | #95402 |
On Sun, Aug 16, 2015, at 14:41, Chris Angelico wrote: > On Mon, Aug 17, 2015 at 3:27 AM, Albert-Jan Roskam > <sjeik_appie@hotmail.com> wrote: > > Does that number happen to be -1 * sys.maxint? > > No, it's -1 * 0x7ff5f806. As a signed 32-bit integer, it's 0x800a07fa. > Does either of those numbers mean anything? That's a COM error code, for Excel error 2042, which (unsurprisingly) means N/A. http://stackoverflow.com/questions/7526640/any-ideas-why-excel-interop-reads-many-decimals-as-2146826246 Here's some information from someone having the same problem in .NET, which may or may not be helpful https://xldennis.wordpress.com/2006/11/22/dealing-with-cverr-values-in-net-%E2%80%93-part-i-the-problem/ It looks like the values are actually returned as a VT_ERROR variant, which .NET (and apparently python) reads as an integer.
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.python
csiph-web