pywin32 icon indicating copy to clipboard operation
pywin32 copied to clipboard

Some date values in Excel cause ValueError: microsecond must be in 0..999999

Open yang-cs opened this issue 5 years ago • 2 comments

There is an excel workbook contains date value 43318.1247685135 or 43609.9708065236 , displayed as 2018/8/6 2:59 and 2019/5/24 23:17 in the cells. Try to read this workbook via xlwings v0.17.0 and pywin32 v227 , using following code:

import xlwings as xw
ws = xw.Book('d:/demo1.xlsx').sheets[0]
print( ws.range('b2:b3').value )

Then got such error prompts:


> Traceback (most recent call last):
>   File "D:/pycharm/test/p/mypackage/e.py", line 3, in <module>
>     print( ws.range('b2:b3').value )
>   File "D:\pycharm\b\venv\lib\site-packages\xlwings\main.py", line 1543, in value
>     return conversion.read(self, None, self._options)
>   File "D:\pycharm\b\venv\lib\site-packages\xlwings\conversion\__init__.py", line 26, in read
>     pipeline(ctx)
>   File "D:\pycharm\b\venv\lib\site-packages\xlwings\conversion\framework.py", line 63, in __call__
>     stage(*args, **kwargs)
>   File "D:\pycharm\b\venv\lib\site-packages\xlwings\conversion\standard.py", line 68, in __call__
>     c.value = c.range.raw_value
>   File "D:\pycharm\b\venv\lib\site-packages\xlwings\main.py", line 1164, in raw_value
>     return self.impl.raw_value
>   File "D:\pycharm\b\venv\lib\site-packages\xlwings\_xlwindows.py", line 725, in raw_value
>     return self.xl.Value
>   File "D:\pycharm\b\venv\lib\site-packages\xlwings\_xlwindows.py", line 116, in __getattr__
>     v = getattr(self._inner, item)
>   File "D:\pycharm\b\venv\lib\site-packages\win32com\client\dynamic.py", line 516, in __getattr__
>     ret = self._oleobj_.Invoke(retEntry.dispid,0,invoke_type,1)
> ValueError: microsecond must be in 0..999999
> 

Solution: Down grade pywin to v225 or lower version, there is no problem with these values.

Have tested the case on four computers, all got same conclusion.

Error in pywin v227 : 227

OK in pywin v225: 1

yang-cs avatar Jan 16 '20 05:01 yang-cs

I have the same error with a (non public) COM interface. A fallback to pywin v225 is no option, as I need the millioseconds introduced in v227.

mohnen avatar Feb 27 '20 13:02 mohnen

same error using .ReceivedTime on an outlook mail, downgrading to v225 works

saucoide avatar Aug 18 '20 08:08 saucoide