1

I have 2 GridViews that have a master-detail relationship between them. Right now, when I have one row selected I'm able to export to excel the Gridview's detail by doing this:

GridView2.ExportToXlsx("OneMasterDetail.xlsx")

But what I want to do is export all the possible details from the master GridViews. I've tried the following but it just exports the master-detail that is currently selected.

GridView2.OptionsPrint.PrintDetails = True
GridView2.OptionsPrint.ExpandAllDetails = True
GridView2.ExportToXlsx("AllMasterDetail.xlsx")

Just to be sure I'm being clear. Let's say I have a Master GridView that has brands of cars, and the detail GridView that gives you the car colors available for that brand of car. The final Excel would have all the car brands with all their available colors.

Eric
  • 363
  • 2
  • 9
  • 24

2 Answers2

1

I had the same issue. It seems the Grid View's native export function is a little too primitive to pick up the various options and does more of a straight dump. If you want to accomplish what you seek, you need to use the DevExpress XtraPrinting library:

using DevExpress.XtraPrinting;

I don't know VB.net, but I am hopeful you can translate my C# into what you need. This will achieve the result you are after:

using (PrintableComponentLink link = new PrintableComponentLink(new PrintingSystem()))
{
    link.Component = GridControl2;
    link.CreateDocument(link.PrintingSystem);
    link.ExportToXlsx("AllMasterDetail.xlsx");
}

This is also necessary if, for example, you want the output as landscape rather than portrait.

--edit-- screen shots

UI:

enter image description here

Exported Spreadsheet:

enter image description here

Hambone
  • 15,600
  • 8
  • 46
  • 69
  • Thanks but this only exports the car colors for one brand of cars. I need an excel file that has all the car brands with the available colors. – Eric Feb 10 '16 at 15:19
  • And you had included the code above (in your post), which expands all groups? I ran a sample of this, and even though my grid was not expanded in the UI, the resulting Excel file had everything expanded. – Hambone Feb 10 '16 at 15:25
  • I just added the 'GridView2.OptionsPrint.PrintDetails = True GridView2.OptionsPrint.ExpandAllDetails = True' that I had previously commented and I get the same thing: only one master-detail in the excel sheet. – Eric Feb 10 '16 at 15:37
  • Not that it helps your situation, but I added screen shots as "proof" that this can work. My only other thought is this -- do you have a grid view for both the master and the detai? I don't *think* this should matter, but it can't hurt to ask. – Hambone Feb 10 '16 at 15:44
  • Thanks for putting up the screenshots. They made me realise that you were exporting from just one Grid: the master grid. I thought I had to export from the detail grid. I got it working now. Your code worked. – Eric Feb 10 '16 at 16:33
0

1.Devexpress Export to Excel all details from Master Detail GridView in VB.net

DevExpress.Export.ExportSettings.DefaultExportType = DevExpress.Export.ExportType.WYSIWYG
GridControl1.ExportToXlsx(.FileName)
Nimol
  • 1
  • 1