P
pp虫
Unregistered / Unconfirmed
GUEST, unregistred user!
我用worddocument和wordapplication、wordfont的过程中遇到以下问题:
我想控制word每一段的字体,但我用以下方法只能使各段显示同一种字体,还请各位大虾指点,谢过先了
procedure TForm1.Button1Click(Sender: TObject);
var
ItemIndex :OleVariant;
FileName, ConfirmConversions, ReadOnly, AddToRecentFiles,
PasswordDocument, PasswordTemplate, Revert,
WritePasswordDocument, WritePasswordTemplate, Format: OleVariant;
procedure setfont1;
begin
WordFont.ConnectTo(WordDocument. .Sentences.Get_Last.Font);
WordFont.Name:='宋体';
WordFont.Size :=9;
WordFont.Bold := 1;
end;
procedure setfont2;
begin
WordFont.ConnectTo(WordDocument.Sentences.Get_Last.Font);
WordFont.Name:='黑体';
WordFont.Size :=9;
WordFont.Bold := 0;
end;
begin
try
Wordapplication.Connect;
except
MessageDlg('Word may not be installed', mtError, [mbOk], 0);
Abort;
end;
Wordapplication.Visible := True;
WordApplication.Caption := 'Delphi automation';
FileName := 'e:/newword.doc'; //我硬盘里存在的word文件
ConfirmConversions := False;
ReadOnly := False;
AddToRecentFiles := False;
PasswordDocument := '';
PasswordTemplate := '';
Revert := True;
WritePasswordDocument := '';
WritePasswordTemplate := '';
Format := wdOpenFormatDocument;
WordApplication.Documents.Open( FileName, ConfirmConversions,
ReadOnly, AddToRecentFiles, PasswordDocument, PasswordTemplate,
Revert, WritePasswordDocument, WritePasswordTemplate, Format );
{Assign WordDocument component}
ItemIndex := 1;
WordDocument.ConnectTo(WordApplication.Documents.Item(ItemIndex));
Wordapplication.Visible := true;
SetFont1;
WordDocument.Range.InsertAfter('这句显示用宋体');
SetFont2;
WordDocument.Range.InsertAfter('这句显示用黑体')
end;
我想控制word每一段的字体,但我用以下方法只能使各段显示同一种字体,还请各位大虾指点,谢过先了
procedure TForm1.Button1Click(Sender: TObject);
var
ItemIndex :OleVariant;
FileName, ConfirmConversions, ReadOnly, AddToRecentFiles,
PasswordDocument, PasswordTemplate, Revert,
WritePasswordDocument, WritePasswordTemplate, Format: OleVariant;
procedure setfont1;
begin
WordFont.ConnectTo(WordDocument. .Sentences.Get_Last.Font);
WordFont.Name:='宋体';
WordFont.Size :=9;
WordFont.Bold := 1;
end;
procedure setfont2;
begin
WordFont.ConnectTo(WordDocument.Sentences.Get_Last.Font);
WordFont.Name:='黑体';
WordFont.Size :=9;
WordFont.Bold := 0;
end;
begin
try
Wordapplication.Connect;
except
MessageDlg('Word may not be installed', mtError, [mbOk], 0);
Abort;
end;
Wordapplication.Visible := True;
WordApplication.Caption := 'Delphi automation';
FileName := 'e:/newword.doc'; //我硬盘里存在的word文件
ConfirmConversions := False;
ReadOnly := False;
AddToRecentFiles := False;
PasswordDocument := '';
PasswordTemplate := '';
Revert := True;
WritePasswordDocument := '';
WritePasswordTemplate := '';
Format := wdOpenFormatDocument;
WordApplication.Documents.Open( FileName, ConfirmConversions,
ReadOnly, AddToRecentFiles, PasswordDocument, PasswordTemplate,
Revert, WritePasswordDocument, WritePasswordTemplate, Format );
{Assign WordDocument component}
ItemIndex := 1;
WordDocument.ConnectTo(WordApplication.Documents.Item(ItemIndex));
Wordapplication.Visible := true;
SetFont1;
WordDocument.Range.InsertAfter('这句显示用宋体');
SetFont2;
WordDocument.Range.InsertAfter('这句显示用黑体')
end;