Hello Everyone !
how can I make it the same as what it looks like in my grid when I export to excel? almost everything comes out the same... but when I set the condition it doesn't come out :(
this my export Method:
public static void Export(SfDataGrid SfGrid)
{
var options = new ExcelExportingOptions();
options.AllowOutlining = true;
foreach (var column in SfGrid.Columns)
{
if (!column.Visible)
options.ExcludeColumns.Add(column.MappingName);
}
options.ExcludeColumns.Add("EKSREF");
ExcelEngine excelEngine = new ExcelEngine();
IWorkbook workbook = excelEngine.Excel.Workbooks.Create(1);
IWorksheet sheet = workbook.Worksheets[0];
options.ExportStackedHeaders = true;
options.ExportMode = ExportMode.Value;
options.ExcelVersion = ExcelVersion.Excel2016;
options.Exporting += options_Exporting;
sheet.IsRightToLeft = true;
excelEngine = SfGrid.ExportToExcel(SfGrid.View, options);
var workBook = excelEngine.Excel.Workbooks[0];
workBook.Worksheets[0].AutoFilters.FilterRange = workBook.Worksheets[0].UsedRange;
int columnIndexToWrapText = 0;
var columnRange = workBook.Worksheets[0].Columns[columnIndexToWrapText];
columnRange.WrapText = true;
columnRange.ColumnWidth = 15;
columnRange.RowHeight = 24;
string filePath = Path.GetTempFileName().Replace(".tmp", ".xlsx");
workBook.SaveAs(filePath);
System.Diagnostics.Process.Start(filePath);
}
private static void options_Exporting(object sender, Syncfusion.WinForms.DataGridConverter.Events.DataGridExcelExportingEventArgs e)
{
if (e.CellType == ExportCellType.HeaderCell)
{
e.CellStyle.BackGroundColor = Color.LightPink;
e.CellStyle.ForeGroundColor = Color.Black;
e.Handled = true;
}
else if (e.CellType == ExportCellType.GroupCaptionCell)
{
e.CellStyle.BackGroundColor = Color.LightSkyBlue;
e.CellStyle.ForeGroundColor = Color.Black;
e.CellStyle.FontInfo.Bold = true;
e.CellStyle.FontInfo.Size = 10;
e.Handled = true;
}
else if (e.CellType == ExportCellType.TableSummaryCell)
{
e.CellStyle.BackGroundColor = Color.PaleVioletRed;
e.CellStyle.ForeGroundColor = Color.Black;
e.CellStyle.FontInfo.Bold = true;
e.CellStyle.FontInfo.Size = 13;
e.Handled = true;
}
}
This my Sfdatagrid QueryStyle :
private void SfDataGrid_QueryRowStyle(object sender, QueryRowStyleEventArgs e)
{
if (e.RowType == RowType.DefaultRow)
{
var PeriodOne = dtpBaslangic1.Value.ToString("dd-MM-yy");
var PeriodTwo = dtpBaslangic2.Value.ToString("dd-MM-yy");
if ((e.RowData as DataRowView).Row["Raportype"].ToString().Contains(PeriodOne))
e.Style.BackColor = Color.SkyBlue;
else if ((e.RowData as DataRowView).Row["Raportype"].ToString().Contains(PeriodTwo))
e.Style.BackColor = Color.Bisque;
if ((e.RowData as DataRowView).Row["Raportype"].ToString().Contains("RASIYA"))
{
e.Style.Font.Bold = true;
e.Style.TextColor = Color.Red;
}
}
}
this.SfGrid.QueryRowStyle += SfDataGrid_QueryRowStyle;
Please help me with this, it is very important!THANKS :)
Hi Murad Jafarov,
We regret for the inconvenience ,
Your requirement to access SfDataGrid each cell styles and background colors is not possible. If you need to apply colors to an Excel sheet, you will need to manually set the colors for the Excel file.
Regards,
Chidanand M.