Re: Reading an Excel file in C#

Vince P <[email protected]> Fri, 13 Apr 2007 20:45:55 -0500
Newsgroups gmane.comp.windows.devel.dotnet.cx
Message-ID <01dc01c77e36$a4c86a00$ee593e00$@net>
If the machine is in x64 mode, make sure you build this to run x86 because
there is no 64bit Jet driver. (I hope I'm right)


-
THESE are the times that try men's souls. The summer soldier and the
sunshine patriot will, in this crisis, shrink from the service of their
country; but he that stands by it now, deserves the love and thanks of man
and woman. Tyranny, like hell, is not easily conquered; yet we have this
consolation with us, that the harder the conflict, the more glorious the
triumph.

> -----Original Message-----
> From: Discussion relating to the specifics of the C# and Managed C++
> languages [mailto:[email protected]] On Behalf Of Alan
> Baljeu
> Sent: Friday, April 13, 2007 16:07
> To: [email protected]
> Subject: Re: [DOTNET-CX] Reading an Excel file in C#
>
> Try this:
>
> using System.Data.OleDb;
> using System.Data;
>
> namespace ee
> {
>   public class ExcelDataReader
>   {
>     public readonly DataSet excelData ;
>
>     public ExcelDataReader(string fileName)
>     {
>       excelData = new DataSet();
>       Connect(fileName);
>     }
>     private void Connect(string fileName)
>     {
>       string sConnectionString =
> string.Format("Provider=Microsoft.Jet.OLEDB.4.0;Data
> Source={0};"+
>             "Extended Properties=Excel 8.0;", fileName);
>
>       OleDbConnection objConn = new OleDbConnection(sConnectionString);
>       objConn.Open();
>
>       try
>       {
>         OleDbCommand objCmdSelect =new OleDbCommand("SELECT * FROM
> [VMM$]", objConn);
>         OleDbDataAdapter objAdapter1 = new OleDbDataAdapter();
>         objAdapter1.SelectCommand = objCmdSelect;
>         objAdapter1.Fill(excelData, "XLData");
>       }
>       finally
>       {
>         objConn.Close();
>       }
>     }
>   }
> }
>
> ===================================
> This list is hosted by DevelopMentor.  http://www.develop.com
>
> View archives and manage your subscription(s) at
> http://discuss.develop.com

===================================
This list is hosted by DevelopMentorĀ®  http://www.develop.com

View archives and manage your subscription(s) at http://discuss.develop.com