Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Read Excel File Data From HttpPostedFileBase object

Tags:

excel

Uploaded Excel file Is In HttpPostedFileBase object

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

Want To Read Excel Data From This Object. thanks.

like image 680
rjdmello Avatar asked Sep 10 '09 10:09

rjdmello


1 Answers

If you use EPPlus, it's as simple as this:

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 
}
like image 100
triskelion Avatar answered Nov 15 '22 20:11

triskelion