473,326 Members | 2,148 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

Excel 2003 Automation (connect to a running instance)

Hello,

Is there a way to connect (through automation) a c# application to a
running Excel 2003 instance on a specific workbook ?

In the past, i used to use GetObject(...) function in VB6.

Regarding C#, I have heard about
System.Runtime.InteropServices.marshal.GetActiveOb ject
("Excel.Application")

but i think this is used only for COM Excel objects, isn't it ?

What about connecting to Excel 2003 ?
Is it COM interface or native interface (.net ? managed automation ? i
don't know what would be the name of the newest automation method)
Thanks for your help,

Regards,
Cybertof.
Nov 15 '05 #1
1 5019
I have previously connected to MS Office components (Excel mostly) from C#.
For both versions, the only way is to use the COM Interop (There are MS
Office Interop dlls available on Microsoft Web site, or you can add
Reference manually to the Office COM component and Interop wrapper is built
automativally).

Following is then sample C# code that I used to instantiate Excel App,
Workbooks, and Worksheets:

////////////////////////////////////////////////////////////////////////////
////////////

using Microsoft.Office.Interop.Excel;

//...

//This is comparable to CoCreateInstance

Application app = new Application();

app.Visible=true;
Workbook wkb =
app.Workbooks.Open("spreadsheetPath",Missing.Value ,Missing.Value,Missing.Val
ue,Missing.Value,Missing.Value,

Missing.Value,Missing.Value,Missing.Value,Missing. Value,Missing.Value,Missin
g.Value,Missing.Value,Missing.Value,Missing.Value) ;

//Main processing of data

foreach(_Worksheet wks in wkb.Worksheets){

//Process all worksheets

Range wksRange;

try{

wksRange=wks.UsedRange;

builder.ProcessWorksheet(wks, ref wksRange, ref strm);

Console.WriteLine(wks.Name + " processed ...");

}

catch{

}

}

////////////////////////////////////////////////////////////////////////////
////////////

If you are only inetrested in Excel files, not manipulating all of the
features,may I recommend this great control:

http://www.codeproject.com/dotnet/Ex...Excel%7CExport

It allows you to export excel spreadsheet from file directly into dataset.
No COM components required It is free with source code. It uses OleDb to get
the data.

Hope that helps.

Nermin

"cybertof" <cy****************@gmx.net> wrote in message
news:MP************************@msnews.microsoft.c om...
Hello,

Is there a way to connect (through automation) a c# application to a
running Excel 2003 instance on a specific workbook ?

In the past, i used to use GetObject(...) function in VB6.

Regarding C#, I have heard about
System.Runtime.InteropServices.marshal.GetActiveOb ject
("Excel.Application")

but i think this is used only for COM Excel objects, isn't it ?

What about connecting to Excel 2003 ?
Is it COM interface or native interface (.net ? managed automation ? i
don't know what would be the name of the newest automation method)
Thanks for your help,

Regards,
Cybertof.

Nov 15 '05 #2

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

Similar topics

1
by: Steven Stewart | last post by:
I have a user who has been using Excel for a while to keep statistics and print reports. She finds using it cumbersome because of long formulas and a lot of copying and pasting. I have designed...
7
by: taylor.bryant | last post by:
I am running: Win XP SP2 Excel 2002, Access 2002 (Office XP SP3) Using Visual Basic (not VB.NET) At one point (prior to XP SP2?!? - I can't pin it down), this did not happen and I was easily...
6
by: Matthew Wieder | last post by:
I have the following requirements: Build a stand-alone C# application that asks the user to click in a cell in an Excel spreadsheet, and then displays the address of that cell in the C#...
6
by: frankplank | last post by:
Hi *, I'm wondering if it is possible to create a C# object, and reference it *explicitly* in an excel document. I imagine this will be more possible if I programmatically populate the excel...
5
by: cnathaide | last post by:
I am trying to control an existing running process from C#. More specifically, I am trying to control an existing workbook that is open in memory. I use the following code using...
5
by: Wenke Ji | last post by:
Hi I open a Excel workbook using below API: Set ExcelServer = CreateObject("EXCEL.Application") Set TargetWorkbook = ExcelServer.Workbooks.Open (CurrentBook) Befor the programm exit , I use...
12
by: elziko | last post by:
I'm using late binding (I must) to automate Excel. My code opens Excel after createing and poulating some sheets. My problem is that when the user finally decides to close Excel its process is...
7
by: Alain \Mbuna\ | last post by:
Hi everybody. In my program I have some data that is calculated after some input from the user. I have written some code that opens an Excel workbook, with 5 worksheets and the calculated data...
6
by: Mark Rae | last post by:
Hi, My client has asked me to provide a "quick and dirty" way to export the contents of a DataGrid to both Excel for analysis and Word for editing and printing, so I'm investigating client-side...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.