delphi 中对word 进行控制时,word 中Paragraphs对象的使用,请高手进

jimiking 2003-07-10 10:09:37
在delphi 中对进行控制,主要是获得文档的段落信息 首先打开本地的一个指定文件

创建OLE对象
var
MSWord:variant;
begin
MSWord:=CreateOLEObject('Word.Application');
MSWord.Documents.Open(FileName:=TestFile,ReadOnly:=True);
然后获得文档的段落信息
var
oleParaCnt,olePgSetUp,oleParas,oleRanges : olevariant ;
str :string ;
begin
result:=true;
try
olePgSetUp:=word_app.ActiveDocument.PageSetup ; //返回PageSetup 对象,包含了文档的所有页面设置属性
oleParaCnt:=word_app.ActiveDocument.Paragraphs.count ; //得到段落数
while oleParaCnt>0 do
begin
oleRanges:=word_app.ActiveDocument.Paragraphs.item(oleParaCnt).range ; //引用活动文档的第oleParaCnt个段落
oleRanges.end:= oleRanges.end-1; //改变区域但是不改变当前选定的内容
str:=trim(oleRanges.text);
if strlen(PChar(str))>0 then break ; //如strlen(PChar(str))为0 ,即所选区域的最后一段为空,在段落数目中减一
oleParaCnt:=oleParaCnt-1;
end ;
oleRanges.Start:=word_app.ActiveDocument.Paragraghs.item(1).Range.Start ;
oleRanges.end:= word_app.ActiveDocument.Paragraghs.item(oleParaCnt).Range.end ;

在执行最后两句时候 有错误为: method 'paragraphs' not supported by automation object 请问如何解决
...全文
195 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
nzh517 2003-07-11
  • 打赏
  • 举报
回复
不懂,帮你UP

1,184

社区成员

发帖
与我相关
我的任务
社区描述
Delphi Windows SDK/API
社区管理员
  • Windows SDK/API社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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