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
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
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);
}
} |
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
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!
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); |
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)