Grouped Data: how collapse or delete groupname?

Hi!

I'm exporting "grouped" data from SfDataGrid to XLS. The listing is grouped by FILENAME, a field reflected by the first column of the grid,

My problem :

The sheet contains both the "group name" in a row and, in the next row, the grid data which shows a duplicate view of the filename. The "group-name" is an OUTLINE row, allowing user to collapse it. 


Possible solutions:

1- I could close the oulined rows automatically during the sheet generation (all oulined rows are expanded).

2- I could discard the "group-name" during the exportation.

Does anyone has a tip to achieve ANY of the above solutions to my problem?
I appreciate any help.

Kind regards,
David


8 Replies

VS Vijayarasan Sivanandham Syncfusion Team October 4, 2021 02:41 PM UTC

Hi David Ben Svaiter,

Thank you for contacting Syncfusion Support. 



Can you please confirm above mentioned scenario is duplicate value shows while exporting to excel with grouping case?

Regards, 
Vijayarasan S 



DA DavidBS October 5, 2021 12:12 AM UTC

Hi Vijayarasan!


My data is a little bit differente (see the RAR):


1- My SfDataGrid is Grouped by the 1st field (filename), as shown in IMAGE1. It makes easier to user to locate some file and, then, he can inspect the file details (IMAGE2)


2- When I export to Excel using XLS-IO, you can see that all groups name appear (otherwise would be fine!) and also they are expanded - if they could be collapsed would be fine too!


Kind regards!


Attachment: grid_12ad5e29.rar



VS Vijayarasan Sivanandham Syncfusion Team October 5, 2021 02:13 PM UTC

Hi David Ben Svaiter,

Thanks for the update.

Your requirement can be achieved by create the custom Excel export by using DataGridToExcelConverter and override the ExportGroupToExcel method in custom Excel Export option. Please refer the below code snippet, 
public partial class Form1 : Form 
{ 
        customDataGridToExcelConverter customDataGridToExcel; 
        public Form1() 
        { 
            InitializeComponent(); 
            customDataGridToExcel = new customDataGridToExcelConverter(); 
            sfDataGrid.DataSource = new ViewModel().Orders; 
            sfDataGrid.ShowGroupDropArea = true; 
            btnExportExcel.Click += BtnExportExcel_Click; 
        } 
 
        private void BtnExportExcel_Click(object sender, EventArgs e) 
        { 
            var options = new ExcelExportingOptions(); 
            options.AllowOutlining = true; 
 
            //call the custom Excel Exporting  
            var excelEngine = customDataGridToExcel.ExportToExcel(sfDataGrid,sfDataGrid.View, options); 
            var workBook = excelEngine.Excel.Workbooks[0]; 
            workBook.SaveAs("Sample.xlsx"); 
         }             
} 
 
public class customDataGridToExcelConverter : DataGridToExcelConverter 
{ 
        protected override void ExportGroupToExcel(SfDataGrid grid, ICollectionViewAdv view, IWorksheet sheet, ExcelExportingOptions excelExportingOptions, Group group) 
        { 
            //here set the false value for IsExpanded property to collapse the all groups after exporting 
            group.IsExpanded = false; 
            base.ExportGroupToExcel(grid, view, sheet, excelExportingOptions, group); 
        } 
} 
 
Sample Link: https://www.syncfusion.com/downloads/support/forum/169371/ze/SfDataGridDemo86363177

Please let us know if you have any concerns in this. 

Regards, 
Vijayarasan S 



DA DavidBS October 5, 2021 04:50 PM UTC

Hi Vijayarasan!

It looks great... I will test until tomorrow and report if this method fix my problem.


Thank you very much.

See you soon.


Kindest regards,

David



DA DavidBS October 5, 2021 10:37 PM UTC

Vijayarasan, it didn't function...


If I try something like 

excelEngine = CustomDataGridToExcel.ExportToExcel(gridAutenticidade, gridAutenticidade.View, options)

... I can see the new custom Class being called, I see the "group.IsExpanded" being "false", but the sheet still opens with all lines expanded (same result as before).


But notice that:

1- I neither have the GROUP AREA in my datagrid nor I allow users to define one. I set it programatically for the first field (filename).


2- If I try something like 

excelEngine = CustomDataGridToExcel.ExportToExcel(gridAutenticidade, gridAutenticidade.View, options, gridAutenticidade.GroupColumnDescriptions)

... the method is not accepted (syntax error). And it's right, since Workbook and Sheet aren't defined yet (they will be defined as an "excelEngine" type).

So, it seems that my programmatically defined Group is not being seen by the custom class...

Any tip about it?

Thanks!





VS Vijayarasan Sivanandham Syncfusion Team October 6, 2021 08:10 AM UTC

Hi David Ben Svaiter, 

Thanks for the update.

You can resolve the reported by enabling the AllowOutlining property in ExcelExportingOptions. Please refer the below code snippet, 
var options = new ExcelExportingOptions(); 
//enable the AllowOutlining property in ExcelExportingOptions 
options.AllowOutlining = true; 
 
//call the custom Excel Exporting  
var excelEngine = customDataGridToExcel.ExportToExcel(sfDataGrid,sfDataGrid.View, options); 
 
For more information related to Export Groups with Outlines , please refer the user guide documentation, 
UG Link: https://help.syncfusion.com/windowsforms/datagrid/exporttoexcel#export-groups-with-outlines

Please let us know if you have any concerns in this. 

Regards, 
Vijayarasan S 



DA DavidBS October 6, 2021 12:36 PM UTC

Dear Vijayarasan,


This option is ALREADY enabled.

See my options below:



Dim options = New ExcelExportingOptions()


options.ExportMode = ExportMode.Value

options.ExportPageOptions = ExportPageOptions.ExportToSingleSheet

options.ExportStyle = True

options.ExportTableSummary = False

options.StartColumnIndex = 2

options.StartRowIndex = 6

options.ExportGroupSummary = False

options.ExportUnboundRows = False


options.AllowOutlining = True

Dim excelEngine = CustomDataGridToExcel.ExportToExcel(gridAutenticidade, gridAutenticidade.View, options)


Dim workBook = excelEngine.Excel.Workbooks(0)

Dim sheet As IWorksheet = workBook.Worksheets(0)




VS Vijayarasan Sivanandham Syncfusion Team October 7, 2021 02:58 PM UTC

Hi David Ben Svaiter,

Thanks for the update.

We have checked with your provided code snippet from our end. Grouped data collapsed in Exported excel file. Please find the tested sample and video demo from our end in the link below, 
If we misunderstood your requirement, can you please share us below things?         
        1. Provide more details about your scenario with image illustrations? 
        2. Can you please share your exact requirement?

Kindly revert to us with the above requested details. It will be more helpful for us to check the possibilities to resolve the reported problem.

Regards,
Vijayarasan S 


Loader.
Up arrow icon