The code xaml for the column is:
<tlkEx:RadGridViewEx x:Name="gvData" Grid.Row="1" AutoGenerateColumns="False" IsReadOnly="True" ColumnsWidthMode="Auto">
<tlkGrid:RadGridView.Columns> ....
<tlkGrid:GridViewDataColumn UniqueName="LetturaDataCalcolo" HeaderText="sospesoEFLetturaDataCalcolo" DataMemberBinding="{Binding LetturaDataCalcolo}" DataFormatString="{}{0:#,0.######}" TextAlignment="Right"/> ...
</tlkGrid:RadGridView.Columns></tlkEx:RadGridViewEx>
Code behind to generate Excel:
if (gvData != null)
{
var clientStatusColumn = GridView.Columns.OfType<GridViewColumn>().Where(c => c.UniqueName.Equals(Constants.GridViewColumnsIDs.clientStatusNotifyID, StringComparison.InvariantCultureIgnoreCase)).FirstOrDefault();
if (clientStatusColumn != null) clientStatusColumn.IsVisible = false;
String content = GridView.ToExcelML(true);
if (clientStatusColumn != null) clientStatusColumn.IsVisible = true;
if (!String.IsNullOrEmpty(content))
{
Uri uri = new Uri(HtmlPage.Document.DocumentUri, String.Format("ExportHandler.aspx?type=xls&uid={0}", App.UserInfo.UserName));
WebClient client = new WebClient();
client.UploadStringCompleted += new UploadStringCompletedEventHandler(exportClientUploadStringCompleted);
client.UploadStringAsync(uri, content);
}
}
The export of number column as the LetturaDataCalcolo in excel is a text cell or has at the beginning a char like '; It's not a number cell even if I specify, in the inizialize method,:
((GridViewDataColumn)gvData.Columns["LetturaDataCalcolo"]).DataType = typeof(Double);
The item source of the grid is a list of type that have the correct decimal type
Is it possible, in Silverlight3 with ToExcelML, format the cell in the output excel file like a number ?
I can send the excel generated that I cannot attach here.
Regards
Vittorio
8 Answers, 1 is accepted
Since you have defined DataFormatString for this column the grid will call string.Format() with this format and you will get new string type value.
Kind regards,Vlad
the Telerik team
Is it possible to convert that column into a double even if there is a data format string applied to that column?
Best regards,
Charlie
You can use the ElementExporting event of the grid to modify the exported value any way you want to. You can see how this can be done in our online examples here.
Hope this helps!
Nik
the Telerik team
I have a RadGridView and it is grouped by a column. Also, I've implemented aggregate functions to the grid (Sum function). When I export it, I've dealt with the problem where all of the exported cells in the tables are strings (even though they are numbers). I implemented that using this link you've provided, and thanks a lot! http://demos.telerik.com/silverlight/#GridView/Exporting
Unfortunately, I am dealing with exporting the GroupFooterCell. The exported results (the aggregate results) are always string. Even if it's just a number. Here is the code I'm using:
else if (e.Element == ExportElement.GroupFooterCell)
{
GridViewDataColumn column = e.Context as GridViewDataColumn;
QueryableCollectionViewGroup qcvGroup = e.Value as QueryableCollectionViewGroup;
if (column != null && qcvGroup != null && column.AggregateFunctions.Count > 0)
{
string value = GetAggregates(qcvGroup, column);
value = ReplaceIllegalExcelCharacters(value);
double Number;
bool IsNum = double.TryParse(value, out Number);
if (IsNum)
e.Value = Number;
else
e.Value = value;
}
}
This code runs, and the e.Value is being set to the correct value, but it's string. I've tried setting a break point at e.Value = Number, and that breakpoint is being hit. I've even tried hardcoding that e.Value = 10, and the result appears in the exported excel sheet, but it's a string. I'm not sure what's going on! Thanks!
Best regards,
Charlie
This happens as the original value in e.Value is not of type Number. The Element (for the GroupFooterCell) is already created by the time when you change the value.
To change the exported data, you can extract the text from the resulted Stream and change the type for those nodes to be Number instead of String.
Didie
the Telerik team
Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>
I'm not sure what you mean by "To change the exported data, you can extract the text from the resulted Stream and change the type for those nodes to be Number instead of String."
Best regards,
Charlie
When I set a breakpoint and view the dataType of "e.Context as GridViewDataColumn", I get a result of Double. I'm not sure what to do from here. Thanks for your help!
Best regards,
Charlie
You can take the generated stream and proceed with it as you would like. For example:
this
.clubsGrid.Export(tempStream, exportOptions);
var reader = newStreamReader(tempStream);
tempStream.Position = 0;
var text = reader.ReadToEnd();
// change the text
var writer =
new
StreamWriter(stream);
writer.Write(text);
writer.Flush();
Didie
the Telerik team
Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>