[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 422
  • Last Modified:

Error reading a date from an excel spreadsheet

Hello experts:
I'm having an issue getting a date colum from excel into another field.

double d = 38449.0;
DateTime dt = DateTime.FromOADate(d);
 dt = Convert.ToDateTime(range.Cells[rCnt, cCnt]);

the last statement generates this error:

Invalid cast exception was unhandled
Unable to cast COM object of type 'System.__ComObject' to interface type 'System.IConvertible'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{805E3B62-B5E9-393D-8941-377D8BF4556B}' failed due to the following error: No such interface supported (Exception from HRESULT: 0x80004002 (E_NOINTERFACE)).
1 Solution
Anurag ThakurCommented:
something wrong is happening here and see this link and according to msdn it will always throw exception

the following link provides how datetime can be initialized in .Net

Featured Post

Visualize your virtual and backup environments

Create well-organized and polished visualizations of your virtual and backup environments when planning VMware vSphere, Microsoft Hyper-V or Veeam deployments. It helps you to gain better visibility and valuable business insights.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now