Einzelnen Beitrag anzeigen

Benutzerbild von user0815
user0815

Registriert seit: 5. Okt 2007
331 Beiträge
 
Delphi XE2 Professional
 
#6

AW: Word 2010 Vorlage.dot ausfüllen

  Alt 8. Feb 2012, 13:13
Danke @einbeliebigername hat mir alles sehr geholfen, jetzt läuft es.

Delphi-Quellcode:
procedure TFormMain.PrintVorlage(Ausdrucken : Boolean);
var
  WordApp : TWordApplication;
  Dokument : TWordDocument;
  FileName, SaveChanges, Background, Copies : OleVariant;
begin
  FileName := Anwendungsverzeichnis + 'Vorlage\XYZ.dot';
  SaveChanges := wdDoNotSaveChanges;
  Background := false;

  try
    Copies := StrToInt(EditPrinterCopy.Text);
  except
    Copies := 1;
  end;

  try
    WordApp := TWordApplication.Create(Self);
    Dokument := TWordDocument.Create(Self);

    WordApp.Connect;
    WordApp.Visible := not Ausdrucken;

    Dokument.ConnectTo(WordApp.Documents.Add(FileName, EmptyParam, EmptyParam, EmptyParam));

    with Datenmodul.UniQueryDataGrid do
    begin
      Dokument.FormFields.Item('Nummer').Result := FieldByName('Nummer').AsString;
      Dokument.FormFields.Item('Jahreszahl').Result := FieldByName('Jahreszahl').AsString;
      // ...
    end;

    if Ausdrucken then
    begin
      if not CheckBoxStandarddrucker.Checked
        then WordApp.ActivePrinter := ComboBoxPrinter.Text;

      Dokument.PrintOut(Background, EmptyParam, EmptyParam, EmptyParam, EmptyParam, EmptyParam, EmptyParam,
                        Copies, EmptyParam, EmptyParam);
      Dokument.Close(SaveChanges, EmptyParam, EmptyParam);
      WordApp.Quit;
    end;

  finally
    WordApp.Disconnect;

    Dokument.Free;
    WordApp.Free;
  end;
end;
  Mit Zitat antworten Zitat