十万火急,如何读写word文件,请给出代码,谢谢。

hexiaofeng 2002-02-02 01:02:58
十万火急,如何读写word文件,请给出代码,谢谢。
...全文
75 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
hexiaofeng 2002-02-05
  • 打赏
  • 举报
回复
:)
Bellamy 2002-02-02
  • 打赏
  • 举报
回复
呵呵!
minkerui 2002-02-02
  • 打赏
  • 举报
回复
OLE?
cszhz 2002-02-02
  • 打赏
  • 举报
回复
procedure TForm1.SaveDocument;
var
FileName, FileFormat, LockComments, Password,
AddToRecentFiles, WritePassword, ReadOnlyRecommended,
EmbedTrueTypeFonts, SaveNativePictureFormat,
SaveFormsData, SaveAsAOCELetter :olevariant;
begin
FileName := 'd:\2.doc';
FileFormat := wdFormatDocument;
LockComments := false;
Password := '';
AddToRecentFiles := false;
WritePassword := '';
ReadOnlyRecommended := false;
EmbedTrueTypeFonts := false;
SaveNativePictureFormat := false;
SaveFormsData := false;
SaveAsAOCELetter := false;

worddocument.SaveAs(FileName, FileFormat, LockComments, Password,
AddToRecentFiles, WritePassword, ReadOnlyRecommended,
EmbedTrueTypeFonts, SaveNativePictureFormat, SaveFormsData,
SaveAsAOCELetter);
end;


procedure TForm1.RepalceString;
//让word替换标记字符串要使用worddocument.range.find.execute,这里用delphi替换了<#name>:
var
//一共15个参数
findtext, matchcase, matchwholeword, matchwildcards, matchsoundslike,
matchallwordforms, forward1, wrap, format, replacewith, replace,
MatchKashida, MatchDiacritics, MatchAlefHamza, MatchControl : olevariant; //后四个均为可选项,默认false

num : olevariant;
begin
findtext := '数据上报操作说明';
matchcase := false;
matchwholeword := true;
matchwildcards := false;
matchsoundslike := false;
matchallwordforms := false;
forward1 := true;
wrap := wdfindcontinue;
format := false;
replacewith := 'delphi';
replace := true;
MatchKashida := false;
MatchDiacritics := false;
MatchAlefHamza := false;
MatchControl := false;

// num := 1;
// WordApplication.Documents.Item(num);
worddocument.ConnectTo(WordApplication.ActiveDocument);
worddocument.range.find.execute( findtext, matchcase, matchwholeword,
matchwildcards, matchsoundslike, matchallwordforms,
forward1, wrap, format, replacewith, replace,
matchKashida, MatchDiacritics,
MatchAlefHamza, MatchControl );


end;


procedure TForm1.OpenDocument;
var
FileName : OleVariant;
//Open(FileName, ConfirmConversions, ReadOnly, AddToRecentFiles, PasswordDocument,
//PasswordTemplate, Revert, WritePasswordDocument, WritePasswordTemplate, Format,
//Encoding, Visible)
begin
FileName := 'd:\2.doc';

try
WordApplication.Documents.Open(FileName, EmptyParam, EmptyParam, EmptyParam,
EmptyParam, EmptyParam, EmptyParam, EmptyParam,
EmptyParam, EmptyParam, EmptyParam, EmptyParam);
except
showmessage('该文件不存在!')
end;
end;


procedure TForm1.CloseWord;
var
savechanges, originalformat, routedocument: olevariant;
begin
savechanges := wdSaveChanges;
originalformat := unassigned;
routedocument := unassigned;
try
wordapplication.quit(savechanges, originalformat, routedocument);
wordapplication.disconnect;
except
on e: exception do
begin
showmessage(e.message);
wordapplication.disconnect;
end;
end;
end;


procedure TForm1.startword;
begin
if (wordapplication.Documents.Count <> 0 ) then
begin
messagedlg('请先关闭word!', mterror, [mbok], 0);
exit;
end;

try
wordapplication.connect;
except
messagedlg('word 没有正确安装', mterror, [mbok], 0);
abort;
end;
wordapplication.visible := true;
wordapplication.caption := 'delphi automation';
end;
babyboy 2002-02-02
  • 打赏
  • 举报
回复
去servers控件板上看看,导出word文档去SMExport控件板看看

5,392

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 开发及应用
社区管理员
  • VCL组件开发及应用社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧