I am trying to export the data in the grid using Radgrid export excel feature. Export works fine. But when i trying to do custom formting the rows it is throwing error when opening the excel "Prorblem came up in the following area during load" dialog of excel shows.
Below is the code i am using for custom formating. I found the same code in Radgrid help too. It is working at the sample project present online in Radcontros site. Any help would be appreciated.
protected void rgGrid_ExcelMLExportRowCreated(object source, Telerik.Web.UI.GridExcelBuilder.GridExportExcelMLRowCreatedArgs e)
{
if (e.RowType == Telerik.Web.UI.GridExcelBuilder.GridExportExcelMLRowType.DataRow)
{
if (e.Row.Cells[5] != null && (e.Row.Cells[5].Data.DataItem).Equals("I")){
e.Row.Cells[0].StyleValue = "InsertStyle";
}
if (e.Row.Cells[5] != null && (e.Row.Cells[5].Data.DataItem).Equals("U")){
e.Row.Cells[0].StyleValue = "UpdateStype";
}
if (e.Row.Cells[5] != null && (e.Row.Cells[5].Data.DataItem).Equals("D")){
e.Row.Cells[0].StyleValue = "DeleteStyle";
}
}
}
protected void rgGrid_ExcelMLExportStylesCreated(object source, Telerik.Web.UI.GridExcelBuilder.GridExportExcelMLStyleCreatedArgs e){
foreach (Telerik.Web.UI.GridExcelBuilder.StyleElement style in e.Styles){
if (style.Id == "headerStyle"){
style.FontStyle.Bold = true;
style.FontStyle.Color = System.Drawing.Color.Gainsboro;
style.InteriorStyle.Color = System.Drawing.Color.Wheat;
style.InteriorStyle.Pattern = Telerik.Web.UI.GridExcelBuilder.InteriorPatternType.Solid;
}
else if (style.Id == "itemStyle")
{
style.InteriorStyle.Color = System.Drawing.Color.WhiteSmoke;
style.InteriorStyle.Pattern = Telerik.Web.UI.GridExcelBuilder.InteriorPatternType.Solid;
}
else if (style.Id == "alternatingItemStyle")
{
style.InteriorStyle.Color = System.Drawing.Color.LightGray;
style.InteriorStyle.Pattern = Telerik.Web.UI.GridExcelBuilder.InteriorPatternType.Solid;
}
}
Telerik.Web.UI.GridExcelBuilder.StyleElement myStyle = new Telerik.Web.UI.GridExcelBuilder.StyleElement("InsertStyle");
myStyle.FontStyle.Bold = true;
myStyle.FontStyle.Italic = true;
myStyle.InteriorStyle.Color = System.Drawing.Color.Gray;
myStyle.InteriorStyle.Pattern = Telerik.Web.UI.GridExcelBuilder.InteriorPatternType.Solid;
e.Styles.Add(myStyle);
Telerik.Web.UI.GridExcelBuilder.StyleElement upStyle = new Telerik.Web.UI.GridExcelBuilder.StyleElement("UpdateStyle");
upStyle.FontStyle.Bold = true;
upStyle.FontStyle.Italic = true;
upStyle.InteriorStyle.Color = System.Drawing.Color.Aqua;
upStyle.InteriorStyle.Pattern = Telerik.Web.UI.GridExcelBuilder.InteriorPatternType.Solid;
e.Styles.Add(upStyle);
Telerik.Web.UI.GridExcelBuilder.StyleElement delStyle = new Telerik.Web.UI.GridExcelBuilder.StyleElement("DeleteStyle");
delStyle.FontStyle.Bold = true;
delStyle.FontStyle.Italic = true;
delStyle.InteriorStyle.Color = System.Drawing.Color.Brown;
delStyle.InteriorStyle.Pattern = Telerik.Web.UI.GridExcelBuilder.InteriorPatternType.Solid;
e.Styles.Add(delStyle);
}