What is the best way to generate PDF and Excel file from ASP.Net MVC
Create PDFActionResult and ExcelActionResult
EDIT
Example for excelactionresult: http://stephenwalther.com/blog/archive/2008/06/16/asp-net-mvc-tip-2-create-a-custom-action-result-that-returns-microsoft-excel- documents.aspx
source to share
I recommend writing a Reporting Services (RDLC) report, deploying it using a web application, and using a report viewer to render the output. Engaging reporting services may seem like a steep learning curve, but it's not that bad. You get the added benefit of a solid solution that supports other formats. You don't need a report server for this deployment scenario - not even SQL Server.
source to share
something like abcpdf is cool for generating PDF, as for excel you just need to create datatable from your dataset
var grid = new System.Web.UI.WebControls.DataGrid();
grid.HeaderStyle.Font.Bold = true;
grid.DataSource = yourdatahere;
grid.DataMember = yourdatahere.Stats.TableName;
grid.DataBind();
// render the DataGrid control to a file
using (var sw = new StreamWriter("c:\\test.xls"))
{
using (var hw = new HtmlTextWriter(sw))
{
grid.RenderControl(hw);
}
}
how to do this with pdf, which will depend on which route you take!
source to share
For PDF, you can use PdfSharp . For Excel, I think Aspose.Cells will be good (although I never used it, I used my Word component and it rocks).
source to share
- PDF - use NFOP , PdfSharp or iSharpText
- Excel - if you need simple data like spreedshet then render as plain text CSV file. If you need formatting and all the whistles, use GBSpreadsheet .
source to share