What is the best way to generate PDF and Excel file from ASP.Net MVC

I need to create PDF and Excel file from my ASP.net MVC application. Any ideas on the best way to implement this?

+2


source to share


6 answers


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

+1


source


Use iTextSharp to create a PDF and return it using FileContentResult .



+2


source


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.

+2


source


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!

0


source


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

0


source


  • 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 .
0


source







All Articles