472,358 Members | 2,026 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,358 software developers and data experts.

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.Office.Interop.Excel;
or
using Excel;
or
using Excel = Microsoft.Office.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(office 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.Office.Interop.Excel;) I get "The
type or namespace name 'Interop' does not exist in the class or namespace
'Microsoft.Office' (are you missing an assembly reference?)

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

3) when I build using the (using Excel = Microsoft.Office.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.Office.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 3007
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********************@agilent.com> wrote in message
news:eP**************@TK2MSFTNGP05.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.Office.Interop.Excel;
or
using Excel;
or
using Excel = Microsoft.Office.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(office 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.Office.Interop.Excel;) I get "The type or namespace name 'Interop' does not exist in the class or namespace
'Microsoft.Office' (are you missing an assembly reference?)

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

3) when I build using the (using Excel = Microsoft.Office.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.Office.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.Office.Core;
using Microsoft.Office.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********************@agilent.com> wrote in message
news:eP**************@TK2MSFTNGP05.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.Office.Interop.Excel;
or
using Excel;
or
using Excel = Microsoft.Office.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(office 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.Office.Interop.Excel;) I get
"The type or namespace name 'Interop' does not exist in the class or
namespace 'Microsoft.Office' (are you missing an assembly reference?)

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

3) when I build using the (using Excel = Microsoft.Office.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.Office.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.ComponentModel;
using System.Windows.Forms;

namespace MyApplication.Presentation.Winform
{
/// <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
InitializeComponent()
End Sub 'New
Public Overloads Shared Sub Main()
StartApplication(System.Environment.GetCommandLine Args())
End Sub

Public Shared Sub StartApplication(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.Exit()
End Try
End Sub 'Main
Private Sub InitializeComponent()
'
'Entry
'
Me.AutoScaleBaseSize = 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.ShowInTaskbar = False
Me.StartPosition =
System.Windows.Forms.FormStartPosition.CenterScree n
Me.Text = "Non Visable Startup Window"

End Sub 'InitializeComponent
End Class

End Namespace

"Mike in Santa Rosa" <NO********************@agilent.com> wrote in message
news:Ok**************@TK2MSFTNGP05.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.Office.Core;
using Microsoft.Office.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********************@agilent.com> wrote in message
news:eP**************@TK2MSFTNGP05.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.Office.Interop.Excel;
or
using Excel;
or
using Excel = Microsoft.Office.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(office 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.Office.Interop.Excel;) I get
"The type or namespace name 'Interop' does not exist in the class or
namespace 'Microsoft.Office' (are you missing an assembly reference?)

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

3) when I build using the (using Excel = Microsoft.Office.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.Office.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.Application.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.Office.Core;
using Microsoft.Office.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********************@agilent.com> wrote in message
news:eP**************@TK2MSFTNGP05.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.Office.Interop.Excel;
or
using Excel;
or
using Excel = Microsoft.Office.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(office 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.Office.Interop.Excel;) I get
"The type or namespace name 'Interop' does not exist in the class or
namespace 'Microsoft.Office' (are you missing an assembly reference?)

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

3) when I build using the (using Excel = Microsoft.Office.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.Office.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.microsoft.com> wrote in message
news:E1**********************************@microsof t.com...
Try:

System.Windows.Forms.Application.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.Office.Core;
using Microsoft.Office.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********************@agilent.com> wrote in
message
news:eP**************@TK2MSFTNGP05.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.Office.Interop.Excel;
> or
> using Excel;
> or
> using Excel = Microsoft.Office.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(office 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.Office.Interop.Excel;) I get
> "The type or namespace name 'Interop' does not exist in the class or
> namespace 'Microsoft.Office' (are you missing an assembly reference?)
>
> 2) when I build using the (using Excel;) I get "Application' is an
> ambiguous reference". This refers to the
> Applicaiton.Run in my main argument. I can only assume Application in
> conflicting with Excel.Application but can't figure out how to
> straighten
> this out.
>
> 3) when I build using the (using Excel =
> Microsoft.Office.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.Office.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
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....
0
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...
4
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...
3
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...
2
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...
7
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...
2
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...
0
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...
4
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...
0
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge required to effectively administer and manage Oracle...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was proposed, which integrated multiple engines and...
1
by: Matthew3360 | last post by:
Hi there. I have been struggling to find out how to use a variable as my location in my header redirect function. Here is my code. header("Location:".$urlback); Is this the right layout the...
2
by: Matthew3360 | last post by:
Hi, I have a python app that i want to be able to get variables from a php page on my webserver. My python app is on my computer. How would I make it so the python app could use a http request to get...
0
hi
by: WisdomUfot | last post by:
It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific technical details, Gmail likely implements measures...
0
Oralloy
by: Oralloy | last post by:
Hello Folks, I am trying to hook up a CPU which I designed using SystemC to I/O pins on an FPGA. My problem (spelled failure) is with the synthesis of my design into a bitstream, not the C++...
0
by: Carina712 | last post by:
Setting background colors for Excel documents can help to improve the visual appeal of the document and make it easier to read and understand. Background colors can be used to highlight important...
0
by: Rahul1995seven | last post by:
Introduction: In the realm of programming languages, Python has emerged as a powerhouse. With its simplicity, versatility, and robustness, Python has gained popularity among beginners and experts...
0
by: Ricardo de Mila | last post by:
Dear people, good afternoon... I have a form in msAccess with lots of controls and a specific routine must be triggered if the mouse_down event happens in any control. Than I need to discover what...

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.