1、已存在的word模版在指定位置有三个文本框,delphi如何写程序将数据填入word的不同文本框中?
2、已存在word模版里是一个表格,delphi如何将数据写入表格中?
因为时间紧,最好能给出详细些的代码,多谢了
2、已存在word模版里是一个表格,delphi如何将数据写入表格中?
因为时间紧,最好能给出详细些的代码,多谢了
解决方案 »
- delphi将整个结构Move到到一个Array of Byte的问题
- 在线请教,备份和恢复sql server数据库
- 简单问题
- 问题清楚,高手进来看看呀(我如何获得所选行的序号呢?)。
- 为什么我用ADOConnection的ODBC不能访问dBase,paradox等类型的数据库啊?请问如何写驱动呢?谢谢
- 用SQLConnection,事务处理问题怎么写
- ado里面query怎么像BED里面的query设置参数呀? 急!!!解决了 我送200分
- 多线程的疑惑!
- DBGrid有没有这种功能,每个cell可以是下拉框,可实现选择的,然后触发一个事件,在另一个cell得到计算结果?
- 请问怎样打包第三方控件!
- 如何让Delphi做的多媒体播放器程序不用指定初始文件而能正常运行?
- 谁有REPORTMACHINE最新注册版?能否发一份啊
var
WordApp,WordDoc,WordTable:OleVariant;
i,j:integer;
begin
WordApp:=CreateOleObject('Word.Application');
WordApp.Visible:=True;
WordDoc:=WordApp.Documents.Add;
WordTable:=WordDoc.Tables.Add(WordApp.Selection.Range,DBGrid1.DataSource.DataSet.RecordCount+1,DBGrid1.Columns.Count);
for i:=1 to DBGrid1.Columns.Count do
WordTable.Cell(1,i).Range.InsertAfter(DBGrid1.Columns[i-1].Title.Caption);
i:=2;
with DBGrid1.DataSource.DataSet do
while not eof do
begin
for j:=1 to DBGrid1.Columns.Count do
WordTable.Cell(i,j).Range.InsertAfter(DBGrid1.Columns[j-1].Field.Value);
Next;
Inc(i);
end;
end;启动word时用如下代码:
begin
try
wordapplication.connect;
except
messagedlg('word may not be installed', mterror, [mbok], 0);
abort;
end;
wordapplication.visible := true;
wordapplication.caption := 'delphi automation';
end; 关闭word用如下代码。如果想保存doc文件,请修改savechanges变量的内容:
var
savechanges, originalformat, routedocument: olevariant;
begin
savechanges := wddonotsavechanges;
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; 让word打开一个指定的文件,需要先放置opendialog,然后调用wordapplication.documents.open:
var
itemindex :olevariant;
filename, confirmconversions, readonly, addtorecentfiles,
passworddocument, passwordtemplate, revert,
writepassworddocument, writepasswordtemplate, format: olevariant;
begin
if not dlgopen.execute then
exit; {open document}
filename := dlgopen.filename;
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)); {turn spell checking of because it takes a long time if enabled and slows down winword}
wordapplication.options.checkspellingasyoutype := false;
wordapplication.options.checkgrammarasyoutype := false;
end; 让word替换标记字符串要使用worddocument.range.find.execute,这里用delphi替换了<#name>:
var
findtext, matchcase, matchwholeword, matchwildcards, matchsoundslike,
matchallwordforms, forward, wrap, format, replacewith, replace: olevariant;
begin
findtext := '<#name>';
matchcase := false;
matchwholeword := true;
matchwildcards := false;
matchsoundslike := false;
matchallwordforms := false;
forward := true;
wrap := wdfindcontinue;
format := false;
replacewith := 'delphi';
replace := true; worddocument.range.find.execute( findtext, matchcase, matchwholeword,
matchwildcards, matchsoundslike, matchallwordforms, forward,
wrap, format, replacewith, replace ); end;
让word替换标记字符串要使用worddocument.range.find.execute,这里用delphi替换了<#name>:
var
findtext, matchcase, matchwholeword, matchwildcards, matchsoundslike,
matchallwordforms, forward, wrap, format, replacewith, replace: olevariant;
begin
findtext := '<#name>';
matchcase := false;
matchwholeword := true;
matchwildcards := false;
matchsoundslike := false;
matchallwordforms := false;
forward := true;
wrap := wdfindcontinue;
format := false;
replacewith := 'delphi';
replace := true;worddocument.range.find.execute( findtext, matchcase, matchwholeword,
matchwildcards, matchsoundslike, matchallwordforms, forward,
wrap, format, replacewith, replace );end;就是这个,在文本框中输入相关标记就ok了!~