C# Simplest way to read values from Excel file

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • rvon
    New Member
    • Aug 2007
    • 2

    C# Simplest way to read values from Excel file

    I'm doing some basic programing in C# and want to read two numeric values from an Excel file.

    Hope I'm in the right forum. The C# code is compiled and used within a vendor's charting application.

    So confused I don't know where to start. Is there a simple way?

    Thanks for your help.
    Last edited by rvon; Aug 27 '07, 08:51 PM. Reason: Think I'm in wrong forum and won't let me delete
  • chazcross
    New Member
    • Feb 2007
    • 31

    #2
    you can connect to an excel file using a OleDBConnection and run a sql query to get the data from it.

    Code:
    string sql = "SELECT  * FROM [WORKBOOKNAME$]";
    
    string strConn = "Provider=Microsoft.Jet.OleDb.4.0;data source=" + fileName + ";Extended Properties=Excel 8.0;";
    OleDbConnection objConn = new OleDbConnection(strConn);
    OleDbCommand objCmd = new OleDbCommand(sql, objConn);
    OleDbDataAdapter objAdp = new OleDbDataAdapter(objCmd);
    
    DataSet data = new DataSet();
    objConn.Open();
    objAdp.Fill(data);

    Comment

    • rvon
      New Member
      • Aug 2007
      • 2

      #3
      Thank you for replying. Clearly this is beyond my experience. It appears that the numbers are imported as strings. How do I access them and how do I get them to be type double?

      Comment

      Working...