This project has moved and is read-only. For the latest updates, please go here.

Read data from Excel Spreadsheet

Jul 31, 2014 at 8:46 AM
Is it possible to use the ExcelApi to read data from an Excel spreadsheet, I'm trying to replace the use of OleDb due to limitations with remote host Excel drivers, below is an example of code that works locally but not remotely, hence the need to modify:

OleDbConnection conn;

conn = new OleDbConnection("provider=Microsoft.Jet.OLEDB.4.0;data source=" + filename + ";Extended Properties=\"Excel 8.0;HDR=NO;IMEX=1;\"");

var tblSchema = conn.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, new object[] { null, null, null, "TABLE" });

string sheetName = tblSchema.Rows[0]["TABLE_NAME"].ToString();
string getFileName = Path.GetFileName(filename);
string tableName = getFileName.Substring(0, getFileName.Length - 4);

var cmdEdl = new OleDbCommand("SELECT * FROM [" + sheetName + selectRange + "]", conn);

OleDbDataReader drEdl = cmdEdl.ExecuteReader();

Any help would be much appreciated :-)