Skip to content

DevExpress-Examples/asp-net-mvc-grid-export-multiple-gridviews-into-a-document

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

25 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Grid View for MVC - How to export multiple grids into a single print document

This example shows how to use the XtraPrinting library to export several MVC GridView Extensions into a single XLS document.

Exported Grids

You can export several grids into a single document in the following way:

  1. Create a PrintableComponentLinkBase object for every grid. Call the GridViewExtension.CreatePrintableObject method to create an IPrintable object from the GridView based on its GridViewSettings.

    GridViewSettings categoriesGridSettings = new GridViewSettings();
    categoriesGridSettings.Name = "gvCategories";
    categoriesGridSettings.KeyFieldName = "CategoryID";
    categoriesGridSettings.Columns.Add("CategoryID");
    categoriesGridSettings.Columns.Add("CategoryName");
    categoriesGridSettings.Columns.Add("Description");
    
    var link1 = new PrintableComponentLinkBase(ps);
    link1.Component = GridViewExtension.CreatePrintableObject(categoriesGridSettings, MyModel.GetCategories());
  2. Call the CreateDocument method to create a document from the link, so it can be displayed or printed.

    var compositeLink = new CompositeLinkBase(ps);
    compositeLink.Links.AddRange(new object[] { link1, link2 });
    compositeLink.CreateDocument();
  3. Call the PrintingSystemBase.ExportToXls method to export the document.

    MemoryStream stream = new MemoryStream();
    link.PrintingSystemBase.ExportToXls(stream);
    stream.Position = 0;
    FileStreamResult result = new FileStreamResult(stream, "application/xls");
    result.FileDownloadName = "MyData.xls";

Files to Review

More Examples