6 Replies - 748 Views - Last Post: 11 January 2015 - 02:00 PM Rate Topic: -----

#1 DrDress   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 41
  • Joined: 23-July 12

MS Excel interop in c#

Posted 11 January 2015 - 11:34 AM

Hi

I'm trying to acces Excel in a c# (2010) program . I'm using the following code:

using Excel = Microsoft.Office.Interop.Excel;

...

Excel.Application xlApp;
Excel.Workbook xlWorkBook;
Excel.Worksheet xlWorkSheet;

...



I get the error that Office does not exist in namespace Microsoft. I've never really gotten a hold of all that namespace stuff, so I'm a little lost as to get on with my project. I do have Excel on my computer.

Is This A Good Question/Topic? 0
  • +

Replies To: MS Excel interop in c#

#2 Skydiver   User is offline

  • Code herder
  • member icon

Reputation: 7058
  • View blog
  • Posts: 24,006
  • Joined: 05-May 12

Re: MS Excel interop in c#

Posted 11 January 2015 - 11:38 AM

Did you add a reference to the interop assemblies?
Was This Post Helpful? 0
  • +
  • -

#3 Dankwansere   User is offline

  • D.I.C Regular

Reputation: 83
  • View blog
  • Posts: 257
  • Joined: 09-November 09

Re: MS Excel interop in c#

Posted 11 January 2015 - 11:50 AM

Use must reference the office interop libraries in your project before you can use it.
Was This Post Helpful? 0
  • +
  • -

#4 DrDress   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 41
  • Joined: 23-July 12

Re: MS Excel interop in c#

Posted 11 January 2015 - 12:34 PM

I figured it was something like that. But I'm really not good at all that reference stuff. Would you care to help me?
Was This Post Helpful? 0
  • +
  • -

#5 modi123_1   User is online

  • Suitor #2
  • member icon



Reputation: 15277
  • View blog
  • Posts: 61,238
  • Joined: 12-June 08

Re: MS Excel interop in c#

Posted 11 January 2015 - 12:38 PM

Right click your project -> properties -> reference -> add -> com -> scroll down to microsoft excel.
Was This Post Helpful? 0
  • +
  • -

#6 Skydiver   User is offline

  • Code herder
  • member icon

Reputation: 7058
  • View blog
  • Posts: 24,006
  • Joined: 05-May 12

Re: MS Excel interop in c#

Posted 11 January 2015 - 12:45 PM

What tutorial or book are you following? That should have been covered early. If you are paying for a class, I would recommend dropping the class and asking for your money back. Adding references to assemblies is one of those basic options that you should know. Even the worse tutorials or books which don't teach debugging - another essential skill - will at least teach you how to add references.

If you are trying to cobble this program together without the basics of C# and how to use your tools, I suggest stepping back and picking up a "Learn C# in 30 Days" type book and work it cover to cover before taking on this project.
Was This Post Helpful? 1
  • +
  • -

#7 tlhIn`toq   User is offline

  • Xamarin Cert. Dev.
  • member icon

Reputation: 6535
  • View blog
  • Posts: 14,450
  • Joined: 02-June 10

Re: MS Excel interop in c#

Posted 11 January 2015 - 02:00 PM

View PostDrDress, on 11 January 2015 - 12:34 PM, said:

I've never really gotten a hold of all that namespace stuff, so I'm a little lost


View PostDrDress, on 11 January 2015 - 01:34 PM, said:

I figured it was something like that. But I'm really not good at all that reference stuff. Would you care to help me?


As others have said, you need to back up. You are a long way from trying to design and build a new application from scratch. Its not uncommon for rookies to think "I want to learn, so I'll build a program that does xyz" - but it just doesn't make sense to try that. Its like saying "I know NOTHING about cars, so I'll design a sedan from the ground up including all the stuff that goes in it like the engine." You wouldn't try that, right?

As you work through a "Learn C# in 30 days" book, and some introductory tutorials you'll get into more complex concepts such as namespaces. You'll learn by first doing as you're told by the author. First you'll create a solution that has more than one project, more than one namespace of your own creation. Then you'll start importing namespaces from places other than your own work. Then after you have learned the concepts you'll be able to start doing your own designs after a couple months.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1