| 12
 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; | 
Partager