R
redleilei
Unregistered / Unconfirmed
GUEST, unregistred user!
刚才查看了全文检索,都是胡扯的,没有一个有源码或者能用的。
要求很简单,C:/Program Files/Borland/Delphi7/Demos/ActiveX/OleAuto/Word8这个例子已经实现了大部分我需要的功能。现在唯一要做的就是向WORD输出指定字体以及尺寸的文本。
例如:
第一段输出宋体,四号字,"标题" (居中)
第二段输出黑体,小五,“这是内容”(局左)
第三段输出黑体,五号,“时间“(居右)
谁能给出完整源码,非常感谢。 另外对Excel的操作,各位附上Demo的,发到我邮箱,redleilei@sina.com。另外再送上150分。
下面是Delphi自带Demo的源码,我打算用这个就行了,大侠最好在这个基础上改。
-------
procedure TForm1.LaunchButtonClick(Sender: TObject);
begin
if not Assigned(WordObject) then begin
WordObject := TWordObject.Create;
with WordObject do begin
Caption := 'Delphi is RAD!';
Visible := True;
OnQuit := AppQuit;
OnDocumentChange := AppDocumentChange;
OnNewDocument := DocNew;
OnOpenDocument := DocOpen;
OnCloseDocument := DocClose;
end;
LaunchButton.Enabled := False;
CloseButton.Enabled := True;
NewDocButton.Enabled := True;
end;
end;
procedure TForm1.CloseButtonClick(Sender: TObject);
begin
if Assigned(WordObject) then begin
LaunchButton.Enabled := True;
CloseButton.Enabled := False;
NewDocButton.Enabled := False;
TypeTextButton.Enabled := False;
WordObject.Free;
WordObject := nil;
end;
end;
procedure TForm1.AppDocumentChange(Sender: TObject);
begin
Memo1.Lines.Add('Document changed');
TypeTextButton.Enabled := WordObject.Application.Documents.Count > 0;
end;
procedure TForm1.AppQuit(Sender: TObject);
begin
Memo1.Lines.Add('Quitting Word');
WordObject.Free;
WordObject := nil;
LaunchButton.Enabled := True;
CloseButton.Enabled := False;
NewDocButton.Enabled := False;
TypeTextButton.Enabled := False;
end;
procedure TForm1.DocNew(Sender: TObject);
begin
Memo1.Lines.Add('New document');
end;
procedure TForm1.DocOpen(Sender: TObject);
begin
Memo1.Lines.Add('Document opened');
end;
procedure TForm1.DocClose(Sender: TObject);
begin
Memo1.Lines.Add('Document closed');
end;
procedure TForm1.NewDocButtonClick(Sender: TObject);
begin
try
WordObject.NewDoc('');
except
ShowMessage('It seems like somebody killed Word and didn''t tell me about it...');
if Assigned(WordObject) then begin
LaunchButton.Enabled := True;
CloseButton.Enabled := False;
NewDocButton.Enabled := False;
TypeTextButton.Enabled := False;
WordObject.Free;
WordObject := nil;
end;
end;
end;
procedure TForm1.TypeTextButtonClick(Sender: TObject);
begin
WordObject.InsertText(WordText.Text);
end;
procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
if Assigned(WordObject) then begin
WordObject.Free;
WordObject := nil;
end;
end;
要求很简单,C:/Program Files/Borland/Delphi7/Demos/ActiveX/OleAuto/Word8这个例子已经实现了大部分我需要的功能。现在唯一要做的就是向WORD输出指定字体以及尺寸的文本。
例如:
第一段输出宋体,四号字,"标题" (居中)
第二段输出黑体,小五,“这是内容”(局左)
第三段输出黑体,五号,“时间“(居右)
谁能给出完整源码,非常感谢。 另外对Excel的操作,各位附上Demo的,发到我邮箱,redleilei@sina.com。另外再送上150分。
下面是Delphi自带Demo的源码,我打算用这个就行了,大侠最好在这个基础上改。
-------
procedure TForm1.LaunchButtonClick(Sender: TObject);
begin
if not Assigned(WordObject) then begin
WordObject := TWordObject.Create;
with WordObject do begin
Caption := 'Delphi is RAD!';
Visible := True;
OnQuit := AppQuit;
OnDocumentChange := AppDocumentChange;
OnNewDocument := DocNew;
OnOpenDocument := DocOpen;
OnCloseDocument := DocClose;
end;
LaunchButton.Enabled := False;
CloseButton.Enabled := True;
NewDocButton.Enabled := True;
end;
end;
procedure TForm1.CloseButtonClick(Sender: TObject);
begin
if Assigned(WordObject) then begin
LaunchButton.Enabled := True;
CloseButton.Enabled := False;
NewDocButton.Enabled := False;
TypeTextButton.Enabled := False;
WordObject.Free;
WordObject := nil;
end;
end;
procedure TForm1.AppDocumentChange(Sender: TObject);
begin
Memo1.Lines.Add('Document changed');
TypeTextButton.Enabled := WordObject.Application.Documents.Count > 0;
end;
procedure TForm1.AppQuit(Sender: TObject);
begin
Memo1.Lines.Add('Quitting Word');
WordObject.Free;
WordObject := nil;
LaunchButton.Enabled := True;
CloseButton.Enabled := False;
NewDocButton.Enabled := False;
TypeTextButton.Enabled := False;
end;
procedure TForm1.DocNew(Sender: TObject);
begin
Memo1.Lines.Add('New document');
end;
procedure TForm1.DocOpen(Sender: TObject);
begin
Memo1.Lines.Add('Document opened');
end;
procedure TForm1.DocClose(Sender: TObject);
begin
Memo1.Lines.Add('Document closed');
end;
procedure TForm1.NewDocButtonClick(Sender: TObject);
begin
try
WordObject.NewDoc('');
except
ShowMessage('It seems like somebody killed Word and didn''t tell me about it...');
if Assigned(WordObject) then begin
LaunchButton.Enabled := True;
CloseButton.Enabled := False;
NewDocButton.Enabled := False;
TypeTextButton.Enabled := False;
WordObject.Free;
WordObject := nil;
end;
end;
end;
procedure TForm1.TypeTextButtonClick(Sender: TObject);
begin
WordObject.InsertText(WordText.Text);
end;
procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
if Assigned(WordObject) then begin
WordObject.Free;
WordObject := nil;
end;
end;