在dehpi中我想输出指定的内容到word的指定位置、如何在word的查找我的指定位置:@日期@ ?而且我想用剪贴板的内容代替他!谢谢各位大哥大姐帮忙!
解决方案 »
- 调用程序的问题
- 求救 nmftp在connect 時偶爾 報錯 host lookup fail,timeout
- 小弟在此等侯各位高手的指点,急啊,急啊
- 如何实现编号自加
- 急!!!TStoredProc控件的使用问题,激活时报错"Operation not applicable.",请大家指教
- Adodataset请进!
- 如何获得打印机状态?
- 在DBGrid,DBComboBox 中 怎样一次性修改多条记录.但暂时不post到数据库中
- 如何将一个整型指针转换成字符串指针?
- 只把表中某个字段具有相同值的记录显示出来的SQL语句怎么写?!
- 如何判断鼠标响应事件?
- report builder制作交叉报表的问题
): 首先用Word编辑报表格式,并排好版,把将要输出的数据项用表单域代替,并取名。这里我们暂时假设有表单域Item1及Item2(均为文本型),将这个文档存为模板文件Example.dot,然后按如下步骤进行: 1)运行Delphi3,在Form1里加入一个System部件集里的TDdeClientCov部件,取名为DdeExample,将其ConnectMode设为ddeManual(手动方式);将DdeService设为‘(WinWord)’;将ServiceApplication设为‘WinWord’。 2)编写一个自定义过程,以激活Word,如下: procedure Tform1.WordActive(Cmds: TStrings);
var
WordPath: String;
begin
if(not DdeExample.OpenLink) then {判断是否巳动态链接}
begin
if(FindWindow('OpusApp', nil)=0) then
begin
WordPath := 'C:\msoffice\winword';
if(WordPath='') then
ShowMessage('中文Word未安装或未设置路径,请安装设置Word中文 版。')
else begin
DdeExample.ServiceApplication := WordPath+'\Winword.exe';
if(DdeExample.OpenLink) then {如果巳动态链接执行宏命令} DdeExample.ExecuteMacroLines(Cmds,False) else
ShowMessage('无法启动Word中文版!'); DdeExample.ServiceApplication := 'WinWord.exe';
end;
end
else begin{如果巳动态链接执行宏命令}
DdeExample.ExecuteMacroLines(Cmds,False);
end;
end
else
DdeExample.ExecuteMacroLines(Cmds,false);
end; 在private声明区里加入如下:
procedure ActiveWord(Cmds: TStrings); 3)在Form1中加入一个按钮Button1,在其onclick事件里写如下代码:
procedure TForm1.Button1Click(Sender: TObject);
var
Cmds:TStringList;{创建Cmds}
TempItem1,TempItem2:String;
begin
cmds:=TStringList.Create;
cmds.Clear;
TempItem1:='数据项一';
TempItem2:='数据项二';
with Cmds do
begin
Clear;
Add('[FileNew.Template ="Example.Dot″]');{打开模板文件Example.Dot} Add('[AppMaximize]');{文档最大化}
Add('[SetFormResult"Item1″,″'+TempItem1+'″]');{将数据TempItem1传给表单域Item1}
Add('[SetFormResult"Item2″,″'+TempItem2+'″]);{将数据TempItem2传给表单域Item2}
end;
WordActive(DdeExample,Cmds);{调用自定义过程}
Cmds.Free;{释放Cmds}
end;
我前期工作已经做好!只是在输出时无法定位我的模板文档的指定字符的位置:
如下两个结果都可以:
1、得到指定字符的坐标。
2、得到指定字符的Range对象。
都可以满足我的需求、但是我无法得到!
1、我得文档模板格式不固定-某个标志符如:(@日期@)的位置不顾定、但是标志符的名称不会变化。
2、不能使用Range.Find.Execute() 因为他替换的字符的长度有限制、如果稍微长一点就不能输出。
感谢高手来捧场!
procedure ToReplaceTextEx1(vDocment :OleVariant;FindText ,ReplaceText :AnsiString);
var
iCount,i:Integer ;
Range:OleVariant ;
begin
try
iCount:=vDocment.Paragraphs.Count ;
for i:=1 to iCount do
begin
Range:=vDocment.Paragraphs.Item(i).Range ;
if Pos(FindText,Range.Text)>0 then //Range.Text='<@证据内容@>'
begin
Range.Text:=ReplaceText ;
end;
end
finally
end;
end;