Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Controling Excel from C# DLL

8 views
Skip to first unread message

Nondisclosure007

unread,
Feb 28, 2012, 7:42:25 PM2/28/12
to
Ok, this HAS to be my old age catching up to me. But for some reason,
I can't seem to get this.

How can I do this programatically? I've searched the web and found
thousands upon thousands of ways to do this via win form, console,
etc. But I can't find a way to do this via DLL.

I've found some classes @ codeproject and others but can't figure out
how to adapt them to be more simply what I want.

The main reason why I want to do this is to learn.

Here's my code:
using System;
using System.Collections.Generic;
using System.Text;
using Excel = Microsoft.Office.Interop.Excel;

namespace ExcelMT4
{

public class UnmanagedExports
{
Excel.Application excelApp;
Excel.Workbook excelWorkBook;
Excel.Worksheet excelWorkSheet;
Excel.Range excelRange;

static void OpenExcel(string strFileName)
{
excelApp = new Excel.Application;
}

}
}

I can't get past opening Excel in the compilier!
All I want to do is open a workbook, write and read to cells.

Should I put all the EXcel.* in their own methods? If I do, I lose
the availibilty of them to the rest of the DLL.

What am I missing here?

Hints in sample code please?

Thanks a lot!

Nondisclosure007

unread,
Feb 28, 2012, 7:45:12 PM2/28/12
to
On Feb 28, 5:42 pm, Nondisclosure007 <nondisclosure...@gmail.com>
wrote:
PS. I'm using VS2010 and Excel 2010.

Peter Duniho

unread,
Feb 28, 2012, 8:42:50 PM2/28/12
to
On Tue, 28 Feb 2012 16:42:25 -0800 (PST), Nondisclosure007 wrote:

> Ok, this HAS to be my old age catching up to me. But for some reason,
> I can't seem to get this.
>
> How can I do this programatically? I've searched the web and found
> thousands upon thousands of ways to do this via win form, console,
> etc. But I can't find a way to do this via DLL.

It's the same for a DLL as for an EXE (WinForms, console, WPF, whatever).

> I've found some classes @ codeproject and others but can't figure out
> how to adapt them to be more simply what I want.
>
> The main reason why I want to do this is to learn.
>
> Here's my code:
> using System;
> using System.Collections.Generic;
> using System.Text;
> using Excel = Microsoft.Office.Interop.Excel;
>
> namespace ExcelMT4
> {
>
> public class UnmanagedExports
> {
> Excel.Application excelApp;
> Excel.Workbook excelWorkBook;
> Excel.Worksheet excelWorkSheet;
> Excel.Range excelRange;
>
> static void OpenExcel(string strFileName)
> {
> excelApp = new Excel.Application;
> }
>
> }
> }
>
> I can't get past opening Excel in the compilier!

What does that even mean? You don't use a compiler to open things. You
use a compiler to compile your C# code.

You should first take the time to formulate a good, useful question. That
means posting a concise-but-complete code example that reliably
demonstrates the problem, as well as describing _exactly_ what the problem
is. Include the exact text of any error messages, as well as a complete
description of anything else that you do and which does not work the way
you expect it to.

In this case, it is probably also useful if you explain exactly how your
DLL project is configured. What settings are used, what references have
you added, etc.?

Pete

Bjørn Brox

unread,
Feb 29, 2012, 2:40:54 AM2/29/12
to
Den 29.02.2012 01:42, skrev Nondisclosure007:

> I can't get past opening Excel in the compilier!
> All I want to do is open a workbook, write and read to cells.

Define "open Exel"?

If you simply want to open any file in an external program you simply do
the following, and whatever program that is assosiated by your OS to the
file type will open:

using System.Diagnostics;
...

Process.Start(strFileName);

--
Bjørn Brox

bradbury9

unread,
Feb 29, 2012, 5:44:07 AM2/29/12
to
> I can't get past opening Excel in the compilier!
> All I want to do is open a workbook, write and read to cells.

If you want to show the excel file and let the user modify it, the
Bjørn proposal is pretty easy and functional.
I you want to modify it yourself, at your dll code, it wont be
usefull.

If the DLL is going to be used in ASP.NET applications it is not
recomended using Excel.Interop. Its quite nasty ASP.NET + Office
Interop.

Totally agree with Peter about being a vague/undefined question.
0 new messages