I am exporting a grid using the WebExcelExporter and the GroupFields do not seem to be exporting correctly.
See image below.
Hello,
Thank you for posting in the Infragistics community !
Exporting group fields is not currently supported. To achieve this you would need a more custom approach, so I suggest you follow these:
1) In the button click event before you call .Export:
public void Button1_Click(object sender, EventArgs e) {
// 1. create a worksheet to export the grid to Infragistics.Documents.Excel.Workbook book = new Workbook(); book.Worksheets.Add("Report");
// 2. Define merged cells region, which will acts as the group field
book.Worksheets[0].MergedCellsRegions.Add(0, 0, 0, 2); // 2 defines the number of cells to span book.Worksheets[0].MergedCellsRegions[0].Value = "Details"; // set value for the merged cell region, i.e the header text of the group field
// 3. Rebind the grid with AutoGenerateColumns = True, or define new columns without utilizing groupfFeld
this.WebDataGrid1.Columns.Clear(); WebDataGrid1.DataSource = GetDataSource(); this.WebDataGrid1.AutoGenerateColumns = true; this.WebDataGrid1.DataBind();
// 4. Export the grid
this.WebExcelExporter1.Export(this.WebDataGrid1, book.Worksheets["Report"], 1, 0); // 1 means export begins with 1 row offset from the top of the worksheet. This is needed because the first row that is mergedcellsRegions is not part of the grid's rows }
2) Handle RowExported event.
When e.CurrentRowIndex == 1 (this is actualy the grid's header row) we copy its cells' format (font, style, background color) and set them to e.Worksheet.Rows[0], which is the mergedcells region row.
Please see the attached sample that demonstrates the suggested approach and let me know if it meets your requirements.
I'm just following up to see if you need any further assistance with this issue. If so please let me know.
Please find attached the sample that exports the grid. Please be aware that as mentioned multi headers are not supported and this custom approach comply with the following limitations:
1) The Group header is written to the same row in the worksheet where the parent row is displayed
2) Before exporting the grid is bound again and defined with no multi headers
3) I have hardcoded some values for easiness, you should fix these to be dynamically calculated.
Please let me know if you have further question on the matter.
Hi,
You can download the latest service release from Infragistics website, which contains the fix for the issue. Please install it and let me know if you have any further questions or the issue is still reproducible.
I am just following up to see if installing the latest service release fixed the issue. Please let me know.
its working fine,
thanks