Reading content from an Excel file via a .NET application

  • Thread starter Thread starter Bruce Schechter
  • Start date Start date
B

Bruce Schechter

I am looking for good documentation and preferably C#
sample code to show how to read content from an Excel
file via a .NET (Windows Form) application. I want to
access the Excel object model (for Excel 2003) from my
application. My .NET application will provide a
filename and location, open the excel file, read content
from specific locations within the spreadsheet, and then
close the Excel file.

I have searched MSDN and GotDotNet and seen documentation
for the Excel object model and several code samples. But
the paradigm seems to be different in these examples, in
that that are oriented for responding to events when a
user opens an Excel file, rather than my paradigm being
that a .NET application needs to proactively open an
Excel file and then read or manipulate it from the
external application.

I'm somewhat new to C# and to .NET, so forgive me if my
question is not phrased in correct terminology.

Thanks for any help,
Cheers,
Bruce
 
You're right about there being two different paradigms.

The first one is creating an add-in DLL that "resides" in the
Excel/Word/Outlook/etc. process. It usually sits in the background of the
Office process and waits to performs some command at the appropriate time
(such as when a menu item is selected, or a file is opened.) It's like
running a souped-up Office macro.

The second one is using a .Net application (like a standard Windows.Forms
exe) that programatically opens an Office application by setting a variable
to a new instance of the Excel/Word/Ooutlook application object, controls
the application using the Office object model, and then shuts the
application down. This sounds like what you want.

Here are some links that might help you. The first article has code
snippets that show how to start an instance of Powerpoint using C# -- it
should be easy to translate that to Excel.

Developing Microsoft Office Solutions Using C#
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnofftalk/html/office02072002.asp

Programming Office Applications Using Visual C#
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/odc_vsto2003_ta/html/OffCSharp.asp

Office Development Code Examples
http://msdn.microsoft.com/library/d...s/dv_wrcore/html/wroricodeexamplesforword.asp
 
Back
Top