导航:首页 > 文件目录 > 文件内容查找delphi

文件内容查找delphi

发布时间:2025-08-01 06:32:09

㈠ delphi读取word文档每一页的内容

uses ComObj,WordXp;

var wordapp, WordDoc, PageRange: Variant;
sContext: string;
i, nPageCounts, nStart, nEnd : Integer;
begin
wordapp := CreateOleObject('Word.Application');
try
wordapp.Visible := True;
if dlgOpen1.Execute = False then Exit;
WordDoc := wordapp.Documents.Open(dlgOPen1.FileName);
//文档总页数
nPageCounts := wordapp.Selection.Information[wdNumberOfPagesInDocument];

//如果只有一页 那么全选就OK了
if nPageCounts = 1 then
begin
wordapp.Selection.WholeStory;
mmo1.Lines.Add('=============第'+IntToStr(nPageCounts)+'页内容:===================');
mmo1.Lines.Add(wordapp.Selection.Text);
Exit;
end;

nStart := -1;
nEnd := -1;
//循环获取文档页中的内容
for i := 1 to nPageCounts do
begin
//定位到第i页
PageRange := wordapp.Selection.GoTo(wdGoToPage, wdGoToNext, IntToStr(i));
//如果第i页是最后一页 那么直接将光标移动到最后 并输出内容
if i = nPageCounts then
begin
wordapp.Selection.EndKey(wdStory,wdExtend);
sContext := WordApp.Selection.Range.Text;
mmo1.Lines.Add('=============第'+IntToStr(i)+'页内容:===================');
mmo1.Lines.Add(sContext);
Exit;
end;

//取第i页的页首位置作为开始位置
nStart := wordapp.Selection.Start;
//定位到i+1页
PageRange := wordapp.Selection.GoTo(wdGoToPage, wdGoToNext, IntToStr(i+1));
//取第i+1页的页首位置作为结束位置
nEnd := wordapp.Selection.Start;
//根据开始位置和结束位置确定文档选中的内容(第i页的内容)
WordDoc.Range(nStart,nEnd).Select;
sContext := WordDoc.Range.Text;
//输出内容
mmo1.Lines.Add('=============第'+IntToStr(i)+'页内容:===================');
mmo1.Lines.Add(sContext);
nStart := -1;
nEnd := -1;
end;
finally
wordapp.Quit;
end;
end;

昨天没有测试好 这个应该没有问题了吧 试一下吧

㈡ delphi中,如何读取一个目录中的所有文件在线等……

procere FileSearch(PathName:string);
var
F : TSearchRec;
Found : Boolean;
begin
ChDir(PathName);
Found := (FindFirst('*.*', faAnyFile, F) = 0);
while Found do
begin
if (F.Name = '.') or (F.Name = '..') then
begin
Found := (FindNext(F) = 0);
Continue;
end;

if (F.Attr and faDirectory)>0 then
begin
Application.ProcessMessages;
FileSearch(F.Name);
end;
//插入你的代码,F.Name就是文件名,GetCurrentDir可以得到当前目录
Found := (FindNext(F) = 0);
end;
FindClose(F);
ChDir('..\');
end;

转换目录可以用MoveFile,查一下帮助

㈢ delphi 中查找已知路径下某类型文件的个数

变量没有初始化,如下:
-----------------------------------------------------------------
procere TForm1.Button2Click(Sender: TObject);
var
Search:TSearchRec; //搜索到的文件信息的一个数据结构
ret,FileNums:integer; //findFirst文件搜索方法的返回值,0表示成功,不为0表示失败
key:string;
FileName,FilePath:string;
begin
FileNums :=0; //*>>>>>>>>>>>>>>>>>>>这里加上初始化>>>>>>>>>>>>>>
FilePath := edit1.Text;
key := FilePath+ '*.txt';

ret := SysUtils.FindFirst(key,faanyfile,search);

㈣ delphi里怎么把指定文件夹内的所有文件名输出出来

1、使用函数和FindNext函数就可以查找出文件夹内所有的文件名,编写如下一个函数:

function searchfile(path:string):TStringList;
var SearchRec:TSearchRec;
found:integer;
list:TStringList;
begin
list:=TStringList.Create;
found:=FindFirst(path+'*.*',faAnyFile,SearchRec);
while found=0 do
begin
if (SearchRec.Name<>'.') and (SearchRec.Name<>'..') and (SearchRec.Attr<>faDirectory)
then List.Add(SearchRec.Name);
found:=FindNext(SearchRec);
end;
FindClose(SearchRec);
searchfile:=list;
end;

2、使用searchfile(要查找的路径),就可以得到所有文件名,如下示例:

procere TForm1.btn1Click(Sender: TObject);
begin
mmo1.Lines.AddStrings(searchfile('G:BaiDu\_codeigimg'));
end;

效果如下:

㈤ delphi如何获得一个文件夹下所有文件的信息

方法来1:先调用FindFirst启动列表,再自循环调用FindNext获取文件名存入aa数组,最后调用FindClose关闭列表
方法2:直接使用TFileListBox控件,设置好Drive、Directory、FileType属性,然后访问其Items数组就能得到所有文件/子目录列表了,很简单

阅读全文

与文件内容查找delphi相关的资料

热点内容
js给php变量赋值 浏览:446
杂志版本号是什么意思 浏览:223
地图特效代码 浏览:192
去除思科配置文件中的号 浏览:196
运行的16位程序太多 浏览:1
苹果mac用什么软件好学编程 浏览:681
ai中线段怎么添加宽度配置文件 浏览:956
lol文件怎么找不到game 浏览:142
aecc视频教程 浏览:983
linux怎么查看数据库用户名 浏览:182
cefs文件系统 浏览:404
学平面设计个编程哪个好 浏览:701
如何把编程文件转为hex 浏览:80
清除苹果地图来自地址 浏览:233
已经打开的文件如何清理 浏览:685
视频网站有什么用 浏览:70
多个表格文件怎样压缩文件 浏览:729
cad文件大很卡如何解决 浏览:633
将java程序打包成apk 浏览:277
2021唱吧文件找不到了 浏览:463

友情链接