locked
When I try to get datagrid to excel I get Turkish character problem please help me quickly? RRS feed

  • Question

  •        
         System.Windows.Controls.DataGrid dg = ToplantıDg1;
                dg.SelectAllCells();
                dg.ClipboardCopyMode = DataGridClipboardCopyMode.IncludeHeader;
                ApplicationCommands.Copy.Execute(null, dg);
                dg.UnselectAllCells();
                String Clipboardresult = Convert.ToString((System.Windows.Clipboard.GetData(System.Windows.DataFormats.CommaSeparatedValue)));
                StreamWriter swObj = new StreamWriter("exportToExcel.csv");
                swObj.WriteLine(Clipboardresult);
                swObj.Close();
                Process.Start("exportToExcel.csv");

    How Can I solve my problem about turkish characters I mean when datagrid export to Excell all Turkish characters can't read why it is happened




    • Edited by aaydinalp Monday, December 18, 2017 2:25 PM
    Monday, December 18, 2017 1:52 PM

All replies

  • You could try with another kind of StreamWriter constructor. There exists another one that allows to add an encoding parameter 'StreamWriter(Stream, Boolean, Encoding)'. I'm not so sure about the right encoding. I hope this StackOverflow proposal works out for you:
    ...
    String Clipboardresult = Convert.ToString((System.Windows.Clipboard.GetData(System.Windows.DataFormats.CommaSeparatedValue)));
    Encoding iso = Encoding.GetEncoding("ISO-8859-1");
    StreamWriter swObj = new StreamWriter("exportToExcel.csv", true, iso);
    swObj.WriteLine(Clipboardresult);
    swObj.Close();
    Process.Start("exportToExcel.csv");
    
    
    wizend
    Monday, December 18, 2017 5:59 PM
  • Hi,

    You can try Unicode encoding .

    StreamWriter swObj = new StreamWriter(@"exportToExcel.csv",true,Encoding.Unicode)

    Sincerely,

    Bob



    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Tuesday, December 19, 2017 1:29 AM
  • thanks for answer but can you tell me answer how can I save file without open Excel driectly with the same your solution it is only open directly Excell but before open file I need save file too
    Tuesday, December 19, 2017 3:39 AM
  • Hi,

    You use Process.Start to open this .cvs file.

    If don't want to open excel, just remove this line.

    Process.Start("exportToExcel.csv");

    Sincerely,

    Bob


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.


    • Edited by Bob Ding Friday, December 22, 2017 10:07 AM
    Tuesday, December 19, 2017 6:43 AM