Exécute ou répète l'opération de recherche spécifiée
#include <Word.au3>
_Word_DocFind ( $oDoc [, $sFindText = "" [, $vSearchRange = 0 [, $oFindRange = Default [, $bForward = True [, $bMatchCase = False [, $bMatchWholeWord = False [, $bMatchWildcards = False [, $bMatchSoundsLike = False [, $bMatchAllWordForms = False [, $bFormat = False]]]]]]]]]] )
$oDoc | Objet document Word |
$sFindText | [optionnel] Le texte à rechercher. Utilisez une chaîne vide ("") pour rechercher seulement un format. Vous pouvez rechercher des caractères spéciaux en spécifiant les codes de caractères appropriés. Par exemple,"^p" correspond à une marque de paragraphe et "^t" correspond à un caractère de tabulation (par default = "") |
$vSearchRange | [optionnel] Spécifie la sélection ou la plage dans laquelle effectuer la recherche. Peut être: -1 - Indique la sélection actuelle 0 - Indique le document complet (par défaut) Tout objet plage Word |
$oFindRange |
[optionnel] Spécifie la plage retournée par le dernier appel à _Word_DocFind() . Cela est nécessaire si vous voulez rechercher l'occurrence suivante ou précédente de $sFindText. Si défini à Default, la recherche débute au début de la $vSearchRange (valeur par défaut) |
$bForward | [optionnel] True pour rechercher vers l'avant (vers la fin du document) (valeur par défaut = True) |
$bMatchCase | [optionnel] Si True, la recherche est insensible à la casse (par défaut = False) |
$bMatchWholeWord | [optionnel] Si True, recherche seulement des mots entiers (par défaut = False) |
$bMatchWildcards | [optionnel] Si True, le texte recherché contient des jokers (par défaut = False ) |
$bMatchSoundsLike | [optionnel] Si True, recherche des mots qui sonnent comme le texte de la recherche (par défaut = False) |
$bMatchAllWordForms | [optionnel] Si True, recherche toutes les formes de la texte à recherche (par exemple, "sit" trouve aussi "sitting" et "sat") (par défaut = False) |
$bFormat | [optionnel] True pour que la recherche trouve le format en plus ou à la place du texte recherché (par défaut = False) |
Succès: | Retourne un objet plage pour le texte trouvé. |
Échec: | Retourne 0 et définit @error <> 0. |
@error: | 1 - $oDoc n'est pas un objet 2 - $vSearchRange n'est pas un objet 3 - $oFindRange n'est pas un objet 4 - $sFindText n'a pas été trouvée |
#include <MsgBoxConstants.au3> #include <Word.au3> ; Crée un objet application Local $oWord = _Word_Create() If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Word UDF: _Word_DocFind Example", _ "Error creating a new Word application object." & @CRLF & "@error = " & @error & ", @extended = " & @extended) ; Ouvre un document test en lecture seule Local $oDoc = _Word_DocOpen($oWord, @ScriptDir & "\Extras\Test.doc", Default, Default, True) If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Word UDF: _Word_DocFind Example", _ "Error opening '.\Extras\Test.doc'." & @CRLF & "@error = " & @error & ", @extended = " & @extended) ; ; Cherche le dernier texte "test document" dans le document et le marque en gras. ; Local $oRangeFound #forceref $oRangeFound $oRangeFound = _Word_DocFind($oDoc, "test document", 0, Default, False) If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Word UDF: _Word_DocFind Example", _ "Error locating the specified text in the document." & @CRLF & "@error = " & @error & ", @extended = " & @extended) $oRangeFound.Bold = True MsgBox($MB_SYSTEMMODAL, "Word UDF: _Word_DocFind Example", _ "Last occurrence of string 'test document' in the document marked as bold.")
#include <MsgBoxConstants.au3> #include <Word.au3> ; Crée un objet application Local $oWord = _Word_Create() If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Word UDF: _Word_DocFind Example", _ "Error creating a new Word application object." & @CRLF & "@error = " & @error & ", @extended = " & @extended) ; Ouvre un document test en lecture seule Local $oDoc = _Word_DocOpen($oWord, @ScriptDir & "\Extras\Test.doc", Default, Default, True) If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Word UDF: _Word_DocFind Example", _ "Error opening '.\Extras\Test.doc'." & @CRLF & "@error = " & @error & ", @extended = " & @extended) ; ; Souligne le texte "line" des lignes 2-4. ; Local $oRangeFound, $oSearchRange $oSearchRange = _Word_DocRangeSet($oDoc, -1, $wdParagraph, 1, $wdParagraph, 3) $oRangeFound = _Word_DocFind($oDoc, "line", $oSearchRange) If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Word UDF: _Word_DocFind Example", _ "Error locating the specified text in the document." & @CRLF & "@error = " & @error & ", @extended = " & @extended) $oRangeFound.Underline = True While 1 $oRangeFound = _Word_DocFind($oDoc, "line", $oSearchRange, $oRangeFound) If @error Then ExitLoop $oRangeFound.Underline = True WEnd MsgBox($MB_SYSTEMMODAL, "Word UDF: _Word_DocFind Example", _ "All occurrences of string 'line' in paragraphs 2-4 marked as underlined.")
#include <MsgBoxConstants.au3> #include <Word.au3> ; Crée un objet application Local $oWord = _Word_Create() If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Word UDF: _Word_DocFind Example", _ "Error creating a new Word application object." & @CRLF & "@error = " & @error & ", @extended = " & @extended) ; Ouvre un document test en lecture seule Local $oDoc = _Word_DocOpen($oWord, @ScriptDir & "\Extras\Test.doc", Default, Default, True) If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Word UDF: _Word_DocFind Example", _ "Error opening '.\Extras\Test.doc'." & @CRLF & "@error = " & @error & ", @extended = " & @extended) ; ; Cherche le texte "line" dans les lignes 2-4 et marque les nombres suivants en gras. ; Si le nombre est "3", insère le texte avant le texte "line". ; Local $oRangeFound, $oSearchRange, $oRangeText $oSearchRange = _Word_DocRangeSet($oDoc, -1, $wdParagraph, 1, $wdParagraph, 3) $oRangeFound = _Word_DocFind($oDoc, "line", $oSearchRange) If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Word UDF: _Word_DocFind Example", _ "Error locating the specified text in the document." & @CRLF & "@error = " & @error & ", @extended = " & @extended) ; Marque le numéro de ligne en gras. Crée une nouvelle plage déplacée d'un mot vers la droite $oRangeText = _Word_DocRangeSet($oDoc, $oRangeFound, Default, 1, Default, 1) $oRangeText.Bold = True While 1 $oRangeFound = _Word_DocFind($oDoc, "line", $oSearchRange, $oRangeFound) If @error Then ExitLoop ; Marque le numéro de ligne en gras. Crée une nouvelle plage (dupliquée pour ne pas altérer le résultat de la recherche) et la déplace d'un mot vers la droite $oRangeText = $oRangeFound.Duplicate $oRangeText = _Word_DocRangeSet($oDoc, $oRangeText, Default, 1, Default, 1) $oRangeText.Bold = True ; Insère le texte si linenumber = 3 If StringStripWS($oRangeText.Text, 8) = "3" Then $oRangeFound.InsertBefore("(maybe) ") WEnd MsgBox($MB_SYSTEMMODAL, "Word UDF: _Word_DocFind Example", _ "All line numbers in paragraphs 2-4 marked as bold." & @CRLF & "Text inserted before 'line 3'.")
#include <MsgBoxConstants.au3> #include <Word.au3> ; Crée un objet application Local $oWord = _Word_Create() If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Word UDF: _Word_DocFind Example", _ "Error creating a new Word application object." & @CRLF & "@error = " & @error & ", @extended = " & @extended) ; Ouvre un document test en lecture seule Local $oDoc = _Word_DocOpen($oWord, @ScriptDir & "\Extras\Test.doc", Default, Default, True) If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Word UDF: _Word_DocFind Example", _ "Error opening '.\Extras\Test.doc'." & @CRLF & "@error = " & @error & ", @extended = " & @extended) ; ; Remplace le caractère de contrôle 'paragraph' par paragraph + text + paragraph. ; Change seulement la première occurrence. ; Local $oRangeFound $oRangeFound = _Word_DocFind($oDoc, "^p") If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Word UDF: _Word_DocFind Example", _ "Error locating paragraph control character in the document." & @CRLF & "@error = " & @error & ", @extended = " & @extended) $oRangeFound.InsertAfter("[New Line] ") If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Word UDF: _Word_DocFind Example", _ "Error inserting text after the paragraph control character in the document." & @CRLF & "@error = " & @error & _ ", @extended = " & @extended) MsgBox($MB_SYSTEMMODAL, "Word UDF: _Word_DocFind Example", "Paragraph control character successfully replaced." & @CRLF & _ "Text inserted in paragraph 2.")