یا اجرای دستورات بالا پیغام زیر ظاهر میشه!
The server threw an exeption
من که سر در نیاوردم
اینم source مربوطه! delphi man عزیز شما چیزی سر در میارید؟
unit Unit2;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, OleServer, Comobj, ExtCtrls, Word2000 ;
type
TForm1 = class(TForm)
Button1: TButton;
Edit1: TEdit;
Edit2: TEdit;
Edit3: TEdit;
Edit4: TEdit;
Edit5: TEdit;
ComboBox1: TComboBox;
RadioGroup1: TRadioGroup;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
Var TmpOle1 : Variant;
FileName : String;
Word : OLEVariant;
begin
FileName := 'D:\1.htm';
TmpOle1 := wdFormatHTML;
try
word := CreateOleObject('Word.Application');
except
ShowMessage('Cannot start Word !');
Exit;
end;
// Show Word
word.Visible := True;
// Add a new Document
word.Documents.Add;
if word.ActiveWindow.View.SplitSpecial <> 0 then
word.ActiveWindow.Panes[2].Close;
if (word.ActiveWindow.ActivePane.View.type = 1) or
(word.ActiveWindow.ActivePane.View.type = 2) or
(word.ActiveWindow.ActivePane.View.type = 5) then
word.ActiveWindow.ActivePane.View.type := 3;
word.ActiveWindow.ActivePane.View.SeekView := 9;
word.Selection.Font.Name := 'Times New Roman';
word.Selection.Font.Size := 12;
word.Selection.Font.Bold := True;
word.Selection.ParagraphFormat.Alignment := 1;
word.Selection.TypeText(Text := 'Kohlenhandel Brikett-GmbH & Co.-KG. - Holzweg 16 -54633 Steinhausen');
if word.Selection.HeaderFooter.IsHeader = True then
word.ActiveWindow.ActivePane.View.SeekView := 10
else
word.ActiveWindow.ActivePane.View.SeekView := 9;
word.Selection.TypeText(Text := 'Bankverbindung: Stadtsparkasse Steinhausen BLZ 123456789KtoNr. 782972393243');
word.ActiveWindow.ActivePane.View.SeekView := 0;
word.Selection.TypeText(Text := Edit2.Text + ' ' + edit1.Text);
word.Selection.TypeParagraph;
word.Selection.TypeText(Text := edit3.Text);
word.Selection.TypeParagraph;
word.Selection.TypeParagraph;
word.Selection.Font.Name := 'Times New Roman';
word.Selection.font.Size := 12;
word.Selection.font.Bold := True;
word.Selection.TypeText(Text := edit4.Text + ' ' + edit5.Text);
word.Selection.TypeParagraph;
word.Selection.TypeParagraph;
word.Selection.TypeParagraph;
word.Selection.TypeParagraph;
word.Selection.Font.Name := 'Arial';
word.Selection.Font.Size := 14;
word.Selection.Font.Bold := True;
word.Selection.TypeText(Text := Combobox1.Text);
word.Selection.TypeParagraph;
word.Selection.TypeParagraph;
word.Selection.TypeParagraph;
word.Selection.Font.Name := 'Times New Roman';
word.Selection.Font.Size := 12;
word.Selection.Font.Bold := True;
if radiogroup1.ItemIndex = 0 then
word.Selection.TypeText(Text := 'Sehr geehrter Herr ' + edit1.Text)
else
word.Selection.TypeText(Text := 'Sehr geehrte Frau ' + edit1.Text);
Word.ActiveDocument.SaveAs(FileName, TmpOle1, EmptyParam, EmptyParam, EmptyParam,
EmptyParam, EmptyParam, EmptyParam, EmptyParam, EmptyParam, EmptyParam);
end;
end.