Skip to content

Commit 9caf7a1

Browse files
authored
Merge pull request #2 from SyncfusionExamples/ES-976509
ES-976509 - Resolve the read me file changes to the sample repository
2 parents 784ad54 + 9689e6c commit 9caf7a1

File tree

3 files changed

+41
-40
lines changed

3 files changed

+41
-40
lines changed

ExportingToExcel.png

67.7 KB
Loading

ExportingToPDF.png

71.5 KB
Loading

README.md

Lines changed: 41 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,54 +1,56 @@
1-
# How to export the WinForms DataGrid StackedHeaders with different back color to Excel and PDF?
1+
# How to Export the WinForms DataGrid StackedHeaders with Different BackColor to Excel and PDF?
22

3-
## About the sample
4-
This example illustrates how to export the WinForms DataGrid StackedHeaders with different back color to Excel and PDF
3+
This example illustrates how to export the [WinForms DataGrid](https://www.syncfusion.com/winforms-ui-controls/datagrid) (SfDataGrid) StackedHeaders with different back color to Excel and PDF
54

6-
By default, actual value only will be exported to Pdf. You can customize StackedHeader cellstyle by using PdfGridCellStyle instance through CellExporting event in PdfExportingOptions.
5+
## Pdf Exporting
6+
7+
By default, background color is not applied for [StackedHeaderRow](https://help.syncfusion.com/cr/windowsforms/Syncfusion.WinForms.DataGrid.StackedHeaderRow.html) when export a `DataGrid` to PDF, you can apply the back color by using [PdfGridCell](https://help.syncfusion.com/cr/windowsforms/Syncfusion.Pdf.Grid.PdfGridCell.html) in [PdfExportingOptions.CellExporting](https://help.syncfusion.com/cr/windowsforms/Syncfusion.WinForms.DataGridConverter.ExcelExportingOptions.html#Syncfusion_WinForms_DataGridConverter_ExcelExportingOptions_CellExporting) event.
78

89
```C#
9-
private void PDF_Exporting(object sender, EventArgs e)
10-
{
11-
PdfExportingOptions options = new PdfExportingOptions();
12-
options.ExportStackedHeaders = true;
13-
options.CellExporting += options_CellExporting;
14-
var document = sfDataGrid1.ExportToPdf(options);
15-
document.Save("Sample.pdf");
16-
}
10+
private void PDF_Exporting(object sender, EventArgs e)
11+
{
12+
PdfExportingOptions options = new PdfExportingOptions();
13+
options.ExportStackedHeaders = true;
14+
options.CellExporting += options_CellExporting;
15+
var document = sfDataGrid1.ExportToPdf(options);
16+
document.Save("Sample.pdf");
17+
}
1718

18-
private void options_CellExporting(object sender, DataGridCellPdfExportingEventArgs e)
19+
private void options_CellExporting(object sender, DataGridCellPdfExportingEventArgs e)
20+
{
21+
if(e.CellType==ExportCellType.StackedHeaderCell)
1922
{
20-
if(e.CellType==ExportCellType.StackedHeaderCell)
23+
if(e.CellValue.ToString()=="Order Details")
24+
{
25+
var cellStyle = new PdfGridCellStyle();
26+
cellStyle.BackgroundBrush = PdfBrushes.DarkCyan;
27+
cellStyle.TextBrush = PdfBrushes.White;
28+
e.PdfGridCell.Style = cellStyle;
29+
}
30+
else if (e.CellValue.ToString() == "Customer Details")
31+
{
32+
var cellStyle = new PdfGridCellStyle();
33+
cellStyle.BackgroundBrush = PdfBrushes.LightCyan;
34+
e.PdfGridCell.Style = cellStyle;
35+
}
36+
else if (e.CellValue.ToString() == "City Details")
2137
{
22-
if(e.CellValue.ToString()=="Order Details")
23-
{
24-
var cellStyle = new PdfGridCellStyle();
25-
cellStyle.BackgroundBrush = PdfBrushes.DarkCyan;
26-
cellStyle.TextBrush = PdfBrushes.White;
27-
e.PdfGridCell.Style = cellStyle;
28-
}
29-
else if (e.CellValue.ToString() == "Customer Details")
30-
{
31-
var cellStyle = new PdfGridCellStyle();
32-
cellStyle.BackgroundBrush = PdfBrushes.LightCyan;
33-
e.PdfGridCell.Style = cellStyle;
34-
}
35-
else if (e.CellValue.ToString() == "City Details")
36-
{
37-
var cellStyle = new PdfGridCellStyle();
38-
cellStyle.BackgroundBrush = PdfBrushes.DarkGray;
39-
cellStyle.TextBrush = PdfBrushes.White;
40-
e.PdfGridCell.Style = cellStyle;
41-
}
38+
var cellStyle = new PdfGridCellStyle();
39+
cellStyle.BackgroundBrush = PdfBrushes.DarkGray;
40+
cellStyle.TextBrush = PdfBrushes.White;
41+
e.PdfGridCell.Style = cellStyle;
4242
}
43-
44-
}
43+
}
44+
}
4545
```
4646

47+
![Exporting the StackedHeaders to PDF](ExportingToPDF.png)
4748

48-
Exporting SfDataGrid StackedHeaders with different back colors by using ExcelExportingOptions by defining the cell style for the StackedHeader cell range.
49+
## Excel Exporting
4950

50-
```C#
51+
By default, background color is not applied for [StackedHeaderRow](https://help.syncfusion.com/cr/windowsforms/Syncfusion.WinForms.DataGrid.StackedHeaderRow.html) when export a SfDataGrid to excel, you can apply the back color by set the color for specific cell range in exported work book.
5152

53+
```C#
5254
private void Excel_Exporting(object sender, EventArgs e)
5355
{
5456
var options = new ExcelExportingOptions();
@@ -64,5 +66,4 @@ private void Excel_Exporting(object sender, EventArgs e)
6466
}
6567
```
6668

67-
## Requirements to run the demo
68-
Visual Studio 2015 and above versions
69+
![Exporting the StackedHeaders to Excel](ExportingToExcel.png)

0 commit comments

Comments
 (0)