RSS

Tag Archives: Exporting Several XtraGrid Controls to a Single Excel File

devexpress multiple gridview export to excel in Single File winforms


After two much searching of this solution to export multiple gridview data to single Excel file with separate Sheet of Excel.

Then i find this solution which resolve my problem. this is 100% tested and use in my project . after that i share with you in both language c# and vb.net.

 

 Solution :: Vb.Net

Imports DevExpress.XtraPrinting
Imports DevExpress.XtraPrintingLinks

 

Public Sub MultiFileExportToExcel()

Using saveDialog = New SaveFileDialog()
saveDialog.Filter = “Excel (.xlsx)|*.xlsx”
If saveDialog.ShowDialog() = DialogResult.OK Then
Dim printingSystem = New PrintingSystemBase()
Dim compositeLink = New CompositeLinkBase()
compositeLink.PrintingSystemBase = printingSystem

Dim link1 = New PrintableComponentLinkBase()
link1.Component = grid1
Dim link2 = New PrintableComponentLinkBase()
link2.Component = grid2

compositeLink.Links.Add(link1)
compositeLink.Links.Add(link2)

Dim options = New XlsxExportOptions()
options.ExportMode = XlsxExportMode.SingleFilePageByPage

compositeLink.CreatePageForEachLink()
compositeLink.ExportToXlsx(saveDialog.FileName, options)
End If
End Using
End Sub

 

Solution ::  C#

using DevExpress.XtraPrinting
using DevExpress.XtraPrintingLinks

public void exportToExcel()
{
using (var saveDialog = new SaveFileDialog())
{
saveDialog.Filter = “Excel (.xlsx)|*.xlsx”;
if (saveDialog.ShowDialog() == DialogResult.OK)
{
var printingSystem = new PrintingSystemBase();
var compositeLink = new CompositeLinkBase();
compositeLink.PrintingSystemBase = printingSystem;

var link1 = new PrintableComponentLinkBase();
link1.Component = grid1;
var link2 = new PrintableComponentLinkBase();
link2.Component = grid2;

compositeLink.Links.Add(link1);
compositeLink.Links.Add(link2);

var options = new XlsxExportOptions();
options.ExportMode = XlsxExportMode.SingleFilePageByPage;

compositeLink.CreatePageForEachLink();
compositeLink.ExportToXlsx(saveDialog.FileName, options);
}
}
}

 

Reference url;

https://www.devexpress.com/Support/Center/Question/Details/A2730

Advertisements
 
Leave a comment

Posted by on April 22, 2015 in Vb.Net, WinForm

 

Tags: ,