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

Langage Delphi Discussion :

Word ole et demande de remplacement de chaine


Sujet :

Langage Delphi

  1. #1
    Membre régulier
    Inscrit en
    Février 2003
    Messages
    138
    Détails du profil
    Informations forums :
    Inscription : Février 2003
    Messages : 138
    Points : 89
    Points
    89
    Par défaut Word ole et demande de remplacement de chaine
    Voila, j'utilise le TWordAppication et le TWordDocument pour travailler sur un document Word et remplacer des chaines par d'autres.

    J'utilise la bibliotheque Word2000 avec un delphi 7.1

    Voici le code utilisé

    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
     
     
            WordDocument.ConnectTo(WordApplication.Documents.Item(ItemIndex));
     
        Param1 := 'tata';
        Param2 := False;
        Param3 := True;
        Param4 := wdFindStop;
        Param5 := wdCharacter;
        Param6 := wdReplaceAll;
        Param7 := 'toto';
     
        WordDocument.Range.Find.Execute(Param1, Param2,
          Param2, Param2,
          Param2, Param2,
          Param3, Param4, EmptyParam,
          Param7, Param6,
          EmptyParam,EmptyParam,EmptyParam,EmptyParam);
    Or il me retourne : Le relai a recu des données incorrectes.

    Là je ne vois pas ce qui debloque donc si vous avez une piste, elle est la biencnue.

    Merci

  2. #2
    Rédacteur


    Profil pro
    Inscrit en
    Janvier 2003
    Messages
    7 171
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Janvier 2003
    Messages : 7 171
    Points : 15 060
    Points
    15 060
    Billets dans le blog
    1
    Par défaut
    Salut,
    essaie qq chose comme ceci :
    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
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
     
    procedure TForm1.Replace(ChaineAvant,ChaineApres:String);
    var FindText,
        MatchCase,
        MatchWholeWord,
        MatchWildcards,
        MatchSoundsLike,
        MatchAllWordForms,
        Forward,
        Wrap,
        Format,
        ReplaceWith,
        Replace,
        MatchKashida,
        MatchDiacritics,
        MatchAlefHamza,
        MatchControl: OleVariant;
        MaZone: Range;
     
    Begin
       //Cherche et remplace ChaineAvant par ChaineApres dans tout le document
     
      MaZone:=WordApplication1.ActiveDocument.Content;
      FindText:=ChaineAvant;
      MatchCase:=False;
      MatchWholeWord:=True;
      MatchWildcards:=False;
      MatchSoundsLike:=False;
      MatchAllWordForms:=False;
      Forward:=True;
      Wrap:=wdFindStop;
      Format:=False;
      ReplaceWith:=ChaineApres;
      Replace:=wdReplaceAll;
      MatchKashida:=False;
      MatchDiacritics:=False;
      MatchAlefHamza:=False;
      MatchControl:=False;
     
      MaZone.Find.Execute(FindText,MatchCase,MatchWholeWord,MatchWildcards,
                          MatchSoundsLike,MatchAllWordForms,Forward,Wrap,
                          Format,ReplaceWith,Replace,MatchKashida,MatchDiacritics,
                          MatchAlefHamza,MatchControl);
     
    end;

  3. #3
    Membre averti

    Homme Profil pro
    Inscrit en
    Mars 2002
    Messages
    0
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations forums :
    Inscription : Mars 2002
    Messages : 0
    Points : 314
    Points
    314
    Par défaut
    Bonjour,

    J'ai le meme problème, j'ai essaye la solution de Laurent et elle provoque la meme erreur, j'ai essaye d'utiliser la fonction ExecuteOld (verion Word 97) mais avec celle ci il ne me trouve rien !

    Cordialement

  4. #4
    Rédacteur


    Profil pro
    Inscrit en
    Janvier 2003
    Messages
    7 171
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Janvier 2003
    Messages : 7 171
    Points : 15 060
    Points
    15 060
    Billets dans le blog
    1
    Par défaut
    Salut,
    merci de préciser les versions des produits utilisés car trés peu d'entre nous sont diplômés des arts divinatoires.

  5. #5
    Membre averti

    Homme Profil pro
    Inscrit en
    Mars 2002
    Messages
    0
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations forums :
    Inscription : Mars 2002
    Messages : 0
    Points : 314
    Points
    314
    Par défaut
    J'utilise Delphi 5 Pro avec Windows XP et Office 2000.
    J'utilise les composants d'office 2000 ou XP et non ceux de 97 (word2000.pas)

    Cordialement.

  6. #6
    Membre averti

    Homme Profil pro
    Inscrit en
    Mars 2002
    Messages
    0
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations forums :
    Inscription : Mars 2002
    Messages : 0
    Points : 314
    Points
    314
    Par défaut [Resolu] Word ole et demande de remplacement de chaine
    J'ai trouvé, c'est un bug de Microsoft !!!

    http://support.microsoft.com/default.aspx/kb/292744

    Le problème : j'avais définit ma variable MaZone en Range, j'ai du la passer en OLEVariant, et ca fonctionne !

    Ancien code qui bugait :
    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
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
     
    var MaZone : Range;
          FindText,
          MatchCase,
          MatchWholeWord,
          MatchWildcards,
          MatchSoundsLike,
          MatchAllWordForms,
          Forward,
          Wrap,
          Format,
          ReplaceWith,
          Replace : OleVariant;
     
    ...
     
          MaZone:=DocWord.Content;
          FindText := TexteARechercher.Strings[j];
          MatchCase := False;
          MatchWholeWord := False;
          MatchWildcards := False;
          MatchSoundsLike := False;
          MatchAllWordForms := False;
          Forward := True;
          Wrap := wdFindStop;
          Format := False;
          ReplaceWith := '';
          Replace := wdReplaceNone;
     
          MaZone.Find.Execute(FindText, MatchCase, MatchWholeWord,
                                         MatchWildcards, MatchSoundsLike,
                                         MatchAllWordForms, Forward,
                                         Wrap, Format, ReplaceWith, Replace,
                                         EmptyParam, EmptyParam, EmptyParam,
                                         EmptyParam);
    Code pour eviter le bug

    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
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
     
    var MaZone,
          FindText,
          MatchCase,
          MatchWholeWord,
          MatchWildcards,
          MatchSoundsLike,
          MatchAllWordForms,
          Forward,
          Wrap,
          Format,
          ReplaceWith,
          Replace : OleVariant;
     
    ...
     
          MaZone:=DocWord.Content;
          FindText := TexteARechercher.Strings[j];
          MatchCase := False;
          MatchWholeWord := False;
          MatchWildcards := False;
          MatchSoundsLike := False;
          MatchAllWordForms := False;
          Forward := True;
          Wrap := wdFindStop;
          Format := False;
          ReplaceWith := '';
          Replace := wdReplaceNone;
     
          MaZone.Find.Execute(FindText, MatchCase, MatchWholeWord,
                                         MatchWildcards, MatchSoundsLike,
                                         MatchAllWordForms, Forward,
                                         Wrap, Format, ReplaceWith, Replace,
                                         EmptyParam, EmptyParam, EmptyParam,
                                         EmptyParam);

  7. #7
    Rédacteur


    Profil pro
    Inscrit en
    Janvier 2003
    Messages
    7 171
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Janvier 2003
    Messages : 7 171
    Points : 15 060
    Points
    15 060
    Billets dans le blog
    1
    Par défaut
    Merci.
    Nous allons ajouter cette info dans la FAQ Delphi.

Discussions similaires

  1. Réponses: 0
    Dernier message: 26/02/2015, 16h01
  2. [Système] Remplacer une chaine par un lien hypertexte
    Par Bisûnûrs dans le forum Langage
    Réponses: 10
    Dernier message: 06/06/2007, 09h34
  3. Réponses: 7
    Dernier message: 27/09/2005, 11h54
  4. Réponses: 9
    Dernier message: 31/05/2005, 14h34
  5. Réponses: 4
    Dernier message: 16/04/2004, 16h31

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