从HttpPostedFileBase对象读取Excel文件数据

rjd*_*llo 4 excel

上传的Excel文件是在HttpPostedFileBase对象中

HttpPostedFileBase hpf = Request.Files ["ExcelFileeUploader"];

想要从此对象读取Excel数据.谢谢.

小智 12

如果您使用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 
}
Run Code Online (Sandbox Code Playgroud)

  • 在我的环境中,它在第二个表单提交时抛出“在写操作期间发生磁盘错误。(来自HRESULT的异常:0x8003001D(STG_E_WRITEFAULT))”错误。 (2认同)