开发者

MVC 3- Grid. Export Data into Excel and PDF

I am using M开发者_开发知识库VC3 Web Grid. I need to export the data into excel 2003 and Higher and to PDF.

I have two button under the grid, When I click on the first button, I should be able to export to excel 2003 and save the data.

When I click on the second button, I should be able to export in to PDF format.

Using Grid View in Webforms, I have done that, but using MVC3, I have not done that.

Any directions please? Is there anything that comes up with in MVC3 framework for export functionality.

Thank you


Is there anything that comes up with in MVC3 framework for export functionality.

No nothing. To export to Excel you could use CSV and use a controller action which will fetch the data from wherever you fetched it initially to display on the grid and return a File content with CSV:

public ActionResult ExportToExcel()
{
    byte[] csvData = ... fetch the data from your repository and convert to CSV
    return File(csvData, "text/csv", "data.csv");
}

To export to PDF, well, nothing built-in .NET. You will need a third party library. Personally I use iTextSharp to achieve this functionality.


You can check here for an easy way to export to CSV. You don't have to worry about converting your data to CSV, this will do it.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜