Query |
Solution | |
Exporting the Stacked headers to Excel |
You can able to customize the back color and text color of the stacked headers in excel exporting can be achieved by using the Exporting event. Please refer the below code snippet, here the colors can be set from grid style setting. You can also able to initialize the RGB colors in below method.
Please refer the below documentation for your reference.
| |
Exporting the stacked headers to PDF
|
You can able to customize the appearance of stacked headers while exporting to PDF by using the
Please refer the below documentation for your reference.
|
private void Excel_Exporting(object sender, EventArgs e)
{
var options = new ExcelExportingOptions();
var excelEngine = sfDataGrid1.ExportToExcel(sfDataGrid1.View, options);
var workBook = excelEngine.Excel.Workbooks[0];
workBook.Worksheets[0].Range["A1:A1"].CellStyle.Color = Color.DarkCyan;
workBook.Worksheets[0].Range["A1:A1"].CellStyle.Font.Color = ExcelKnownColors.White;
workBook.Worksheets[0].Range["B1:C1"].CellStyle.Color = Color.LightCyan;
workBook.Worksheets[0].Range["B1:C1"].CellStyle.Font.Color = ExcelKnownColors.Black;
workBook.Worksheets[0].Range["D1:E1"].CellStyle.Color = Color.DarkGray;
workBook.Worksheets[0].Range["D1:E1"].CellStyle.Font.Color = ExcelKnownColors.White;
workBook.SaveAs("SampleRange.xlsx");
} |
private void options_CellExporting(object sender, DataGridCellPdfExportingEventArgs e)
{
if(e.CellType==ExportCellType.StackedHeaderCell)
{
if(e.CellValue.ToString()=="Order Details")
{
var cellStyle = new PdfGridCellStyle();
cellStyle.BackgroundBrush = PdfBrushes.DarkCyan;
cellStyle.TextBrush = PdfBrushes.White;
e.PdfGridCell.Style = cellStyle;
}
else if (e.CellValue.ToString() == "Customer Details")
{
var cellStyle = new PdfGridCellStyle();
cellStyle.BackgroundBrush = PdfBrushes.LightCyan;
e.PdfGridCell.Style = cellStyle;
}
else if (e.CellValue.ToString() == "City Details")
{
var cellStyle = new PdfGridCellStyle();
cellStyle.BackgroundBrush = PdfBrushes.DarkGray;
cellStyle.TextBrush = PdfBrushes.White;
e.PdfGridCell.Style = cellStyle;
}
}
} |