2

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?

6 Answers 6

2

Use iTextSharp to create the PDF and return it with a FileContentResult.

Sign up to request clarification or add additional context in comments.

Comments

2

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.

1 Comment

This was our solution for generating reports as both excel and word format, though as a file result rather than with the report viewer. One caveat though, if the reports fail on your server, you'll probably need to deploy the Microsoft.ReportViewer .dll's to your bin folder.
1

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

Comments

0

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!

Comments

0

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).

Comments

0
  • PDF - use NFOP, PdfSharp or iSharpText
  • Excel - if you need plain data as a spreedshet, then render as plain-text CSV file. If you need formatting and all the whistles, then use GBSpreadsheet.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.