Bonjour,
Je voudrais trouver les mots en gras dans un document Word et les remplacer par d'autre mots. Est ce possible de repérer les mots en gras ou italique ? Comment faire ?
Cordialement
Bonjour,
Je voudrais trouver les mots en gras dans un document Word et les remplacer par d'autre mots. Est ce possible de repérer les mots en gras ou italique ? Comment faire ?
Cordialement
Salut,
voici qq infos :
Traitement des paragraphes.
Décompose le paragraphe
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 var MesParagraphs: Paragraphs; I,J,CountParagraphs:integer; MonParagraph: Paragraph; MonTexte : String; begin // Recherche tous les paragraphes MesParagraphs:=WordDocument1.Paragraphs; CountParagraphs:=MesParagraphs.Count; For I:=1 to CountParagraphs do begin MonTexte:=''; // récupére un paragraphe // et recherche les objets le constituant MonParagraph:=MesParagraphs.Item(I); MonTexte:=Traite_MotsParagraph(MonParagraph.Range.Words) ...
Teste chaque mot
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8 Function TForm1.Traite_MotsParagraph( MesMots : Words):String; var J :integer; Begin Result:=''; For J:=1 to MesMots.Count do Result:=Result+GetWordFormat(MesMots.Item(J)); end;
Supprime qq caractéres de contrôle, tous ne sont pas gérés ici ...
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 Function TForm1.GetWordFormat(MonMot : Range):String; var WTexte : WideString; begin Result:=''; WTexte:= CleanString(MonMot.Text); if WTexte<>'' then begin If MonMot.Bold=-1 then .. If MonMot.Italic=-1 then ... If MonMot.Underline<>wdUnderlineNone then ... end Result:=WTexte; end;
Pour récupérer la position
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11 Function TForm1.CleanString(lTexte:WideString):WideString; begin // Supprime les Tabulations lTexte:= StringReplace(lTexte,#$D, '', [rfReplaceAll]); // Supprime les coupures de ligne lTexte:= StringReplace(lTexte, #$7, '', [rfReplaceAll]); // Supprime les saut de pages Result:= StringReplace(lTexte, #$C, '', [rfReplaceAll]); end;
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 var MyRange : Olevariant; StartMonLien,EndMonLien: Integer; Begin ... StartMonLien:=MonMot.Range.Start; EndMonLien:=MonMot.Range.End_; ... // Supprime le mot, ou 'une étendue'. MyRange:=MonMot.Range; MyRange.Start:=Start; MyRange.End:=End_; MyRange.Delete; ... // Insére le texte à la position désiré. MyRange.Start:=Start; MyRange.End:=End_; MyRange.InsertBefore(MonTexte);
Tutoriels Delphi Win32/Delphi .NET/Oracle/PowerShell - FAQ Delphi - FAQ Delphi .NET
Beatus, qui prodest, quibus potest.
Partager