This is a migrated thread and some comments may be shown as answers.

[Solved] Export to Excel number format

5 Answers 454 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Gerwin
Top achievements
Rank 1
Gerwin asked on 19 Mar 2013, 02:22 PM
I have the following problem.

When a number in the grid is formatted in the format used in France (10 123 in stead of 10.123) and when i export to excel, excel does not see this as a number, because of the space.

Is there a way that it will always be exported as 10123, so without any formatting?

5 Answers, 1 is accepted

Sort by
0
Accepted
Kostadin
Telerik team
answered on 22 Mar 2013, 09:37 AM
Hello Gerwin,

I am not sure which Excel format you are using. If you are using Html-Based format you could remove the DataFormatString in code behind when export is fired. Note that if IgnorePaging property is set to false you have to call Rebind() method. Check out the following code snippet.
protected void Button1_Click(object sender, EventArgs e)
{
    GridBoundColumn col = RadGrid1.MasterTableView.GetColumn("Column1") as GridBoundColumn;
    col.DataFormatString = null;
    RadGrid1.MasterTableView.ExportToExcel();
}

All the best,
Kostadin
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
0
Gerwin
Top achievements
Rank 1
answered on 29 Mar 2013, 12:17 PM
Hi Kostadin.
Thank you for you're reaction.
This solution is working, but is it also possible to do this for all the columns at once?
0
Shinu
Top achievements
Rank 2
answered on 01 Apr 2013, 06:51 AM
Hi,

Try the following code to loop through columns.
C#:
protected void Button1_Click(object sender, EventArgs e)
{
        foreach (GridBoundColumn col in RadGrid1.Columns)
        {
            col.DataFormatString = null;
        }
        RadGrid1.MasterTableView.ExportToExcel();
}

Thanks,
Shinu
0
Gerwin
Top achievements
Rank 1
answered on 15 Apr 2013, 02:56 PM
Is it also possible to have formatting on a GridTemplateColumn?
0
Shinu
Top achievements
Rank 2
answered on 16 Apr 2013, 04:24 AM
Hi,

You can format the columns as shown below.
C#:
protected void RadGrid1_ExportCellFormatting(object sender, ExportCellFormattingEventArgs e)
{
    if ((e.FormattedColumn.UniqueName) == "Uniquename")
    {
        e.Cell.Style["mso-number-format"] = @"$";
       
    }
}

Thanks,
Shinu
Tags
Grid
Asked by
Gerwin
Top achievements
Rank 1
Answers by
Kostadin
Telerik team
Gerwin
Top achievements
Rank 1
Shinu
Top achievements
Rank 2
Share this question
or