We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

GridGroupingControl Export to Excel

Hi Support,

I am using Syncfusion Grid Grouping Windows Forms control in my application. I have implemented nested table. In child table rows, some of contains plain text, some contains GridControl. I need to export this GridGroupingControl like below. 

1. While exporting to excel I need to exclude some of columns from Child table
2. need to export child table row which contains GridControl

I am using below code,
GroupingGridExcelConverterControl excelConverter = new GroupingGridExcelConverterControl();
  excelConverter.ExportStyle = true;
  excelConverter.GroupingGridToExcel(myGGC, "Result.Xlsx", ConverterOptions.Default);

Please share the details to achieve the above mentioned format exporting.

Thanks,
Kevin

6 Replies

MG Mohanraj Gunasekaran Syncfusion Team February 24, 2017 12:50 PM UTC

Hi Kevin, 

Thanks for using Syncfusion products. 

Please find your response in below table, 
Query 
Solution 
While exporting to excel I need to exclude some of columns from Child table 

By default, GroupingGridExcelConverterControl do not have the support to hide the column while exporting. But you can achieve your scenario using GridGroupingExcelConverterControl using ExcludeColumns property in QueryExportNestedTable event. Please refer to the below code example, 
 
Code example 
GridGroupingExcelConverterControl converter = new GridGroupingExcelConverterControl(); 
converter.QueryExportNestedTable += converter_QueryExportNestedTable; 
 
private void converter_QueryExportNestedTable(object sender, Syncfusion.GroupingGridExcelConverter.ExportNestedTableEventArgs e) 
{ 
    List<String> hidecolumn = new List<string>(); 
    hidecolumn.Add("Field2"); 
    hidecolumn.Add("Field3"); 
    e.ExportingOptions.ExcludeColumns = hidecolumn; 
             
} 


need to export child table row which contains GridControl 

In order to export the child table which contains the GridControl. You can use the Cancel property in QueryExportRowRange event. Please refer to the below code example, 
 
Code example 
GridGroupingExcelConverterControl converter = new GridGroupingExcelConverterControl(); 
converter.QueryExportRowRange += converter_QueryExportRowRange; 
 
private void converter_QueryExportRowRange(object sender, Syncfusion.GroupingGridExcelConverter.QueryExportRowRangeEventArgs e) 
{ 
    Record record = e.Element.GetRecord(); 
    if (record != null && record.ParentTable.Info.Contains("Child")) 
    { 
        int colindex = this.gridGroupingControl1.GetTableModel("Child").NameToColIndex("Control"); 
        GridTableCellStyleInfo style = this.gridGroupingControl1.Table.GetTableCellStyle(e.Element, "Control"); 
        if (!(style.Control is GridControl)) 
            e.Cancel = true; 
    } 
} 
 
Please let us know if we misunderstood your query. 

 


Sample link: GridGroupingControl 
 
 
Regards, 
Mohanraj G. 
 



KE Kevin February 27, 2017 07:10 AM UTC

Hi Mohan,

Thanks for the response. First one is working fine. For "need to export child table row which contains GridControl" query, I would like to export the Grid control which is inside the nested table cell. Also, Is there any options available to exclude column from Grid control(not GridGrouping) on export?

- Kevin


KE Kevin February 28, 2017 07:11 AM UTC

Hi,
I have overrided the gridGroupingControl1_QueryCellStyleInfo event.
void gridGroupingControl1_QueryCellStyleInfo(object sender, GridTableCellStyleInfoEventArgs e)
 {

if (e.TableCellIdentity.DisplayElement.Kind == DisplayElementKind.Record)

{

if (e.TableCellIdentity.DisplayElement.ChildTableGroupLevel == 1)

       {

Record parentRecord = e.TableCellIdentity.Table.TableModel.FilteredChildTable.ParentDisplayElement.ParentRecord;

              // My Coode

}

}

 

GroupingGridExcelConverterControl converter = new GroupingGridExcelConverterControl();

                converter.ExportStyle = true;

                converter.GroupingGridToExcel(this.gridGroupingControl1, "SampleOutput.xls", ConverterOptions.Default);

 

If I am using this converter, below property having values.

e.TableCellIdentity.Table.TableModel.FilteredChildTable 

 

GridGroupingExcelConverterControl converter = new GridGroupingExcelConverterControl();

                converter.ExportStyle = true;

                converter.ExportToExcel(this.gridGroupingControl1, "Output.Xls", new ExcelExportingOptions());

 

If I am using this converter, below property having null values.

e.TableCellIdentity.Table.TableModel.FilteredChildTable

How to get the Parent record if using GridGroupingExcelConverterControl converter?

 
- Kevin



MG Mohanraj Gunasekaran Syncfusion Team March 1, 2017 01:59 AM UTC

 
Sorry for the inconvenience caused. 
 
Please find your response in below table 
Query 
Solution 
 I would like to export the Grid control which is inside the nested table cell. Also, Is there any options available to exclude column from Grid control(not GridGrouping) on export? 
 
By default, we do not have the support to export the GridControl which is inside the nested table cell. But you can export the GridControl in another sheet and add that sheet reference in that GridControl loaded cell using HyperLinks property and you can hide the column using ColumnWidth property while exporting the GridControl to excel. Please refer to the below code example, 
 
Code example 
converter.QueryExportCellRange += converter_QueryExportCellRange; 
 
void converter_QueryExportCellRange(object sender, Syncfusion.GroupingGridExcelConverter.QueryExportCellRangeEventArgs e) 
{ 
    if (e.GridCell.Control is GridControl) 
    { 
        GridControl control = e.GridCell.Control as GridControl; 
        if (control != null && e.GridCell.CellType == "Control") 
        { 
            GridExcelConverterControl converter = new GridExcelConverterControl(); 
            workbook.Worksheets.Create("Child" + i.ToString()); 
 
                     
            //Export the each grid separately to the worksheets 
            converter.GridToExcel(control, workbook.Worksheets["child" + i.ToString()], ConverterOptions.ColumnHeaders); 
                     
            //Date column has hided. 
            workbook.Worksheets["Child" + i.ToString()].Columns[1].ColumnWidth = 0; 
            //refer the exported sheet for GridCotrol 
            IHyperLink hyperlink4 = e.ExcelCell.Worksheet.HyperLinks.Add(workbook.Worksheets["child" + i.ToString()].Range[e.ExcelCell.AddressLocal]); 
            hyperlink4.Type = ExcelHyperLinkType.Workbook; 
            hyperlink4.Address = "child" + i.ToString() + "!A1"; 
            hyperlink4.TextToDisplay = "child" + i.ToString(); 
 
            //To hide the colum in GridControl while exporting. 
            if (e.GridCell.CellIdentity.ColIndex == 2) 
                e.ExcelCell.ColumnWidth = 0; 
 
        } 
 
        i++; 
    } 
} 
 
 
 
If I am using this converter, below property having null values. 
e.TableCellIdentity.Table.TableModel.FilteredChildTable
How to get the Parent record if using GridGroupingExcelConverterControl converter?
 
 
 
We have tested your scenario using below attached sample. But we are unable to reproduce your scenario at our end. The GridGroupingExcelConverterControl not affect the FilteredChildTable property in QueryCellStyleInfo. So, please provide the following details, 
·         Let us know, have you got the null value for FilteredChildTable while exporting. 
·         Please provide the your Syncfusion product version details. 
 
If we missed anything in our attached sample, please modify the sample to reproduce your scenario. It will be helpful to provide the solution at the earliest. 
 
 
 
Sample link: GridGroupingControl 
 
Regards, 
Mohanraj G 
  



KE Kevin March 1, 2017 05:36 AM UTC

Hi Mohan,

Thanks a lot. I will check and get touch with you shortly. 
In Grid Exporting, there is an option for export hidden rows and columns handling-hidden-rows-and-columns-exporting. Like this, Is there any option available in GridGroupingControl excel export using GridGroupingExcelConverterControl converter?

- Kevin


MG Mohanraj Gunasekaran Syncfusion Team March 2, 2017 07:17 AM UTC

Hi Kevin  
   
Thanks for your update.   
   
By default, The GridGroupingExcelConverter control having the support to hide the columns using ExcludeColumns property. Please refer to the below code example, 
 
Code example 
ExcelExportingOptions options = new ExcelExportingOptions(); 
options.ExcludeColumns.Add("Date"); 
 
 
If you want to export the hidden columns in hidden state, we do not have the direct API (ExportHiddenColumnsMode and ExportHiddenRowsMode) in GridGroupingExcelConverterControl. But you can achieve your scenario by using IWorksheet.HideRow and IWorksheet.HideColumn method to export the hidden rows or columns with hidden state. Please refer to the below code example and the sample,   
   
Code example   
IWorkbook workbook = ExcelUtils.CreateWorkbook(new String[] { "Sheet" });                   
converter.ExportToExcel(this.gridGroupingControl1, workbook.Worksheets[0], options);   
//To export the hidden column in hidden state.   
workbook.Worksheets[0].HideColumn(2);   
//To export the hidden row in hidden state.   
workbook.Worksheets[0].HideRow(4);   
 
 
Screenshot 
 
   
Sample link: GridGroupingControl   
   
   
Regards,   
Mohanraj G   
 


Loader.
Live Chat Icon For mobile
Up arrow icon