Delphi与Word(三)取得Word文件的数据
LuckyJan
//取得Word文件的数据
procedure getWordStr;
var WordApp: TWordApplication;
WordDoc: TWordDocument;
DocInx,oFileName,CfCversions,oReadOnly,AddToRctFiles,PswDocument,
PswTemplate,oRevert,WPswDocument,WPswTemplate,oFormat: OleVariant;
i,iRow,iCol:integer;
myCell:Cell;
myRow:Row;
begin
memo1.Lines.Clear ;
LuckyJan
//取得Word文件的数据
procedure getWordStr;
var WordApp: TWordApplication;
WordDoc: TWordDocument;
DocInx,oFileName,CfCversions,oReadOnly,AddToRctFiles,PswDocument,
PswTemplate,oRevert,WPswDocument,WPswTemplate,oFormat: OleVariant;
i,iRow,iCol:integer;
myCell:Cell;
myRow:Row;
begin
memo1.Lines.Clear ;
// ===== 创建对象 =====
if not Assigned(WordApp) then
begin
WordApp:= TWordApplication.Create(nil);
WordApp.Visible := false;
end;
if not Assigned(WordDoc) then
WordDoc:= TWordDocument.Create(nil);
try
DocInx:=1;
oFileName := ´d:/test.doc´;
oReadOnly:=true;
CfCversions := EmptyParam;
AddToRctFiles:= EmptyParam;
PswDocument:= E
if not Assigned(WordApp) then
begin
WordApp:= TWordApplication.Create(nil);
WordApp.Visible := false;
end;
if not Assigned(WordDoc) then
WordDoc:= TWordDocument.Create(nil);
try
DocInx:=1;
oFileName := ´d:/test.doc´;
oReadOnly:=true;
CfCversions := EmptyParam;
AddToRctFiles:= EmptyParam;
PswDocument:= E

这篇博客介绍了如何使用Delphi控制Word进行数据库和公文处理。通过创建TWordApplication和TWordDocument对象,打开并操作Word文档,替换文本中的标记字符串,实现了将数据库中的数据动态插入到Word模板中,从而生成个性化合同的功能。此外,还提供了启动、关闭Word,以及打开、保存Word文件的相关代码示例。
最低0.47元/天 解锁文章
3479

被折叠的 条评论
为什么被折叠?



