none
Word text wrong text!? RRS feed

  • Question

  • Hi!

    I have a wrong text in a word document like this:

    Ě, Ğ, Ă, Č, Ĵ, Ķ, Ĺ, Ļ, Ň, Ď, Ŏ, Ŗ, ǟ, ǧ, ḱ, ả, Ả, Ầ,

    The right text was:

    Ě, Ğ, Ă, Č, Ĵ, Ķ, Ĺ, Ļ, Ň, Ď, Ŏ, Ŗ, ǟ, ǧ, ḱ, ả, Ả, Ầ,

    what is wrong? (Text Font???)

    Can anyone help me?

    Best Regards

    Bernd

    Thursday, June 11, 2015 11:52 AM

Answers

  • Hi Bernd

    Try simply assigning the ConvertText string to document.Content.Text, without any conversion to any particular encoding...


    Cindy Meister, VSTO/Word MVP, my blog

    • Marked as answer by Bernd Riemke Sunday, June 14, 2015 12:19 PM
    Friday, June 12, 2015 2:44 PM
    Moderator

All replies

  • Hallo Bernd

    Is this something you're doing with code (topic of this forum)?

    In any case, we'd need more information.

    1. Which version of Word?

    2. What action did you perform before seeing that the "wrong" text is in the document?

    3. What can you tell us about the history of this document?


    Cindy Meister, VSTO/Word MVP, my blog

    Thursday, June 11, 2015 4:09 PM
    Moderator
  • Here is the c# code and the Problem:

                // UTF-8
                ConvertText = "Ě, Ğ, Ă, Č, Ĵ, Ķ, Ĺ, Ļ, Ň, Ď, Ŏ, Ŗ, ǟ, ǧ, ḱ, ả, Ả, Ầ,";
    
                // UTF-8 to Windows-1252  --> OK for database
                textA = ConvertText;
                byte[] bytes = Encoding.UTF8.GetBytes(textA);
                Encoding enc = Encoding.GetEncoding("Windows-1252");
                textA = enc.GetString(bytes);
    
                // UTF-8 to ????  --> MS-WORD
                textB = ConvertText;
                byte[] bytesW = Encoding.UTF8.GetBytes(textB);
                Encoding encW = Encoding.GetEncoding("Windows-1252"); // wich CODE for MS-WORD !?!?!?!
                textB = encW.GetString(bytes);
    
    
    
                //Create an instance for word app
                Microsoft.Office.Interop.Word.Application winword = new Microsoft.Office.Interop.Word.Application();
    
                //Set status for word application is to be visible or not.
                winword.Visible = true;
    
                //Create a missing variable for missing value
                object missing = System.Reflection.Missing.Value;
    
                //Create a new document
                Microsoft.Office.Interop.Word.Document document = winword.Documents.Add(ref missing, ref missing, ref missing, ref missing);
    
                //adding text to document
                document.Content.SetRange(0, 0);
                document.Content.Text = textB + Environment.NewLine;
    
                object filename = @"c:\temp1.docx";
                document.SaveAs2(ref filename);
                document.Close(ref missing, ref missing, ref missing);
                document = null;
                winword.Quit(ref missing, ref missing, ref missing);
                winword = null;
    

    The wordfile looks like:

    But what i Need in Wod is: "Ě, Ğ, Ă, Č, Ĵ, Ķ, Ĺ, Ļ, Ň, Ď, Ŏ, Ŗ, ǟ, ǧ, ḱ, ả, Ả, Ầ,"

    What Code Type is the right that Word is typing the right letters???

    Best Regards

    Bernd

    Thursday, June 11, 2015 9:00 PM
  • Hi Bernd

    Try simply assigning the ConvertText string to document.Content.Text, without any conversion to any particular encoding...


    Cindy Meister, VSTO/Word MVP, my blog

    • Marked as answer by Bernd Riemke Sunday, June 14, 2015 12:19 PM
    Friday, June 12, 2015 2:44 PM
    Moderator
  • Many Thanks !!!

    Best Regards

    Bernd

    Sunday, June 14, 2015 12:19 PM