[Delphi+Word]和大家共享(如何使用)

happyprogram 2003-10-12 03:02:05
使用前,先根据需要建立一个空的WORD文件作为模板,在模板文件中设置好各种格式和文本。另外,其中的PrnWordTable的参数是TDBGridEh类型的控件,取自Ehlib2.6

示范代码如下:

代码1:
替换打印模板中的“#TITLE#”文本为“示范代码1”
并且将DBGridEh1控件当前显示的内容插入到文档的末尾
在文档末尾插入一个空行
在文档末尾插入新的一行文本
将文档中的空行去掉

if PrnWordBegin('C:\打印模板.DOC','C:\目标文件1.DOC') then
begin
PrnWordReplace('#TITLE#','示范代码1');
PrnWordTable(DBGridEh1);
PrnWordInsert('');
PrnWordInsert('这是新的一行文本');
PrnWordReplace('^p^p','^p',true);
PrnWordSave;
end;

...全文
35 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
happyprogram 2003-10-13
  • 打赏
  • 举报
回复
整理了一下,已经放到文档中心去了,标题为:[Delphi+Word]解决方案参考
本来有些代码的处理方式还可以更灵活些,但实在没有时间再改进了,大家将就将就,呵呵
noil0125 2003-10-13
  • 打赏
  • 举报
回复
up
hare007 2003-10-13
  • 打赏
  • 举报
回复
mark
zhoutian618 2003-10-13
  • 打赏
  • 举报
回复
up
奔跑9999 2003-10-13
  • 打赏
  • 举报
回复
不錯,不錯,我試用一下。。。
happyprogram 2003-10-12
  • 打赏
  • 举报
回复
忘了补充一点:PrnWordBegin里的shFileCopy也是自己编的函数,用于复制文件的。干脆也把代码贴出来吧:

功能:安全的复制文件
srcFile,destFile:源文件和目标文件
bDelDest:如果目标文件已经存在,是否覆盖
返回值:true成功,false失败
}
function shFileCopy(srcFile,destFile:String;bDelDest:boolean=true):boolean;
begin
result:=false;
if not FileExists(srcFile) then
begin
ShowMessage('源文件不存在,不能复制。'+#10#13+srcFile);
exit;
end;
if srcFile=destFile then
begin
ShowMessage('源文件和目标文件相同,不能复制。');
exit;
end;
if FileExists(destFile) then
begin
if not bDelDest then
begin
ShowMessage('目标文件已经存在,不能复制。'+#10#13+destFile);
exit;
end;
FileSetAttr(destFile,FileGetAttr(destFile) and not $00000001);
if not DeleteFile(PChar(destFile)) then
begin
ShowMessage('目标文件已经存在,并且不能被删除,复制失败。'+#10#13+destFile);
exit;
end;
end;
if not CopyFileTo(srcFile,destFile) then
begin
ShowMessage('发生未知的错误,复制文件失败。');
exit;
end;
//目标文件去掉只读属性
FileSetAttr(destFile,FileGetAttr(destFile) and not $00000001);
result:=true;
end;

5,388

社区成员

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

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