導航:首頁 > 文件教程 > delphiword頁碼

delphiword頁碼

發布時間:2023-08-13 07:14:49

1. delphi控制word

用OLE技術,
在uses部分添加模塊,
然後,如下例子:
unit Unit1;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls,ComObj;

type
TForm1 = class(TForm)
Button1: TButton;
procere Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.dfm}

procere TForm1.Button1Click(Sender: TObject);
var
wd,:OLEVariant;
begin
wd:=CreateOleObject('Word.Application');//建立WinWord對像
:=wd.Documents.Open('e:\a.doc'); //打開Word文檔
ShowMessage(String(wd.ActiveDocument.Name));//顯示打開的文檔名稱
//以下可以插入你自己的程序
.close;//關閉文檔
wd.Quit; //關閉程序
end;

end.

2. 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;

昨天沒有測試好 這個應該沒有問題了吧 試一下吧

3. delphi怎麼設置WORD的頁邊距怎麼設置 WORD某一行的字體大小

分太誘人了,寫一個吧......
uses comobj;

var word,document:olevariant;

begin

word:=createoleobject('word.application');
document:=word.documents;
document.open('c:\1.doc');
word.ActiveDocument.pagesetup.topmargin:=111; //上邊距topmargin 下bottommargin 左leftmargin 右 right.....
word.selection.HomeKey(wdline,1); //開始選擇范圍
word.Selection.MoveDown(wdline,3);
word.selection.endkey(wdline,wdExtend );
word.Selection.Font.Size:=1111; //結束范圍設置,第四行文字改變。
word.ActiveDocument.saveas('c:\2.doc');
document.close;
word.quit;
word:=unassigned;

end; 補充一下,需要用到控制項server中的 wordapplication,通過d7測試!

閱讀全文

與delphiword頁碼相關的資料

熱點內容
cocoapods版本更新 瀏覽:361
國外it大神教你學習如何編程 瀏覽:312
手機存儲應用程序 瀏覽:284
頁面自適應屏幕如何調整代碼數據 瀏覽:681
jsjson工具 瀏覽:299
資料庫中如何備份一張表的數據 瀏覽:739
網路設備能用到什麼 瀏覽:64
暴風轉碼如何添加文件夾 瀏覽:515
延安整合網路營銷有哪些 瀏覽:74
查找word打開過的文件在哪裡 瀏覽:137
b樹java代碼 瀏覽:683
電腦文件存儲 瀏覽:657
蘭州中考徵集志願在哪個網站 瀏覽:215
cs文件上傳下載 瀏覽:244
拷貝文件到根目錄下重命名linux 瀏覽:603
api函數的頭文件 瀏覽:249
華為怎麼綁定迷你編程 瀏覽:215
機構怎麼申請少兒編程考級 瀏覽:495
崑山數控編程哪裡好學 瀏覽:459
jspcfor跳出 瀏覽:65

友情鏈接