tags:

views:

316

answers:

6

What's the way to open a excel workbook and to read excel cells?

+4  A: 

Use Visual Studio Tools for Office (VSTO) to extend Office products with your code and here's a good tutorial to get you started in Excel programming

RaYell
A: 

In this thread you will get details how to open and handle excel through C#.

malay
+1  A: 

SpreadsheetGear for .NET will do it. Here is a simple example:

using System;
using SpreadsheetGear;

namespace Program
{
    internal class test
    {
        internal test()
        {
            Factory.GetWorkbook();
        }
    }

    class Program
    {
        static void Main(string[] args)
        {
            IWorkbook workbook = Factory.GetWorkbook(@"C:\tmp\MyWorkbook.xls");
            IWorksheet worksheet = workbook.Worksheets[0];
            IRange a1 = worksheet.Cells["A1"];
            object rawValue = a1.Value;
            string formattedText = a1.Text;
            Console.WriteLine("rawValue={0} formattedText={1}", rawValue, formattedText);
        }
    }
}

You can see live ASP.NET samples here or download the free trial here if you want to try it yourself.

Disclaimer: I own SpreadsheetGear LLC

Joe Erickson
A: 

You can also use open xml sdk to read (and write) excel files (in open xml format off course). There is an msdn article describing how to use the open xml sdk.

A big advantage is that you don't have to install excel on the server (or client) to read excel files.

Jelle
A: 

There is an open source .NET library called Koogra for reading Excel files, both BIFF (older Excel) and XSLX (newer Excel). Otherwise you can use Excel automation, but I would avoid that if possible.

Ryan
A: 

SmartXLS for .Net can read/write Excel files in both xls and xlsx format.It is a commercial Excel spreadsheet component and support most Excel features.

liya