導航:首頁 > 文件目錄 > 文件內容查找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相關的資料

熱點內容
msp430系列單片機實用c語言程序設計 瀏覽:423
移動硬碟的文件格式 瀏覽:904
文件本地路徑與雲路徑 瀏覽:103
進大白菜找不到系統文件 瀏覽:380
ug裝配體找不到文件部件已刪除 瀏覽:629
小網站怎麼弄出來 瀏覽:649
jsp表單加參數 瀏覽:607
蘋果5s手機老是卡屏 瀏覽:58
js給php變數賦值 瀏覽:446
雜志版本號是什麼意思 瀏覽:223
地圖特效代碼 瀏覽:192
去除思科配置文件中的號 瀏覽:196
運行的16位程序太多 瀏覽:1
蘋果mac用什麼軟體好學編程 瀏覽:681
ai中線段怎麼添加寬度配置文件 瀏覽:956
lol文件怎麼找不到game 瀏覽:142
aecc視頻教程 瀏覽:983
linux怎麼查看資料庫用戶名 瀏覽:182
cefs文件系統 瀏覽:404
學平面設計個編程哪個好 瀏覽:701

友情鏈接