IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

C++Builder Discussion :

Probleme d'adaptation de recherche/remplacement OleWord


Sujet :

C++Builder

  1. #1
    Rédacteur
    Avatar de blondelle
    Homme Profil pro
    Inscrit en
    Mars 2006
    Messages
    2 738
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations forums :
    Inscription : Mars 2006
    Messages : 2 738
    Points : 3 766
    Points
    3 766
    Par défaut Probleme d'adaptation de recherche/remplacement OleWord
    Je cherche le moyen de rechercher et remplacer une chaine de caractere je reussi a selectionner la chaine mais pas a la remplacer.
    le code:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
     
    vMSWord.OlePropertyGet("Selection").OlePropertyGet("Find").OleFunction("ClearFormatting");
    vMSWord.OlePropertyGet("Selection").OlePropertyGet("Find").OlePropertyGet("Replacement").OleFunction("ClearFormatting");
    vMSWord.OlePropertyGet("Selection").OlePropertyGet("Find").OlePropertySet("Text", "toto"); // texte que l'on veut remplacer
    vMSWord.OlePropertyGet("Selection").OlePropertyGet("Find").OlePropertyGet("Replacement").OlePropertySet("Text", "tata"); // texte qui va remplacer
    vMSWord.OlePropertyGet("Selection").OlePropertyGet("Find").OlePropertySet("Forward",true);
    vMSWord.OlePropertyGet("Selection").OlePropertyGet("Find").OlePropertySet("Wrap", 1);
    vMSWord.OlePropertyGet("Selection").OlePropertyGet("Find").OlePropertySet("Format", false);
    vMSWord.OlePropertyGet("Selection").OlePropertyGet("Find").OlePropertySet("MatchCase", false);
    vMSWord.OlePropertyGet("Selection").OlePropertyGet("Find").OlePropertySet("MatchWholeWord", false);
    vMSWord.OlePropertyGet("Selection").OlePropertyGet("Find").OlePropertySet("MatchWildcards", false);
    vMSWord.OlePropertyGet("Selection").OlePropertyGet("Find").OlePropertySet("MatchSoundsLike", false);
    vMSWord.OlePropertyGet("Selection").OlePropertyGet("Find").OlePropertySet("MatchAllWordForms", false);
    vMSWord.OlePropertyGet("Selection").OlePropertyGet("Find").OleProcedure("Execute");
    La chaine recherchee "toto" est selectionnee.
    Si je modifie la derniere ligne comme suit j'ai une erreur nom inconnu.
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
     
    vMSWord.OlePropertyGet("Selection").OlePropertyGet("Find").OlePropertyGet("Execute").OleProcedure("Replace", 2);
    le code en VB:
    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
     
        Selection.Find.ClearFormatting
        Selection.Find.Replacement.ClearFormatting
        With Selection.Find
            .Text = "toto"
            .Replacement.Text = "tata"
            .Forward = True
            .Wrap = wdFindContinue ' = 1
            .Format = False
            .MatchCase = False
            .MatchWholeWord = False
            .MatchWildcards = False
            .MatchSoundsLike = False
            .MatchAllWordForms = False
        End With
        Selection.Find.Execute Replace:=wdReplaceAll ' = 2
    Ca fait plusieurs jours que j'y suis et je n'y arrive pas, si quelqu'un a une idee? elle sera bien venue.

  2. #2
    Rédacteur
    Avatar de blondelle
    Homme Profil pro
    Inscrit en
    Mars 2006
    Messages
    2 738
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations forums :
    Inscription : Mars 2006
    Messages : 2 738
    Points : 3 766
    Points
    3 766
    Par défaut
    Il n'y a pas eut de reponse mais j'ai quand meme trouve c'est ma fonction qui n'etait pas complete
    la ligne qui ne fonctionnait pas
    vMSWord.OlePropertyGet("Selection").OlePropertyGet("Find").OleFunction("Execute", "toto", false, true, false, false, false, true, false, false, "tata", 2);
    le code complet:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
     
    vMSWord.OlePropertyGet("Selection").OlePropertyGet("Find").OleFunction("ClearFormatting");
    vMSWord.OlePropertyGet("Selection").OlePropertyGet("Find").OlePropertyGet("Replacement").OleFunction("ClearFormatting");
    vMSWord.OlePropertyGet("Selection").OlePropertyGet("Find").OlePropertySet("Text", "toto"); // texte que l'on veut remplacer
    vMSWord.OlePropertyGet("Selection").OlePropertyGet("Find").OlePropertyGet("Replacement").OlePropertySet("Text", "tata"); // texte qui va remplacer
    vMSWord.OlePropertyGet("Selection").OlePropertyGet("Find").OlePropertySet("Forward",true);
    vMSWord.OlePropertyGet("Selection").OlePropertyGet("Find").OlePropertySet("Wrap", 1);
    vMSWord.OlePropertyGet("Selection").OlePropertyGet("Find").OlePropertySet("Format", false);
    vMSWord.OlePropertyGet("Selection").OlePropertyGet("Find").OlePropertySet("MatchCase", false);
    vMSWord.OlePropertyGet("Selection").OlePropertyGet("Find").OlePropertySet("MatchWholeWord", false);
    vMSWord.OlePropertyGet("Selection").OlePropertyGet("Find").OlePropertySet("MatchWildcards", false);
    vMSWord.OlePropertyGet("Selection").OlePropertyGet("Find").OlePropertySet("MatchSoundsLike", false);
    vMSWord.OlePropertyGet("Selection").OlePropertyGet("Find").OlePropertySet("MatchAllWordForms", false);
    vMSWord.OlePropertyGet("Selection").OlePropertyGet("Find").OleFunction("Execute", "toto", false, true, false, false, false, true, false, false, "tata", 2);

  3. #3
    Rédacteur
    Avatar de blondelle
    Homme Profil pro
    Inscrit en
    Mars 2006
    Messages
    2 738
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations forums :
    Inscription : Mars 2006
    Messages : 2 738
    Points : 3 766
    Points
    3 766
    Par défaut
    Apres divers essais on simplifie par
    le code:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
     
    vMSWord.OlePropertyGet("Selection").OlePropertyGet("Find").OleFunction("Execute", "toto", false, true, false, false, false, true, false, false, "tata", 2);
    la fonction fait la recherche et le remplacement donc plus besoin du reste du code

  4. #4
    Rédacteur
    Avatar de blondelle
    Homme Profil pro
    Inscrit en
    Mars 2006
    Messages
    2 738
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations forums :
    Inscription : Mars 2006
    Messages : 2 738
    Points : 3 766
    Points
    3 766
    Par défaut
    Version definitive qui remplace tous les mots recherches par un autre dans le documents de la position du curseur jusque la fin du document
    le code:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
     
    vMSWord.OlePropertyGet("Selection").OlePropertyGet("Find").OleFunction("Execute", "toto", false, true, false, false, false, true, false, false, "tata", 2, false, false, false, false);
    Pour les expressions remplacees par true ou false voir execute, methode dans l'aide VB

  5. #5
    Rédacteur
    Avatar de blondelle
    Homme Profil pro
    Inscrit en
    Mars 2006
    Messages
    2 738
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations forums :
    Inscription : Mars 2006
    Messages : 2 738
    Points : 3 766
    Points
    3 766
    Par défaut
    Comme ca marche je met un petit resolu

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Réponses: 3
    Dernier message: 11/06/2009, 17h49
  2. Réponses: 4
    Dernier message: 25/04/2006, 11h10
  3. Comment faire une recherche/remplacement sous Linux
    Par fabszn dans le forum Shell et commandes GNU
    Réponses: 12
    Dernier message: 07/02/2006, 16h38
  4. Rechercher -> remplacer ?
    Par Joul dans le forum Langage SQL
    Réponses: 2
    Dernier message: 29/09/2005, 02h03
  5. Probleme lors d'une recherche sur les forums
    Par JUSTIN Loïc dans le forum Mode d'emploi & aide aux nouveaux
    Réponses: 8
    Dernier message: 27/07/2005, 12h22

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo