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

Excel Exporting Losing Characters

1 Answer 60 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Jako
Top achievements
Rank 1
Jako asked on 24 Apr 2014, 08:13 AM
Hi there

I have a grid that exports to Excel, the data in the SQL Server table are NVARCHAR(4000) fields. It displays correctly, but when exporting it changes some of the diacritics to foreign characters, for example:

DB: André Letoit
Excel:  Andr頌etoit

The code I am using to export is:

/// <summary>
/// Export the Grid to XLS on Server instead of Clientside
/// </summary>
/// <param name="source"></param>
/// <param name="e"></param>
protected void uxExportRequests_GridExporting(object source, GridExportingArgs e)
{
    User currentUser = new User(HttpContext.Current.User.Identity.Name.ToString());
    string fileName = currentUser.UserID.ToString() + "_TitleRequests_" + DateTime.Now.ToShortDateString().Replace("/", "").Replace("-", "") + ".xls";
    string path = Server.MapPath("~/Requests/") + fileName;
 
    using (FileStream fs = File.Create(path))
    {
        Byte[] info = System.Text.Encoding.Default.GetBytes(e.ExportOutput);
        fs.Write(info, 0, info.Length);
    }
}
and
protected void Page_Load(object sender, EventArgs e)
{
    if (!IsPostBack)
    {               
            uxExportRequests.GridLines = GridLines.Both;
            uxExportRequests.GridExporting += new OnGridExportingEventHandler(uxExportRequests_GridExporting);
            uxExportRequests.ExportSettings.Excel.Format = GridExcelExportFormat.ExcelML;
            uxExportRequests.ExportSettings.ExportOnlyData = true;
    }
}
Is there any setting I need to change for this to keep the database characters?

Thank you.

1 Answer, 1 is accepted

Sort by
0
Daniel
Telerik team
answered on 24 Apr 2014, 08:40 AM
Hello Jako,

The problem in my opinion is that you use the "Default" encoding which means that you are using an ANSI code page. If you need to display special characters I would recommend that you try UTF8 (Encoding.UTF8) or UTF16 (Encoding.Unicode) encoding instead.
I hope this helps.

Regards,
Daniel
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
Tags
Grid
Asked by
Jako
Top achievements
Rank 1
Answers by
Daniel
Telerik team
Share this question
or