bonjour

Quelqu'un aurait-il un bout de code pour lire le texte d'un document word depuis Delphi ?

Voici mon 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
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
46
47
48
49
50
51
52
 
// les composants de la fiche
    WordDocument: TWordDocument;
    WordApplication: TWordApplication;
 
// la procédure
 
procedure GetWordText(fileWord : string) : string;
var
   Template : OleVariant;
   fileName : OleVariant;
   OvYes    : OleVariant;
   ovNo     : OleVariant;
   pass     : OleVariant;
   format   : OleVariant;
   itIndex  : OleVariant;
   SaveChanges,
   OriginalFormat,
   RouteDocument: OleVariant;
begin
  GetWordText := '';
  try
    Template := EmptyParam;
    try
      Wordapplication.Connect;
    except
      MessageDlg('MS Word n''a pas été trouvé.', mtError, [mbOk], 0);
      Abort;
    end;
    Template := EmptyParam;
    fileName := fileWord;
    Ovyes := 0;
    OvNo := 1;
    pass := UnAssigned;
    format := wdOpenFormatAuto;
    WordApplication.Documents.open(FileName, ovNo, OvYes, OvNo, pass, pass, ovNo, ovNo, ovNo, format);
    itIndex := 1;
    WordDocument.ConnectTo(WordApplication.Documents.Item(itIndex));
    GetWordText := WordDocument.Range.get_text;
    SaveChanges := WdDoNotSaveChanges;
    OriginalFormat := UnAssigned;
    RouteDocument := UnAssigned;
    WordApplication.Quit(SaveChanges, OriginalFormat, RouteDocument);
    WordApplication.Disconnect;
  except
    on E: Exception do
    begin
      ShowMessage(E.Message);
      WordApplication.Disconnect;
    end;
  end;
end;
Ceci plante à l'ouverture du doc ... message : "Le type ne correspond pas".

PS : la syntaxe de cette méthode est :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
    function  Open(var FileName: OleVariant; var ConfirmConversions: OleVariant; 
                   var ReadOnly: OleVariant; var AddToRecentFiles: OleVariant; 
                   var PasswordDocument: OleVariant; var PasswordTemplate: OleVariant; 
                   var Revert: OleVariant; var WritePasswordDocument: OleVariant; 
                   var WritePasswordTemplate: OleVariant; var Format: OleVariant): WordDocument; safecall;
Toute aide sera bienvenue !

Merci