delphi里操作word文档(100分)

  • 主题发起人 主题发起人 anni9977
  • 开始时间 开始时间
A

anni9977

Unregistered / Unconfirmed
GUEST, unregistred user!
在delphi里操作word文档,最起码能查找替换,把源码贴出来测试通过,马上给分。只要解决把我的全部家当都给也可以
 
[:(]怎么没有人回答我的问题呢,难道真的没人弄过吗?有知道的帮帮忙吧,谢谢,兄弟姐妹们了[:)]
 
uses
ComObj, OleServer, PowerPointXP,
ExcelXP;
......

procedure TfrmHelpWoedPPT.SpeedButton1Click(Sender: TObject);
var
WordApp:OleVariant;
begin
WordApp:=CreateOleObject('word.application');
WordApp.visible:=true;
WordApp.Documents.Open(ExtractFilePath(paramstr(0))+'Doc/posonWord.doc');
end;

procedure TfrmHelpWoedPPT.SpeedButton2Click(Sender: TObject);
var
pptApp:OleVariant;
begin
pptApp:=CreateOleObject('PowerPoint.application');
pptApp.visible:=true;
pptApp.Presentations.Open(ExtractFilePath(paramstr(0))+'Doc/posonPPT.ppt');
end;
上述可以打开PPT/WORD文档。
不知道你说的是不是这个意思!
 
我不只是要打开,而是打弄程序查找替换某词后,保存,我现在也能打开只是没有保存上我修改的内容,代码如下
procedure TForm1.btn1Click(Sender: TObject);
begin
try
Wordapplication.Connect;
except
MessageDlg('Word may not be installed', mtError, [mbOk], 0);
Abort;
end;
Wordapplication.Visible := True;
WordApplication.Caption := 'Delphi automation';
end;

procedure TForm1.btn2Click(Sender: TObject);
var
SaveChanges, OriginalFormat, RouteDocument: OleVariant;
begin
SaveChanges := WdSaveChanges;
OriginalFormat := UnAssigned;
RouteDocument := UnAssigned;
try
WordApplication.Quit(SaveChanges, OriginalFormat, RouteDocument);
WordApplication.Disconnect;
except
on E: Exceptiondo
begin
Showmessage(E.Message);
WordApplication.Disconnect;
end;
end;
end;

procedure TForm1.btn3Click(Sender: TObject);
var
ItemIndex :OleVariant;
FileName, ConfirmConversions, ReadOnly, AddToRecentFiles,
PasswordDocument, PasswordTemplate, Revert,
WritePasswordDocument, WritePasswordTemplate, Format, aa, bb: OleVariant;
begin
{Opendo
cument}
if not dlgOpen1.Execute then
Exit;
FileName := dlgOpen1.FileName;
ConfirmConversions := False;
ReadOnly := False;
AddToRecentFiles := False;
PasswordDocument := '';
PasswordTemplate := '';
Revert := True;
WritePasswordDocument :='' ;
WritePasswordTemplate :='' ;
Format := wdOpenFormatDocument;
aa := TRUE;
bb := TRUE;

WordApplication.Visible := TRUE;
{WordApplication.Documents.Open( FileName, ConfirmConversions,
ReadOnly, AddToRecentFiles, PasswordDocument, PasswordTemplate,
Revert, WritePasswordDocument, WritePasswordTemplate, Format, aa, bb);}
WordApplication.Documents.Open( FileName, ConfirmConversions,
ReadOnly, AddToRecentFiles, PasswordDocument, PasswordTemplate,
Revert, WritePasswordDocument, WritePasswordTemplate, Format, aa, bb);
ItemIndex := 0;
WordDocument.ConnectTo(WordApplication.Documents.Item(ItemIndex));
WordApplication.Options.CheckSpellingAsYouType := False;
WordApplication.Options.CheckGrammarAsYouType := False;
end;
procedure TForm1.btn4Click(Sender: TObject);
var
FindText, MatchCase, MatchWholeWord, MatchWildcards, MatchSoundsLike,
MatchAllWordForms, Forward1, Wrap, Format, ReplaceWith, Replace: OleVariant;
begin
FindText := '<#Name>';
MatchCase := False;
MatchWholeWord := True;
MatchWildcards := False;
MatchSoundsLike := False;
MatchAllWordForms := False;
Forward1 := True;
Wrap := EmptyParam;
Format := False;
ReplaceWith := '123456';
Replace := True;
WordDocument.Range.Find.Execute( FindText, MatchCase, MatchWholeWord,
MatchWildcards, MatchSoundsLike, MatchAllWordForms, Forward1,
Wrap, Format, ReplaceWith, Replace,EmptyParam,EmptyParam,EmptyParam,EmptyParam );
end;
 
已经可以了,不过同样感谢listhano
 
后退
顶部