Reputation: 4660
I need to generate a PDF and an Excel file from my ASP.net MVC application. Any ideas on the best way to implement this?
Upvotes: 2
Views: 3443
Reputation: 24078
Upvotes: 0
Reputation: 34391
For PDF, you can use PdfSharp. For Excel, I think Aspose.Cells will be good (although I've never used it, I have used their Word component and it rocks).
Upvotes: 0
Reputation: 37648
I recommend writing a reporting services report (RDLC), deploying it with the web application, and using the report viewer control to render the output. Bringing reporting services in may seem like a steep learning curve, but it is not too 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.
Upvotes: 2
Reputation: 99720
Use iTextSharp to create the PDF and return it with a FileContentResult.
Upvotes: 2
Reputation: 3932
something like abcpdf is cool for creating the PDF, as for excel you just need to create a 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);
}
}
as for doing it with a pdf, that would depend on what route you take!
Upvotes: 0
Reputation: 24832
Create a PDFActionResult and an ExcelActionResult
EDIT
Example for an 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
Upvotes: 1