0

For my work, I needed .net excel application for reading some data from excel sheet. I decided to use .NET dlls for my goal. I added the references.(from .COM tab, I don't know if I'm sure or not because there is no Microsoft.Office in .NET tab in add reference section.) But when i write my code as microsoft.office.interop.excel or excel.workbook , it gives error and says it's illegal, use of namespace identifier. I searched the internet but all the solutions says that "you should add reference". But I added excel as reference already? Can you give me solution for this asap?

  • 1
    have you checked out this question? http://stackoverflow.com/questions/10477977/what-reference-do-i-need-to-use-microsoft-office-interop-excel-in-net – aw04 Aug 04 '14 at 13:34

1 Answers1

0
  1. Make sure Excel and Office are referenced (as shown in the image showing the "Recent" tab in the "Add a reference" option) enter image description here

  2. Add the proper Using in your program. Add this at the very beginning of your program :

    using Microsoft.Office.Interop;
    using Microsoft.Office.Interop.Outlook;
    using Microsoft.Office.Interop.Excel;
    using System.Runtime.InteropServices;
    
Sifu
  • 1,082
  • 8
  • 26
  • They will only show up in recent if you recently choose them. You need to look under `COM` or `.NET` – Scott Chamberlain Aug 04 '14 at 13:36
  • @ScottChamberlain That's why I asked her to verify if they were in that tab. Because if they weren't referenced, they wouldn't show in that tab. – Sifu Aug 04 '14 at 13:37
  • They are shown in the recent option. But when I trying to write using Microsoft.Office.Interop or others, the intellisense will not recognize after the dot and the same error happens again. – misscalypso Aug 04 '14 at 18:48
  • @misscalypso You have added the `Using`s? (See #2 in my answer) – Sifu Aug 04 '14 at 18:58
  • I added 'Using' but I solved the problem. I did not put using and define all the excel object with long version. I think that windows form application gives error somehow when i add another using with 'using std' and it's a huge project. – misscalypso Aug 05 '14 at 08:34