Hello, I have recently migrated a scorecard system from the RadControls_Q1_2007_SP2 to RadControls_for_ASP.NET_AJAX_2009_3_1208_dev. One of the features that seemed to be inherently built in was a consistent format in the excel output. A large chunk of the data is in percent form. It displays fine in the grid, but when I am exporting it, it returns to a standard decimal format. The data stays correct, but I cannot get the percent format in the export. Here is the aspx for the column that is calculated from the data source.
Here is the codebehind to generate the value of the field:
As you can see, we have a column with a span that creates a popup, and then a column appended with "_Export" That holds just the data.
We adjust the visibility on export as follows:
I've tried modifying the ExportOnlyData field, and adding the following as well, nothing seems to work to get the percent formatted. Any help would be greatly appreciated.
<telerik:GridBoundColumn Visible="False" DataField="AvgQA_Export" HeaderText="Avg. QA" UniqueName="colAvgQA_Export"> |
<HeaderStyle BackColor="#FFCC00" CssClass="rgYellow" HorizontalAlign="Center" /> |
<ItemStyle HorizontalAlign="Right" /> |
</telerik:GridBoundColumn> |
Here is the codebehind to generate the value of the field:
Protected Sub rgScorecard_ItemDataBound(ByVal sender As Object, ByVal e As GridItemEventArgs) Handles rgScorecard.ItemDataBound |
If TypeOf e.Item Is GridDataItem Then |
Dim dataItem As GridDataItem = CType(e.Item, GridDataItem) |
' QA |
' -------------------------------------------- |
If dataItem("colQAScore").Text = 0 Or dataItem("colQANumEvals").Text = 0 Then |
dataItem("colAvgQA").Text = "<a href='#' class='info'><span class='info'>" & dataItem("colSupName").Text & "<br>'Avg. QA'<br>GOAL: " & FormatPercent(m.goal("AvgQA"), 3) & "<hr>Total QA Score: " & dataItem("colQAScore").Text & "<br># QAs: " & dataItem("colQANumEvals").Text & "<hr>" & dataItem("colQAScore").Text & "/" & dataItem("colQANumEvals").Text & "</span>" & FormatPercent(0, 3) & "</a>" |
dataItem("colAvgQA_Export").Text = FormatPercent(0, 3) |
Else |
dataItem("colAvgQA").Text = "<a href='#' class='info'><span class='info'>" & dataItem("colSupName").Text & "<br>'Avg. QA'<br>GOAL: " & FormatPercent(m.goal("AvgQA"), 3) & "<hr>Total QA Score: " & dataItem("colQAScore").Text & "<br># QAs: " & dataItem("colQANumEvals").Text & "<hr>" & dataItem("colQAScore").Text & "/" & dataItem("colQANumEvals").Text & "</span>" & FormatPercent(Double.Parse(dataItem("colQAScore").Text) / Integer.Parse(dataItem("colQANumEvals").Text) / 100, 3) & "</a>" |
dataItem("colAvgQA_Export").Text = FormatPercent(Double.Parse(dataItem("colQAScore").Text) / Integer.Parse(dataItem("colQANumEvals").Text) / 100, 3) |
End If |
We adjust the visibility on export as follows:
Protected Sub btExcel_Click(ByVal sender As Object, ByVal e As EventArgs) Handles DateControl.Export |
rgscorecard.Rebind |
rgScorecard.Columns.FindByUniqueNameSafe("colAvgQA").Visible = False |
rgScorecard.Columns.FindByUniqueNameSafe("colAvgQA_Export").Visible = True |
rgScorecard.ExportSettings.OpenInNewWindow = True |
rgScorecard.ExportSettings.ExportOnlyData = False |
rgScorecard.ExportSettings.FileName = "Sups_Tiers_Scorecard_" & DateControl.SCFrom & "_thru_" & DateControl.SCTo |
rgScorecard.MasterTableView.ExportToExcel() |
End Sub |
I've tried modifying the ExportOnlyData field, and adding the following as well, nothing seems to work to get the percent formatted. Any help would be greatly appreciated.
Private Sub rgScorecard_ExcelExportCellFormatting(ByVal source As Object, ByVal e As Telerik.Web.UI.ExcelExportCellFormattingEventArgs) Handles rgScorecard.ExcelExportCellFormatting |
If TypeOf e.FormattedColumn Is GridBoundColumn Then |
Dim column As GridBoundColumn = CType(e.FormattedColumn, GridBoundColumn) |
If column.HeaderText.Contains("%") Then 'ALL REQUIRED COLUMNS CONTAIN THE PERCENT SIGN IN THE HEADER |
column.DataFormatString = "{0:D4}" |
End If |
End If |
End Sub |