0

Im trying to replace this superscript with a text but when i tried i get an error of property or indexers 'Microsoft.Office.Interop.Word.Find.Replacement' cannot be assigned to - -it is read only. Sorry im just new in processing word docs.

        wordDoc.ActiveWindow.Selection.Find.Font.Superscript = -1;
        object forward = true;
        object wrap = WdFindWrap.wdFindStop;
        object format = true;
        object matchCase = false;
        object matchWholeWord = false;
        object matchWildcards = false;
        object matchSoundsLike = false;
        object matchAllWordForms = false;


        // Search all numeric superscripts
        while (wordDoc.ActiveWindow.Selection.Find.Execute(ref missing, ref matchCase, ref matchWholeWord, ref matchWildcards, ref matchSoundsLike, ref matchAllWordForms, ref forward, ref wrap, ref format, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing))
        {

            // Look for Numbered References
            if (Regex.IsMatch((wordDoc.ActiveWindow.Selection.Text).Trim(), @"^(\d+|\d+.?\d+?)$"))
            {
                object reference = wordDoc.ActiveWindow.Selection.Range;
                string refNo = Regex.Match((wordDoc.ActiveWindow.Selection.Text).Trim(), @"^(\d+|\d+.?\d+?)$").Value.ToString();
                MessageBox.Show(refNo);
                object replaceAll = Word.WdReplace.wdReplaceOne;

                wordDoc.ActiveWindow.Selection.Find.Text = refNo;
                wordDoc.ActiveWindow.Selection.Find.ClearFormatting();
                wordDoc.ActiveWindow.Selection.Find.Replacement = "Here"; 
4

1 回答 1

0

To find a text which is superscript you will need to add additional settings to your .Find object.

//after this line of your code...
wordDoc.ActiveWindow.Selection.Find.Text = refNo;

//...add the following two:
wordDoc.ActiveWindow.Selection.Find.Superscript = true;
wordDoc.ActiveWindow.Selection.Find.Format = true;

//and the rest of your code unchanged
于 2013-08-08T07:11:08.620 回答