Click here to Skip to main content
15,896,730 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi Friends,
I am working on MVC framework, open office.org excel sheet. I want to display the data of excel sheet in html table.

This code is to export the data, but i want to display the same data in html table in view i.e in .aspx page
Can any MVC experts tell me code. I am very new to MVC.
please help me its urgent.
C#
[controller class]
 [AcceptVerbs(HttpVerbs.Post)]
        public ActionResult ExcelPackageCreate(string id)
        {
            try
            {
                
                FileInfo template = new FileInfo(Server.MapPath(@"\Content\ExcelPackageTemplate.xlsx"));

                FileInfo newFile = new FileInfo(Server.MapPath(@"\Content\ExcelPackageNewFile.xlsx"));

                // Using the template to create the newFile...
                using(ExcelPackage excelPackage = new ExcelPackage(newFile, template))
                {
                    // Getting the complete workbook...
                    ExcelWorkbook myWorkbook = excelPackage.Workbook;

                    // Getting the worksheet by its name...
                    ExcelWorksheet myWorksheet = myWorkbook.Worksheets["Sheet1"];
                   
                    // Setting the value 77 at row 5 column 1...
                    myWorksheet.Cell(5, 1).Value = 77.ToString();
                    
                    // Saving the change...
                    excelPackage.Save();
                }

                TempData["Message"] = "Excel report created successfully!";

                return RedirectToAction("ExcelPackage");
            }
            catch(Exception ex)
            {
                TempData["Message"] = "Oops! Something went wrong.";

                return RedirectToAction("ExcelPackage");
            }
        }


Thanks
Regards
Madhu
Posted
Updated 12-Dec-10 21:57pm
v3
Comments
Abdul Quader Mamun 13-Dec-10 3:57am    
Spelling check.

1 solution

Hi Madu,

from your code . you redirect to the action "ExcelPackage".In this action you can keep ur value in a viewdata or tempdata as "htmlstring".this value can be access in your view.

eg:
In Controller

tblStr="<table><tr><td> " + "Your Value" + " </td></tr></table>"

ViewData("dvExcelData") == new HtmlString(tblStr)
Or
TempData("dvExcelData") == new HtmlString(tblStr)


In View

<div id='div' ><%:TempData("dvExcelData") %></div>

Note:- Viewdata only stores data in a single request
 
Share this answer
 
Comments
madhusudhan.k 15-Dec-10 23:40pm    
Hi ANSAI
Thanks for your post.

Regards
Madhu
ANSAL P R 22-Dec-10 10:54am    
Thank You

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