从HttpPostedFileBase对象读取Excel文件数据

时间:2009-09-10 10:29:23

标签: excel

上传的Excel文件位于HttpPostedFileBase对象

HttpPostedFileBase hpf = Request.Files [“ExcelFileeUploader”];

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

1 个答案:

答案 0 :(得分:11)

如果你使用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 
}
相关问题