Exporting Stacked Headers - Excel/PDF
Dear Sir,
I am unable to export Stacked Header in Excel/PDF format with Background Color/Text Color in RGB.
I can Export only Stacked Header but its color is not working. What is the Solution for that ?
Thanks
Deepak
SIGN IN To post a reply.
3 Replies
JP
Jagadeesan Pichaimuthu
Syncfusion Team
May 20, 2019 12:23 PM UTC
Hi Deepak,
Thanks for using Syncfusion product.
|
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.
|
Please find the sample from below location.
Let us know whether this helps also if you need any further assistance on this.
Regards,
Jagadeesan
DE
Deepak
July 19, 2019 07:13 AM UTC
Hi Jagadeesan,
Thanks for your reply.
I want to export Stack Header in different color.
Example : I have Two Stack Header in my SFDATAGRID.. First Stach Header has different color and second Stach Header has different color. Check the attachment for reference.
I am unable to get the required result.
Pls send me the solution with sample.
Thanks
Deepak
Attachment: stackheadercolorsimple_b43b3e56.rar
SS
Susmitha Sundar
Syncfusion Team
July 22, 2019 06:27 PM UTC
Hi Deepak,
We have analyzed your reported query “Export the StackedHeaders with different colors” in Excel/PDF. You can achieve this in Excel by add the range for cells. Please refer the following code snippet,
C#:
|
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");
} |
For exporting in PDF, you can achieve this by CellExporting event. Please refer the following code snippet,
C#:
|
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;
}
}
} |
Sample link: https://www.syncfusion.com/downloads/support/forum/144690/ze/DataGrid_Exporting1124718529
Please contact us for further assistance.
Regards,
Susmitha S
SIGN IN To post a reply.
- 3 Replies
- 3 Participants
-
DE Deepak
- May 17, 2019 01:57 PM UTC
- Jul 22, 2019 06:27 PM UTC