Click here to Skip to main content
14,828,731 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi All,

I want to read an excel sheet data into an html table.
I am working on MVC framework.

[controller]
C#
public ActionResult ExcelRead()
        {
            try
            {
                string[,] TestArray = new string[3, 5];
                FileInfo newFile = new FileInfo(Server.MapPath(@"\Content\ExcelPackageNewFile.xlsx"));
                using (ExcelPackage xlPackage = new ExcelPackage(newFile))
                {
                    ExcelWorkbook myWorkbook = xlPackage.Workbook;

                    // Getting the worksheet by its name...
                    ExcelWorksheet myWorksheet = myWorkbook.Worksheets["Sheet1"];
                   
//I want to read excel data here, please help me,Iam very new to this 

                }
                return RedirectToAction("ExcelRead");
            }
            catch (Exception ex)
            {
                return RedirectToAction("ExcelRead");
            }
        }
Posted
Updated 7-Dec-10 22:01pm
v2
Comments
Dalek Dave 8-Dec-10 4:01am
   
Edited for Code BLock.

1 solution

   
v2
Comments
madhusudhan.k 8-Dec-10 4:47am
   
Thanks Sengupta, I have gone throw this link once before, but im not getting, please can guide me.

Regards
Madhusudhan
senguptaamlan 8-Dec-10 4:52am
   
please explain what do you want to do wat's the problem that you are facing doing that
madhusudhan.k 8-Dec-10 4:58am
   
Here they have written in console application, but i want in web application, Iam not getting how to read the excel sheet.
Please if you know then can help me.

Thanks
Regards
Madhusudhan
senguptaamlan 8-Dec-10 5:02am
   
They have used Console.WriteLIne to show the extracted value from Excel Sheet....the reading method is standard for web or console appp...you just need to implement the HTML rendering ... I'm not quite confident in ASP.NET MVC framework...but this is the basic idea that you have to implement

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900