(c#) Create Microsoft Word Add-In (VSTO) on formatted MS Word documents... RRS feed

  • Question

  • Hello everyone. I'll try to explain:
    I'm trying to make one Microsoft Word Add-In (VSTO) on formatted MS Word documents (Word 2016 and Word 2019). (This Add-In is used to switch between Cyrillic and Latin text, and reverse).

    This simple code works fine, but only the basic function (switch between Cyrillic and Latin text, and reverse), but with breaking source text formatting: (NET Framework 4.0)

    private void Button1_Click(object sender, RibbonControlEventArgs e)
                Word.Selection currentSelection = Globals.ThisAddIn.Application.Selection;
                if (currentSelection.Range.Text != null)
                    string sText = currentSelection.Range.Text;
                    currentSelection.Range.Text = Konvert.LatintoCyrillic&CyrillictoLatin(sText.ToString());

    This Add-in using LatintoCyrillic&CyrillictoLatin.cs , and it works fine.

    What is the problem?

    After executing the code it happens, breaking source text formatting...
    I would like this code without breaking source text formatting.

    Before executing the code (Latin):

    After executing the code (Cyrillic):

    I would like this result after executing the codewithout breaking source text formatting (Cyrillic):

    I hope you understood me. I ask for your help if possible. Thank you.


    To get a better understanding:
    In the first case, when I select part by part of the text, everything works as it should:

    In the second case, when I select the whole text, the result is not good:

    I want when selecting the whole text, after executing the code, the result should be as if I was selecting part by part.

    • Edited by denysH Tuesday, January 7, 2020 11:52 AM
    Tuesday, January 7, 2020 9:44 AM

All replies