在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 请问如何解决
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 请问如何解决
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货