Hello Jan,
Thank you for writing back.
The layout you want can be achieved by hiding all header rows and adding two custom rows to the top of the excel table. To do that you should you use the ExcelTableCreated event of the exporter. Here is an example of how to use it:
this
.radGridView1.MasterTemplate.ShowColumnHeaders =
false
;
this
.radGridView1.MasterTemplate.Templates[0].ShowColumnHeaders =
false
;
ExportToExcelML exporter =
new
ExportToExcelML(
this
.radGridView1);
string
filePath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop),
"grid.xls"
);
exporter.ExcelTableCreated += exporter_ExcelTableCreated;
exporter.ExportHierarchy =
true
;
exporter.RunExport(filePath);
this
.radGridView1.MasterTemplate.ShowColumnHeaders =
true
;
this
.radGridView1.MasterTemplate.Templates[0].ShowColumnHeaders =
true
;
private
void
exporter_ExcelTableCreated(
object
sender, ExcelTableCreatedEventArgs e)
{
RowElement excelRowElement1 =
new
RowElement();
excelRowElement1.Attributes.Add(
"ss:Height"
,
"15"
);
RowElement excelRowElement2 =
new
RowElement();
excelRowElement2.Attributes.Add(
"ss:Height"
,
"15"
);
CellElement cellElement =
new
CellElement();
string
mainGroupStyleId =
"MyUniqueStyleIdString"
;
//This should be unique so styles do not mix
SingleStyleElement excelStyleElement =
new
SingleStyleElement(mainGroupStyleId);
excelStyleElement.AlignmentElement.HorizontalAlignment = HorizontalAlignmentType.Center;
foreach
(GridViewColumn col
in
this
.radGridView1.MasterTemplate.Columns)
{
cellElement =
new
CellElement();
cellElement.Data.DataItem = col.HeaderText;
cellElement.StyleValue = mainGroupStyleId;
excelRowElement1.Cells.Add(cellElement);
}
cellElement =
new
CellElement();
cellElement.Data.DataItem =
""
;
excelRowElement2.Cells.Add(cellElement);
foreach
(GridViewColumn col
in
this
.radGridView1.MasterTemplate.Templates[0].Columns)
{
cellElement =
new
CellElement();
cellElement.Data.DataItem = col.HeaderText;
cellElement.StyleValue = mainGroupStyleId;
excelRowElement2.Cells.Add(cellElement);
}
e.ExcelTableElement.Workbook.Styles.Add(excelStyleElement);
e.ExcelTableElement.Rows.Add(excelRowElement1);
e.ExcelTableElement.Rows.Add(excelRowElement2);
}
I hope this will help. Feel free to write back with any further questions.
Regards,
Ivan Petrov
Telerik