Hello,
I'd like to keep colors of my radgrid's rows on my Excel file. When I execute my export, Excel displays an loading issue of file ("Table" is the cause of error).
Can you help me to resolve this problem, please !
Here my source code :
transaction.aspx :
...
transactions.aspx.cs :
Best Regards
I'd like to keep colors of my radgrid's rows on my Excel file. When I execute my export, Excel displays an loading issue of file ("Table" is the cause of error).
Can you help me to resolve this problem, please !
Here my source code :
transaction.aspx :
...
<telerik:RadGrid ID="RadGrid1" runat="server" AllowPaging="True" GridLines="None" AllowFilteringByColumn="True" AllowSorting="True" Skin="Windows7" OnItemDataBound="RadGrid1_ItemDataBound" OnSelectedIndexChanged="RadGrid1_SelectedIndexChanged" DataSourceID="odsTransactionsValidees" onprerender="RadGrid1_PreRender" OnExcelMLExportStylesCreated="RadGrid1_ExcelMLExportStylesCreated" onexcelmlexportrowcreated="RadGrid1_ExcelMLExportRowCreated">...
<ExportSettings OpenInNewWindow="True" ExportOnlyData="True" FileName="ExportValidees" IgnorePaging="true" Excel-Format="ExcelML" />....
<MasterTableView DataSourceID="odsTransactionsValidees" AutoGenerateColumns="False" NoMasterRecordsText="Pas de transactions." Font-Size="Medium" UseAllDataFields="true" DataKeyNames="ID_TRANSACTION,DOUTE_CLASSIFICATION" OverrideDataSourceControlSorting="true" AllowNaturalSort="true" CommandItemDisplay="Bottom"> <CommandItemSettings ExportToExcelText="Export Excel" ShowExportToExcelButton="False" ShowAddNewRecordButton="False" ShowRefreshButton="False" />....
</telerik:RadGrid>....
transactions.aspx.cs :
protected void RadGrid1_ExcelMLExportStylesCreated(object source, GridExportExcelMLStyleCreatedArgs e) { // ajoute les bordures de cellule BorderStylesCollection borders = new BorderStylesCollection(); BorderStyles borderStyle = null; for (int i = 1; i <= 4; i++) { borderStyle = new BorderStyles(); borderStyle.PositionType = (PositionType)i; borderStyle.Color = System.Drawing.Color.Black; borderStyle.LineStyle = LineStyle.Continuous; borderStyle.Weight = 1.0; borders.Add(borderStyle); } foreach (StyleElement style in e.Styles) { foreach (BorderStyles border in borders) { style.Borders.Add(border); } } StyleElement style1 = new StyleElement("MyStyleWhite"); style1.InteriorStyle.Pattern = InteriorPatternType.Solid; style1.InteriorStyle.Color = System.Drawing.Color.White; e.Styles.Add(style1); StyleElement style2 = new StyleElement("MyStyleOrange"); style2.InteriorStyle.Pattern = InteriorPatternType.Solid; style2.InteriorStyle.Color = System.Drawing.Color.Orange; e.Styles.Add(style2); }
protected void RadGrid1_ExcelMLExportRowCreated(object sender, GridExportExcelMLRowCreatedArgs e) { string typeTransaction = hidType.Value; if (e.RowType == GridExportExcelMLRowType.DataRow) { if (typeTransaction == TypeTransactionValide || typeTransaction == TypeTransactionValideReseau) { string style; foreach (GridDataItem item in RadGrid1.MasterTableView.Items) { string color = item.BackColor.ToString(); if (!(bool)item.GetDataKeyValue("DOUTE_CLASSIFICATION")) { style = "myStyleWhite"; } else { style = "myStyleOrange"; } foreach (CellElement cellElement in e.Row.Cells) { cellElement.StyleValue = style; } } } } }
Best Regards