mhammond / pywin32

Python for Windows (pywin32) Extensions
4.9k stars 783 forks source link

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

Open yang-cs opened 4 years ago

yang-cs commented 4 years ago

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

mohnen commented 4 years ago

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.

saucoide commented 3 years ago

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