2015-12-02 19 views
-1

如何在不使用OleDbConnection的情況下讀取ASP.net中的Excel表格數據。我已經嘗試過OleDbConnection,但我正面臨着問題。如何閱讀asp.net以外的excel文件而不是OleDbConnection

還有其他的方法嗎?

+0

那麼我們應該幫助解決這些問題的權限或顯示一種替代方法?您可以使用['EPPlus'](http://epplus.codeplex.com/)或['Open XML'](http://stackoverflow.com/questions/2624333/how-do-i-read-data-從-A-電子表格的使用最OPENXML格式-SDK) –

回答

0

您需要EPPlus進行此類工作。 Site

0

檢查this。它可以讀取excel文件而無需OleDbConnection

0

您可以使用LinqToExcel來執行此操作。以下代碼將有所幫助:

public ActionResult fileread() 
{ 
    var excel = new ExcelQueryFactory(@"File Name"); 
    excel.AddMapping<ABC>(x => x.S1, "code");  // ABC is your database table name... code is the column name of excel file 
    excel.AddMapping<ABC>(x => x.S2, "description");  
    // you can map as many columns you want  
    var e = (from c in excel.Worksheet<ABC>("MyExcelFile") select c); // MyExcelFile is the name of Excel File's Sheet name 

// similarly you can do whatever you want with the data like.. save to DB 
    foreach (var y in e) 
    { 
     ABC a = new ABC(); 
     a.S1 = y.S1; 
     a.S2 = y.S2; 
     db.ABC.Add(a); 
    } 
    db.SaveChanges(); 
} 
相關問題