Hello,
My first posting. I'm new to C# and to Visual Studio, so please forgive me if some of these questions are a little simple.
I'm trying to use and Excel COM object in my application. I have an application VS project that I have downloaded and this compiles and runs perfectly.
Then I've started a new project, and I'm attempting to use the same techniques, but I'm running into problems.
I have added a Reference to the same Excel COM object, and my code for grabbing the content of an Excel spreadsheet is the same, but I'm getting errors like:
"The type or namespace name 'Excel' could not be found (are you missing a using directive or an assembly reference?)"
So, I try to add the line:
using Excel;
into my code, but then I get the same error, even though I can see 'Excel' under the References in Solution Explorer.
I think that whatever is not right also means that Intellisense doesn't list 'Excel' either.
Can anyone tell me what I'm doing wrong here?
Many thanks!
Loading
JamesInsidePosted Jul 8, 2007, 8:03 PM
AlanPosted Jul 6, 2007, 10:01 AM
and the compiler couldn't therefore find them before because it was looking for them in a namespace called, simply, Excel. By placing this line near the top of your program:
using Excel = Microsoft.Office.Interop.Excel;
you've defined an alias of 'Excel' for the full namespace name and so everything is now OK in that regard.
It sounds like you were also using a type or types within the System.Reflection namespace and so the 'using System.Reflection;' directive has brought them into scope as well.
JamesInsidePosted Jul 6, 2007, 3:13 AM
After some more example code searching, I tried adding the lines:
using Excel = Microsoft.Office.Interop.Excel; using System.Reflection;
after the other 'using' lines. This seemed to fix things.
Yes, I think it was referencing the GAC before, would anyone care to explain why adding these lines makes it work, and why the downloaded example doesn't need them?
Jan MontanoPosted Jul 6, 2007, 2:52 AM
Or it is referencing the excel object in GAC (global assembly cache). Try to reference it to the physical DLL instead. Verify the path of the dll you're referencing.