2009-09-10 68 views

回答

8

如果使用EPPlus,它是如此簡單:

public void ImportExcelXls(HttpPostedFileBase fileBase) 
{ 
    using (var package = new ExcelPackage(fileBase.InputStream)) 
    { 
     // get the first worksheet in the workbook 
     ExcelWorksheet worksheet = package.Workbook.Worksheets[1]; 
     int col = 1; 

     for (int row = 1; worksheet.Cells[row, col].Value != null; row++) 
     { 
      // do something with worksheet.Cells[row, col].Value      
     } 
    } // the using 
} 
+0

http://rajandmello.blogspot.com/2010/07/get-excel-data-by-passing-file-stream.html – rjdmello 2011-06-02 11:18:16

+1

在我的環境中,它拋出''在寫入操作期間發生磁盤錯誤(異常來自HRESULT:0x8003001D(STG_E_WRITEFAULT))''在第二個表單提交時出錯。 – Muflix 2017-06-23 13:27:37