473,847 Members | 1,756 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

using Excel 2003 from C# 2003

I'm trying to get a simple c# app built that can launch/manipulate an excel
workbook, sheet. I've chased down several examples and can't any of them to
work. So I must be doing somethnig obviouslt wrong.

Most examples to get things started include something:
using Microsoft.Offic e.Interop.Excel ;
or
using Excel;
or
using Excel = Microsoft.Offic e.Interop.Excel ;

....along with the standard namespaces supplied by visual studio IDE, like
System & System.Drawing, etc.

The examples also say to add a refererence (COM) to my project for microsoft
Excel object lib 9, 10, 11, etc via the Project Add Reference menu pick.

I start with a blank C# windows application project and add my (COM) excel
11 object lib reference(offic e 2003 installed on my desktop).
Here's what I observe during build for the 3 "using" scenarios:
1) when I build using the (using Microsoft.Offic e.Interop.Excel ;) I get "The
type or namespace name 'Interop' does not exist in the class or namespace
'Microsoft.Offi ce' (are you missing an assembly reference?)

2) when I build using the (using Excel;) I get "Applicatio n' is an ambiguous
reference". This refers to the
Applicaiton.Run in my main argument. I can only assume Application in
conflicting with Excel.Applicati on but can't figure out how to straighten
this out.

3) when I build using the (using Excel = Microsoft.Offic e.Interop.Excel ;) I
get a Namespace '' already contains a definition for 'Excel' and can't
continue.

Here's another thing. (with Excel 11 referenced in app)
If I use intellisense to show me the members of Microsoft, there's no
..Office.Intero p, only Office.Core. So if I should be using anything in the
"using" section it looks like it should be "using Microsoft.Offic e.Core;"

What using statement should I be incorporating or what else do I need to do?

I feel that once my "includes" are correct I can do the rest of the excel
stuff.(famous last words)

Thanks for absolutely any response in advance?
Mike


May 23 '06 #1
5 3158
Check my blog:
http://spaces.msn.com/sholliday/ 9/22/2005

Its not exactly what your'e looking for, but can probably help.

You don't reference the Interop file, you reference the COM object, and it
creates the Interop.
Its basically an adapter class that lets the two talk to each other.


"Mike in Santa Rosa" <NO************ ********@agilen t.com> wrote in message
news:eP******** ******@TK2MSFTN GP05.phx.gbl...
I'm trying to get a simple c# app built that can launch/manipulate an excel workbook, sheet. I've chased down several examples and can't any of them to work. So I must be doing somethnig obviouslt wrong.

Most examples to get things started include something:
using Microsoft.Offic e.Interop.Excel ;
or
using Excel;
or
using Excel = Microsoft.Offic e.Interop.Excel ;

...along with the standard namespaces supplied by visual studio IDE, like
System & System.Drawing, etc.

The examples also say to add a refererence (COM) to my project for microsoft Excel object lib 9, 10, 11, etc via the Project Add Reference menu pick.

I start with a blank C# windows application project and add my (COM) excel
11 object lib reference(offic e 2003 installed on my desktop).
Here's what I observe during build for the 3 "using" scenarios:
1) when I build using the (using Microsoft.Offic e.Interop.Excel ;) I get "The type or namespace name 'Interop' does not exist in the class or namespace
'Microsoft.Offi ce' (are you missing an assembly reference?)

2) when I build using the (using Excel;) I get "Applicatio n' is an ambiguous reference". This refers to the
Applicaiton.Run in my main argument. I can only assume Application in
conflicting with Excel.Applicati on but can't figure out how to straighten
this out.

3) when I build using the (using Excel = Microsoft.Offic e.Interop.Excel ;) I get a Namespace '' already contains a definition for 'Excel' and can't
continue.

Here's another thing. (with Excel 11 referenced in app)
If I use intellisense to show me the members of Microsoft, there's no
.Office.Interop , only Office.Core. So if I should be using anything in the
"using" section it looks like it should be "using Microsoft.Offic e.Core;"

What using statement should I be incorporating or what else do I need to do?
I feel that once my "includes" are correct I can do the rest of the excel
stuff.(famous last words)

Thanks for absolutely any response in advance?
Mike

May 23 '06 #2
OK,
I found the Primary Interop Assembly installation instructions, did that for
Excel, Word & Forms 2.0 and now I can add:

using Microsoft.Offic e.Core;
using Microsoft.Offic e.Interop.Excel ;

and intellisense shows valid members...

but my Application.Run () in my Main is still flagged as ambiguous when I
build.

How do I work around this?

Thanks again, Mike
"Mike in Santa Rosa" <NO************ ********@agilen t.com> wrote in message
news:eP******** ******@TK2MSFTN GP05.phx.gbl...
I'm trying to get a simple c# app built that can launch/manipulate an
excel workbook, sheet. I've chased down several examples and can't any of
them to work. So I must be doing somethnig obviouslt wrong.

Most examples to get things started include something:
using Microsoft.Offic e.Interop.Excel ;
or
using Excel;
or
using Excel = Microsoft.Offic e.Interop.Excel ;

...along with the standard namespaces supplied by visual studio IDE, like
System & System.Drawing, etc.

The examples also say to add a refererence (COM) to my project for
microsoft Excel object lib 9, 10, 11, etc via the Project Add Reference
menu pick.

I start with a blank C# windows application project and add my (COM) excel
11 object lib reference(offic e 2003 installed on my desktop).
Here's what I observe during build for the 3 "using" scenarios:
1) when I build using the (using Microsoft.Offic e.Interop.Excel ;) I get
"The type or namespace name 'Interop' does not exist in the class or
namespace 'Microsoft.Offi ce' (are you missing an assembly reference?)

2) when I build using the (using Excel;) I get "Applicatio n' is an
ambiguous reference". This refers to the
Applicaiton.Run in my main argument. I can only assume Application in
conflicting with Excel.Applicati on but can't figure out how to straighten
this out.

3) when I build using the (using Excel = Microsoft.Offic e.Interop.Excel ;)
I get a Namespace '' already contains a definition for 'Excel' and can't
continue.

Here's another thing. (with Excel 11 referenced in app)
If I use intellisense to show me the members of Microsoft, there's no
.Office.Interop , only Office.Core. So if I should be using anything in the
"using" section it looks like it should be "using Microsoft.Offic e.Core;"

What using statement should I be incorporating or what else do I need to
do?

I feel that once my "includes" are correct I can do the rest of the excel
stuff.(famous last words)

Thanks for absolutely any response in advance?
Mike

May 23 '06 #3
You can only have 1 start up function....... .

You gotta delete one of them. Without code, its hard to tell.

Basically, there is one entry point to the application.... ....
What I normally do, is a create a class called

Entry.cs

The code looks like this:
using System;
using System.Componen tModel;
using System.Windows. Forms;

namespace MyApplication.P resentation.Win form
{
/// <summary>
/// Main Entry Point.
/// </summary>
public class Entry
{

public static void Main(string[] args)
{
try
{
Application.Run (new MainForm()); // you put the name of your form here
}
catch (Exception ex)
{
MessageBox.Show ("Unhandled exception: " + ex.Message);
}
}
}
}
This way, I at least get a MessageBox .. if I don't handle something in the
main application.
...

the vb.net version looks like this;

Imports System
Imports System.Windows. Forms
Namespace EntryPoint
_
'/ <summary>
'/ Summary description for Entry.
'/ This is the main entry point for the application
'/ </summary>
Public Class Entry : Inherits System.Windows. Forms.Form
Public Sub New()
Me.Visible = False
InitializeCompo nent()
End Sub 'New
Public Overloads Shared Sub Main()
StartApplicatio n(System.Enviro nment.GetComman dLineArgs())
End Sub

Public Shared Sub StartApplicatio n(ByVal args() As String)

Try
Application.Run (New frmMain) ''' put your form here
''This format allows a "catch all" exception block
''This code will only fire when the developer
''doesn't have try/finally/catch blocks

Catch ex As Exception
' Make sure we log the unhandled exceptions.
MessageBox.Show ("A serious error has occured. MyApp cannot
continue." & vbCrLf & ex.Message)
'Shut down application
Application.Exi t()
End Try
End Sub 'Main
Private Sub InitializeCompo nent()
'
'Entry
'
Me.AutoScaleBas eSize = New System.Drawing. Size(5, 13)
Me.ClientSize = New System.Drawing. Size(248, 69)
Me.Location = New System.Drawing. Point(-1000, -1000)
Me.Name = "Entry"
Me.ShowInTaskba r = False
Me.StartPositio n =
System.Windows. Forms.FormStart Position.Center Screen
Me.Text = "Non Visable Startup Window"

End Sub 'InitializeComp onent
End Class

End Namespace

"Mike in Santa Rosa" <NO************ ********@agilen t.com> wrote in message
news:Ok******** ******@TK2MSFTN GP05.phx.gbl...
OK,
I found the Primary Interop Assembly installation instructions, did that for Excel, Word & Forms 2.0 and now I can add:

using Microsoft.Offic e.Core;
using Microsoft.Offic e.Interop.Excel ;

and intellisense shows valid members...

but my Application.Run () in my Main is still flagged as ambiguous when I
build.

How do I work around this?

Thanks again, Mike
"Mike in Santa Rosa" <NO************ ********@agilen t.com> wrote in message
news:eP******** ******@TK2MSFTN GP05.phx.gbl...
I'm trying to get a simple c# app built that can launch/manipulate an
excel workbook, sheet. I've chased down several examples and can't any of them to work. So I must be doing somethnig obviouslt wrong.

Most examples to get things started include something:
using Microsoft.Offic e.Interop.Excel ;
or
using Excel;
or
using Excel = Microsoft.Offic e.Interop.Excel ;

...along with the standard namespaces supplied by visual studio IDE, like System & System.Drawing, etc.

The examples also say to add a refererence (COM) to my project for
microsoft Excel object lib 9, 10, 11, etc via the Project Add Reference
menu pick.

I start with a blank C# windows application project and add my (COM) excel 11 object lib reference(offic e 2003 installed on my desktop).
Here's what I observe during build for the 3 "using" scenarios:
1) when I build using the (using Microsoft.Offic e.Interop.Excel ;) I get
"The type or namespace name 'Interop' does not exist in the class or
namespace 'Microsoft.Offi ce' (are you missing an assembly reference?)

2) when I build using the (using Excel;) I get "Applicatio n' is an
ambiguous reference". This refers to the
Applicaiton.Run in my main argument. I can only assume Application in
conflicting with Excel.Applicati on but can't figure out how to straighten this out.

3) when I build using the (using Excel = Microsoft.Offic e.Interop.Excel ;) I get a Namespace '' already contains a definition for 'Excel' and can't
continue.

Here's another thing. (with Excel 11 referenced in app)
If I use intellisense to show me the members of Microsoft, there's no
.Office.Interop , only Office.Core. So if I should be using anything in the "using" section it looks like it should be "using Microsoft.Offic e.Core;"
What using statement should I be incorporating or what else do I need to
do?

I feel that once my "includes" are correct I can do the rest of the excel stuff.(famous last words)

Thanks for absolutely any response in advance?
Mike


May 23 '06 #4
Try:

System.Windows. Forms.Applicati on.Run()

instead to differentiate betwwent the 'Application' devined within the Exel
interop.

"Mike in Santa Rosa" wrote:
OK,
I found the Primary Interop Assembly installation instructions, did that for
Excel, Word & Forms 2.0 and now I can add:

using Microsoft.Offic e.Core;
using Microsoft.Offic e.Interop.Excel ;

and intellisense shows valid members...

but my Application.Run () in my Main is still flagged as ambiguous when I
build.

How do I work around this?

Thanks again, Mike
"Mike in Santa Rosa" <NO************ ********@agilen t.com> wrote in message
news:eP******** ******@TK2MSFTN GP05.phx.gbl...
I'm trying to get a simple c# app built that can launch/manipulate an
excel workbook, sheet. I've chased down several examples and can't any of
them to work. So I must be doing somethnig obviouslt wrong.

Most examples to get things started include something:
using Microsoft.Offic e.Interop.Excel ;
or
using Excel;
or
using Excel = Microsoft.Offic e.Interop.Excel ;

...along with the standard namespaces supplied by visual studio IDE, like
System & System.Drawing, etc.

The examples also say to add a refererence (COM) to my project for
microsoft Excel object lib 9, 10, 11, etc via the Project Add Reference
menu pick.

I start with a blank C# windows application project and add my (COM) excel
11 object lib reference(offic e 2003 installed on my desktop).
Here's what I observe during build for the 3 "using" scenarios:
1) when I build using the (using Microsoft.Offic e.Interop.Excel ;) I get
"The type or namespace name 'Interop' does not exist in the class or
namespace 'Microsoft.Offi ce' (are you missing an assembly reference?)

2) when I build using the (using Excel;) I get "Applicatio n' is an
ambiguous reference". This refers to the
Applicaiton.Run in my main argument. I can only assume Application in
conflicting with Excel.Applicati on but can't figure out how to straighten
this out.

3) when I build using the (using Excel = Microsoft.Offic e.Interop.Excel ;)
I get a Namespace '' already contains a definition for 'Excel' and can't
continue.

Here's another thing. (with Excel 11 referenced in app)
If I use intellisense to show me the members of Microsoft, there's no
.Office.Interop , only Office.Core. So if I should be using anything in the
"using" section it looks like it should be "using Microsoft.Offic e.Core;"

What using statement should I be incorporating or what else do I need to
do?

I feel that once my "includes" are correct I can do the rest of the excel
stuff.(famous last words)

Thanks for absolutely any response in advance?
Mike


May 23 '06 #5
Thanks.

That is exactly what I was looking for - Mike

"Robert Vasquez" <Ro***********@ discussions.mic rosoft.com> wrote in message
news:E1******** *************** ***********@mic rosoft.com...
Try:

System.Windows. Forms.Applicati on.Run()

instead to differentiate betwwent the 'Application' devined within the
Exel
interop.

"Mike in Santa Rosa" wrote:
OK,
I found the Primary Interop Assembly installation instructions, did that
for
Excel, Word & Forms 2.0 and now I can add:

using Microsoft.Offic e.Core;
using Microsoft.Offic e.Interop.Excel ;

and intellisense shows valid members...

but my Application.Run () in my Main is still flagged as ambiguous when I
build.

How do I work around this?

Thanks again, Mike
"Mike in Santa Rosa" <NO************ ********@agilen t.com> wrote in
message
news:eP******** ******@TK2MSFTN GP05.phx.gbl...
> I'm trying to get a simple c# app built that can launch/manipulate an
> excel workbook, sheet. I've chased down several examples and can't any
> of
> them to work. So I must be doing somethnig obviouslt wrong.
>
> Most examples to get things started include something:
> using Microsoft.Offic e.Interop.Excel ;
> or
> using Excel;
> or
> using Excel = Microsoft.Offic e.Interop.Excel ;
>
> ...along with the standard namespaces supplied by visual studio IDE,
> like
> System & System.Drawing, etc.
>
> The examples also say to add a refererence (COM) to my project for
> microsoft Excel object lib 9, 10, 11, etc via the Project Add Reference
> menu pick.
>
> I start with a blank C# windows application project and add my (COM)
> excel
> 11 object lib reference(offic e 2003 installed on my desktop).
>
>
> Here's what I observe during build for the 3 "using" scenarios:
> 1) when I build using the (using Microsoft.Offic e.Interop.Excel ;) I get
> "The type or namespace name 'Interop' does not exist in the class or
> namespace 'Microsoft.Offi ce' (are you missing an assembly reference?)
>
> 2) when I build using the (using Excel;) I get "Applicatio n' is an
> ambiguous reference". This refers to the
> Applicaiton.Run in my main argument. I can only assume Application in
> conflicting with Excel.Applicati on but can't figure out how to
> straighten
> this out.
>
> 3) when I build using the (using Excel =
> Microsoft.Offic e.Interop.Excel ;)
> I get a Namespace '' already contains a definition for 'Excel' and
> can't
> continue.
>
> Here's another thing. (with Excel 11 referenced in app)
> If I use intellisense to show me the members of Microsoft, there's no
> .Office.Interop , only Office.Core. So if I should be using anything in
> the
> "using" section it looks like it should be "using
> Microsoft.Offic e.Core;"
>
> What using statement should I be incorporating or what else do I need
> to
> do?
>
> I feel that once my "includes" are correct I can do the rest of the
> excel
> stuff.(famous last words)
>
> Thanks for absolutely any response in advance?
> Mike
>
>
>
>


May 23 '06 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
464
by: Igor | last post by:
Hi everyone! I have a program written on C# that works with Microsoft Excel application. I built it to work with Excel 2000. With runtime objects I created assemblies to connect to Excel. Everything worked properly since I was installed the new version on Microsoft Office 2003. Of cause, I rebuild assemblies and tried to connect. I got an error on Excel execution. When I opened source code to fix it, I found that there are no Workbooks and...
0
4204
by: Mike Knight | last post by:
(I've also posted this problem on microsoft.public.excel.programming) I have a MS Access 2003 Database named "AS400 Fields.mdb". This database contains links to tables on an AS400. In MS Excel 2003, I have VBA code that creates and executes queries using the Access database, and returns the results to an Excel sheet. The first time the query is executed, results are returned to Excel in usually less than 10 seconds. However, if the...
4
3410
by: Chris | last post by:
Hi, everything works apart from the last line :-(( rng.Value2.ToString() An exception is thrown : "Old format or invalid type library" It gets compiled though (so he recognizes the property 'Value2'). So I suppose I'm using a incompatible type lib. I'm using Excel 2002 : Excel 10.0 Object Library
3
37928
by: Eliézer Madeira de Campos | last post by:
I'm trying to use VB.NET to read an Excel 2003 file, so to process its data and eventually store (some of) it into a SQL Server 2000 database. However, I'm not quite understanding Office/Excel 2003 object models, and couldn't find any documentation on it. Anybody out there has any experience in doing so? Or has a better idea to acomplish those goals? I've searched the web looking for samples, but couldn't find any. Did anybody have a...
2
17729
by: Senthil | last post by:
Hi All I need to create an Excel report and create a command button and have to run a macro on the click event that will print all the pages in the Excel workbook. I am able to create the report from the database but I am not sure how do I put a command button and associate a macro with that using C#. Can anyone help me?? Thanks in advance. Senthil
7
14419
by: Holger Fitschen | last post by:
Hi to all, I want to use the Excel solver in a VB.Net project. The macro Sub Makro1Solver() Application.Run "Solver.xla!Auto_Open" SolverReset Worksheets(1).Select Worksheets(1).Range("B9").Select
2
1642
by: smtwtfs007 | last post by:
Guys, I am having problems with Excel 2000 to Excel 2003 dll in production. I am having version 2003 in my PC and I used the below code change to open password protected excel files in my application. My application is in ASP.NET From: objExcel = New Excel.Application
0
1716
by: smtwtfs007 | last post by:
Guys, I am having problems with Excel 2000 to Excel 2003 dll in production. I am having version 2003 in my PC and I used the below code change to open password protected excel files in my application. My application is in ASP.NET From: objExcel = New Excel.Application
4
3995
by: =?Utf-8?B?THluZXJz?= | last post by:
Hello All, We have a VB.NET application writen using VS 2003. This application apens an excel file from a vendor, reads the data and performs whatever functions it needs. We recently upgraded our sytems to Excel 2003 from Excel 2000. Our application started erroring out because it was having a problem with opening the Excel file. From troubleshooting, the exact problem is in Excel 2003, it does not like the sheet name (even though the...
0
9727
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10645
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10706
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9480
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7879
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5909
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4523
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
4115
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3160
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.