Reading excel using Microsoft::Office::Interop::Excel vc++
Posted on 2009-05-10
Im using visual studio 2008 and am working with windows form application . I can write data to a particular cell using Microsoft:Office::Interop::Excel: Worksheet->Cells->Item[x,y]=DataIwantToWrite
but am having difficulty trying to read data. Not sure how that can be done. This is what i have so far:
String^ buf= (String^)worksheet->Cells->Item[x,y];
but I am getting an exception on second line:
"An unhandled exception of type 'System.InvalidCastException' occurred"
"Additional information: Unable to cast COM object of type 'System.__ComObject' to class type 'System.String'. Instances of types that represent COM components cannot be cast to types that do not represent COM components; however they can be cast to interfaces as long as the underlying COM component supports QueryInterface calls for the IID of the interface."