0

プログラムで C#.net、Interop.Word を使用して Word ドキュメントに取り組んでいます。このドキュメントには、「#」で始まり、終わる段落があります。

例:

昔々、森の近くの村に #小さな女の子 が住んでいました。彼女が外出するときはいつでも、少女は赤い乗馬用のマントを着ていたので、村の誰もが彼女を赤ずきんと呼んでいました。

ある朝、赤ずきんちゃんは母親に、久しぶりに会った祖母に会いに行けるかどうか尋ねました。

「それはいい考えだ」と母親は言った。#だから彼らは、赤ずきんちゃんが祖母に持っていくための素敵なバスケットを詰めました.#

すべての間に # テキストを太字にする必要があります

4

3 に答える 3

0
oWord.Selection.ClearFormatting();

 bool done = false;
 while (!done)
 {
    object txt = "#*#";
    object oFalse = false;
     object oTrue = true;
    object wdWrap =      Microsoft.Office.Interop.Word.WdFindWrap.wdFindStop;
 oWord.Selection.Find.Execute(ref txt, ref oFalse, ref oFalse, ref oTrue, ref oFalse, ref oFalse, ref oTrue, ref wdWrap  , ref oFalse, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing);
  if (oWord.Selection.Find.Found == false)
     {
        done = true;
     }
  oWord.Selection.Text = oWord.Selection.Text.Substring(2 - 1, oWord.Selection.Text.Length - 2);
   oWord.Selection.Font.BoldBi = 1;
   oWord.Selection.Bookmarks.Add("TM2011_517_1", ref oMissing);
}
于 2013-09-20T06:03:34.327 に答える
0
Sub Macro1()
'
' Macro1 Macro
'
'
    Selection.HomeKey Unit:=wdStory
    Selection.Find.ClearFormatting
    Dim done As Boolean
    done = False
While Not done
    With Selection.Find
        .Text = "#*#"
        .Replacement.Text = "*"
        .Forward = True
        .Wrap = wdFindStop
        .Format = False
        .MatchCase = False
        .MatchWholeWord = False
        .MatchAllWordForms = False
        .MatchSoundsLike = False
        .MatchWildcards = True
    End With

 Selection.Find.Execute

 If Selection.Find.Found = False Then
    done = True
 Else
    Selection.Text = Mid(Selection.Text, 2, Len(Selection.Text) - 2)
    Selection.Font.Bold = wdToggle
    Selection.EndKey Unit:=wdLine
End If

Wend

End Sub
于 2013-09-18T14:59:54.343 に答える