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.