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.