different format into one single line Interop.word

前端 未结 6 908
深忆病人
深忆病人 2020-12-11 04:45

I\'ve been trying to figure out how to insert 2 different formats into the same paragraph using interop.word in c# like this:

hello planet earth her

6条回答
  •  心在旅途
    2020-12-11 05:18

    The following code seemed to work the best for me when formatting a particular selection within a paragraph. Using Word's built in "find" function to make a selection, then formatting only the selected text. This approach would only work well if the text to select is a unique string within the selection. But for most situations I have run across, this seems to work.

            oWord.Selection.Find.Text = Variable_Containing_Text_to_Select; // sets the variable for find and select
            oWord.Selection.Find.Execute(); // Executes find and select
            oWord.Selection.Font.Bold = 1; // Modifies selection
            oWord.Selection.Collapse();  // Clears selection
    

    Hope this helps someone!

提交回复
热议问题