Hello,
I am using Telerik version 2012.1.326
I have a RadGridView, and I am using the ToExcelML() method provided (see code below). The problem is that all of the data is converted into strings by the method. The data comes out of a datatable as strings, decimals, and datetimes. And it is shown in the grid view as it's given datatype. You can filter the columns, and the filter also respects datatype. How do I keep the data as it's original datatype when it is exported?
Thank you,
Eli
SaveFileDialog dialog = new SaveFileDialog();
string extension = "xml";
dialog.InitialDirectory = Settings.Default.DataSavePath;
dialog.DefaultExt = extension;
dialog.Filter = string.Format("{1} files (*.{0})|*.{0}|All files (*.*)|*.*", extension, "ExcelML");
dialog.FilterIndex = 1;
if (dialog.ShowDialog() == DialogResult.OK)
{
var gridOutput = this.radGridView.ToExcelML().Replace("Worksheet1", "Output");
using (Stream stream = dialog.OpenFile())
{
byte[] bytes = Encoding.UTF8.GetBytes(gridOutput);
stream.Write(bytes, 0, bytes.Length);
}
6 Answers, 1 is accepted
Do you have any string formats defined for your columns?
Kind regards,Vlad
the Telerik team
Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>
Thank you for the quick reply. I don't have string formats, because the data is not of string type.
Eli
String formats are for all other types except strings. Do you have anything set for column DataFormatString and/or DataMemberBinding StringFormat?
Kind regards,Vlad
the Telerik team
Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>
DataFormatString is set by a style, we have an attached property because the columns are added in the program.
<attached:ColumnStyle StyleName="Decimal3">
<attached:ColumnStyle.Style>
<Style TargetType="{x:Type telerik:GridViewDataColumn}">
<Setter Property="CellStyle"
Value="{StaticResource DecimalCellTemplate}" />
<Setter Property="DataFormatString"
Value="{}{0:n3}" />
</Style>
</attached:ColumnStyle.Style>
</attached:ColumnStyle>
The grid export will use the defined string format to convert your data to string with the specified format.
All the best,Vlad
the Telerik team
Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>
The RadGridView is displaying the data in the format that we set in the template. The filter is responding correctly as well. The problem seems to be in the export to excel method. I set a breakpoint on the following code and looked at the datatype of the gridViewDataColumn, and it displayed as System.Nullable`1[System.Decimal] I do not know if the fact that it is nullable is forcing a conversion to string, or something else is happening, but the export to excel method is not picking up the datatype correctly.
Thanks,
Eli
GridViewDataColumn gridViewDataColumn = e.Column as GridViewDataColumn;
Binding isVisibleBinding = new Binding("IsVisible");
isVisibleBinding.Mode = BindingMode.TwoWay;
isVisibleBinding.Source = templateColumn;
gridViewDataColumn.SetBinding(GridViewDataColumn.IsVisibleProperty, isVisibleBinding);