Controling Excel from C# DLL

N

Nondisclosure007

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!
 
N

Nondisclosure007

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!

PS. I'm using VS2010 and Excel 2010.
 
B

bradbury9

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top