Export excel and Pdf with Kendo UI MVC c#

Export to Excel and Pdf

  • Export excel and pdf is now a days a basic needs of clients for saving reports or tables data.
  • Kendo UI has build features for exporting table data to excel and pdf with Excel() and Pdf() functions.
  • Functions are used as below.
 @(Html.Kendo().Grid(Model)
    .Name("timeGrid")
    .NoRecords()
    .Columns(columns =>
    {
        columns.Bound(p => p.Field1).Title("Field1");
        columns.Bound(p => p.Field2).Title("Field2");
        columns.Bound(p => p.Field3).Title("Field3");
    }).Groupable()
       .Sortable()
    .Excel(excel => excel
       .FileName("FileName.xlsx").AllPages(true)
       .Filterable(true)
       .ProxyURL(Url.Action("Excel_Export_Save", "Controller"))
    )
             .Pdf(pdf => pdf
                .AllPages()
                .FileName("FileName.pdf").ForceProxy(true)
                .ProxyURL(Url.Action("Pdf_Export_Save", "Controller"))
            )
    .ToolBar(tools => tools.Excel())
    .ToolBar(tools => tools.Pdf())
    .Filterable()
    .Pageable().DataSource(dataSource => dataSource
        .Ajax()
        .PageSize(10)
        .ServerOperation(false)
    )
                )
  • Place above code in your View page, in above code the use of Excel() and Pdf() function in Kendo MVC.
  • For Generating buttons for Excel and Pdf export Toolbar() function is used shown in code.
  • In above their sub-functions which are used like FileName(), ProxyURL(),etc. are used to customize Excel and Pdf.
  • FileName() : This function is used to give file name.
  • ProxyURL() : Sometimes client wants reports or file in different format or customize view in file at that time ProxyURL() function is used to create customize file. ProxyURL() generally takes two arguments like action name and controller name.
    Proxy URL
    ProxyURL Action in Controller
  • Filterable() : This function takes one argument i.e. true or false. If you passed true and then it will allows filtration in generated excel which you used in table.
  • AllPages() : AllPages() function indicates your generated Pdf or Excel file will contains pages of grid or not.It will takes argument as true or false.
Above how you can use Excel(),Pdf() and Toolbar() function for exporting grid data to Excel and Pdf file.

Click Here To Demo For Export to Excel with Kendo Grid 

Click Here To Demo For Export to PDF with Kendo Grid 

Hope this will help you. Keep coding... :)

Comments

Popular posts from this blog

Display image from byte array in ASP.NET MVC

Convert a color image to black and white image in C#