I am working on a web based app the needs to pull data from an excel 97-2003(.xls) spreadsheet that has several small tables on a single worksheet.
I am currently experimenting with the following code to open and read the worksheet:
string properties = String.Format(@"Provider = Microsoft.Jet.OLEDB.4.0; Data Source = C:\Users\Macy\Desktop\lbr_ems.xls; Extended Properties = 'Excel 8.0;'");
using (OleDbConnection conn = new OleDbConnection(properties))
{
string worksheet = "LbrRpt";
conn.Open();
DataSet ds = new DataSet();
//string columns = String.Join(",", columnNames.ToArray());
using (OleDbDataAdapter da = new OleDbDataAdapter("SELECT * FROM [" + worksheet + "$]", properties))
{
DataTable dt = new DataTable();
da.Fill(dt);
ds.Tables.Add(dt);
grdComponent.DataSource = dt;
grdComponent.DataBind();
}
The issue is that it pulls the ENTIRE worksheet and all the numerical values are blank. I'm thinking that this is not the code that i need for the application i am attempting to build.
I have been looking at this code:
Excel.Workbook excelWorkbook = excelApp.Workbooks.Open(workbookPath, 0, false, 5, "", "", false, Excel.XlPlatform.xlWindows, "", true, false, 0, true, false, false);
Excel.Sheets excelSheets = excelWorkbook.Worksheets;
string currentSheet = "Sheet1";
Excel.Worksheet excelWorksheet = (Excel.Worksheet)excelSheets.get_Item(currentSheet);
var cell = (Excel.Range)excelWorksheet.Cells[10, 2];
as per How to read single Excel cell value, however i am lead to believe that it may not be for a web based use due to no mention of .net, or I am missing a using clause somewhere.
most other solutions i have seen generally indicate using third party items.
am i missing something stupid-easy or just not looking in the right spots?