Export of chinese characters ...

10 posts, 1 answers
  1. scott
    scott avatar
    67 posts
    Member since:
    Jul 2010

    Posted 20 Sep 2010 Link to this post

    Hello...

    I've got columns in a grid that display the correct unicode stuff for data coming out of asia. When this is exported to CSV or DOC or HTML the format is gone.  This is a city in china named Kunming:  昆明市  and this displays great on the screen, but once exported it looks like:

    昆明市

    It doesn't seem to matter what font I try.

    Does this not work or am I doing something wrong ?

    Thanks -
    Scott
  2. Yavor Georgiev
    Admin
    Yavor Georgiev avatar
    982 posts

    Posted 21 Sep 2010 Link to this post

    Hello scott,

     I'm afraid I was unable to reproduce your problem. Could you please post a few snippets of your code? Where does the data come from?

    Sincerely yours,
    Yavor Georgiev
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  3. scott
    scott avatar
    67 posts
    Member since:
    Jul 2010

    Posted 21 Sep 2010 Link to this post

    Hi Yavor.  Here's a reproducer...

    <UserControl x:Class="chineseCharactersForumPost.MainPage"
        mc:Ignorable="d"
        d:DesignHeight="300" d:DesignWidth="400">
      
        <Grid x:Name="LayoutRoot" Background="White">
            <StackPanel>
                <telerik:RadGridView Name="myGrid" ItemsSource="{Binding}"/>
                <telerik:RadButton Content="Click Me to Export CSV File" Click="CSV_Click"/>
                <telerik:RadButton Content="Click Me to Export DOC File" Click="DOC_Click"/>
                <telerik:RadButton Content="Click Me to Export HTML File" Click="HTML_Click"/>
            </StackPanel>
        </Grid>
    </UserControl>

    And...

    using System.Collections.Generic;
    using System.IO;
    using System.Windows;
    using System.Windows.Controls;
      
    using Telerik.Windows.Controls;
      
    namespace chineseCharactersForumPost
    {
        public partial class MainPage : UserControl
        {
            public MainPage()
            {
                InitializeComponent();
                myGrid.ItemsSource = ViewModel();
            }
      
            List<string> ViewModel()
            {
                return new List<string>() { "石家庄市", "广东南山区", "天津" };
            }
      
            private void CSV_Click(object sender, RoutedEventArgs e)
            {
                Export("CSV");
            }
      
            private void DOC_Click(object sender, RoutedEventArgs e)
            {
                Export("DOC");
            }
      
            private void HTML_Click(object sender, RoutedEventArgs e)
            {
                Export("HTML");
            }
      
            void Export(string x)
            {
                SaveFileDialog dialog = new SaveFileDialog();
                dialog.DefaultExt = x;
                dialog.Filter = string.Format("{1} File (*.{0}) | *.{0}", x, x);
      
                if (!(bool)dialog.ShowDialog())
                    return;
      
                Stream fileStream = dialog.OpenFile();
                ExportTheFile(fileStream, x);
                fileStream.Close();
            }
      
            private void ExportTheFile(Stream fileStream, string x)
            {
                ExportFormat format;
                switch (x)
                {
                    case "HTML":
                        format = ExportFormat.Html;
                        break;
                    case "CSV":
                        format = ExportFormat.Csv;
                        break;
                    case "DOC":
                        format = ExportFormat.Html;
                        break;
                    default:
                        format = ExportFormat.Html;
                        break;
                }
      
                GridViewExportOptions options = new GridViewExportOptions();
                options.Format = format;
                options.ShowColumnFooters = true;
                options.ShowColumnHeaders = true;
                options.ShowGroupFooters = true;
                myGrid.Export(fileStream, options);
            }
      
      
        }
    }





  4. Yavor Georgiev
    Admin
    Yavor Georgiev avatar
    982 posts

    Posted 21 Sep 2010 Link to this post

    Hello scott,

     This happens only when you export to HTML and is rather the fault of the viewer you use. If you opened the resulting .html file with an editor such as Notepad++ you'll see that the chinese characters are indeed intact. However, you'll notice that the HTML file is not complete, but only a fragment. You need to complete the fragment and add a "meta" tag in the HTML document's Head, which tells the browser (or MS Word) to use Unicode to display the data:
    <html>
    <head>
    <meta http-equiv=content-type content="text/html; charset=UTF-8">
    </head>
    <body>
    <table style="border-collapse:collapse" border="1">
    <tr>
    <td style="width:65">String</td></tr>
    <tr>
    <td>石家庄市</td></tr>
    <tr>
    <td>广东南山区</td></tr>
    <tr>
    <td>天津</td></tr>
    <tr>
    <td></td></tr>
    </table>
    </body>
    </html>

    Greetings,
    Yavor Georgiev
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  5. scott
    scott avatar
    67 posts
    Member since:
    Jul 2010

    Posted 21 Sep 2010 Link to this post

    I figured it was me ...

    I can't see the chinese stuff in a CSV file via Excel either, and thats what my customer is complaining about.  When I open the CSV in a vanilla notepad I can see the chinese stuff just fine.   Do you have a workaround for excel as well ?

    Thanks for the super fast response -
    Scott

  6. Answer
    Yavor Georgiev
    Admin
    Yavor Georgiev avatar
    982 posts

    Posted 21 Sep 2010 Link to this post

    Hello scott,

     You need to tell Excel to open the file with Unicode encoding, but that depends on the version of Microsoft Excel your client is using. In Excel 2010 you do this from the From Text option in the Data ribbon tab. I'm not sure about previous versions of Excel, though.

    Greetings,
    Yavor Georgiev
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  7. scott
    scott avatar
    67 posts
    Member since:
    Jul 2010

    Posted 21 Sep 2010 Link to this post

    Thanks for the tip - I'm testing on 2007 so let me hunt that information down.  You guys rock.
  8. Milinda
    Milinda avatar
    2 posts
    Member since:
    Aug 2009

    Posted 20 Apr Link to this post

    Helloo,

    My problem is Swedish characters are not rendering properly when export to PDF.

    Is there any special way of doing this?

    Thanks

    Prasanna

  9. Milinda
    Milinda avatar
    2 posts
    Member since:
    Aug 2009

    Posted 20 Apr Link to this post

    Hi,

    Sweden characters are not rendering after export to PDF.

    Is there any special way of doing this?

    Thanks,

    Milinda

  10. Dinko
    Admin
    Dinko avatar
    677 posts

    Posted 25 Apr Link to this post

    Hello Milinda,

    I have tested the described behavior but wasn't able to reproduce it on my side. I am attaching the sample project which I used to test your scenario. Can you give it a try and let me know what I need to modify so it reproduces this behavior? Can you also elaborate more on what do you mean that is not rendered?

    Regards,
    Dinko
    Progress Telerik
    Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
Back to Top