Meaning of exception in C# app: “Not a legal OleAut date”?

后端 未结 6 1953
暖寄归人
暖寄归人 2020-12-20 12:03

Does anyone know what this means. Getting this in C# winforms applications:

Not a legal OleAut date

相关标签:
6条回答
  • 2020-12-20 12:36

    What I found was that a column with a large row_id '257381195' was attempting to be read by Excel as a Date. What I ended up doing was altering that column's data to a string by preceding the row_id with a single quote. This resolved my issue. Hope this helps.

    0 讨论(0)
  • 2020-12-20 12:48

    I've used:

    try
    {
        if (folderItem.ModifyDate.Year != 1899)
        {
            this.FileModifiedDate = folderItem.ModifyDate.ToShortDateString() + 
                " " +
                folderItem.ModifyDate.ToLongTimeString();
        }
    }
    //we need this because it throws an exception if it's an invalid date...
    catch (ArgumentException) { } 
    

    to deal with the same problem I'm having. It throws the exception when we check the year in my case. Doing nothing on an invalid date is exactly the behavior I want, so this hack works.

    0 讨论(0)
  • 2020-12-20 12:52

    It means you provided an invalid date somewhere, attempting to convert to or from an OLE Automation date outside the valid range 1-January-4713 BC to 31-December-9999 AD. A possible cause is that it might have slipped through because OLE Automation Dates are represented as a double.

    0 讨论(0)
  • 2020-12-20 12:55

    It means that somewhere in the program is attempting to convert to or from an OLE Automation Date outside the valid range 1-January-4713 BC to 31-December-9999 AD. It might have slipped through because OLE Automation Dates are represented as a double.

    Start by looking for any uses of the methods:

    DateTime.FromOADate

    DateTime.ToOADate

    0 讨论(0)
  • 2020-12-20 12:56

    An OADate is represented as a double value whose value is the number of days from midnight on 30 december 1899 (negative values representing earlier dates).

    This exception is thrown when trying to convert a value that is outside the valid range of Ole Automation dates to/from a .NET DateTime value (methods DateTime.FromOADate and DateTime.ToOADate - which are also used implicitly for COM Interop).

    I believe to be valid for conversion to an OADate the .NET DateTime value needs to be strictly greater than 01/01/0100.

    To convert from OADate to a .NET DateTime value, the double value needs to be strictly greater than -657435 (= 01/01/0100) and strictly less than 2958466.0 (01/01/10000).

    0 讨论(0)
  • 2020-12-20 12:57

    Others have struggled with this. I suggest looking at these threads on DotNetNuke and DevShed.

    0 讨论(0)
提交回复
热议问题