用OLE提取WORD文档怎么实现滚动?(100分)

  • 主题发起人 主题发起人 coonlee
  • 开始时间 开始时间
C

coonlee

Unregistered / Unconfirmed
GUEST, unregistred user!
只能显示一页的文档,太不方便了!

另外,用WORD APPLICATION能够比用OLE更方便吗?怎样实现呢?
 
>>只能显示一页的文档,太不方便了!
??????
>>另外,用WORD APPLICATION能够比用OLE更方便吗?怎样实现呢?
var
v:variant;
begin
v:=CreateOleObject(Word.Application);
end;
 
以前写的一个在WORD中画表和填表的例子,写得比较乱,你只需要看部分内容知道怎么做就行了.
Delphi的例子中也有一个讲调用WORD的.
procedure TFrmCompany.WriteToWord;
var Template,NewTemplate,ItemIndex,PageNumberAlignment:OleVariant;
Count_Var:OleVariant;
un_Var,un_DownVar,ex_Var,Start_var,End_Var,Down_Var,Up_Var:OleVariant;
Bool_var:OleVariant;
i:integer;
CWidth:array[0..8] of single;
begin
CWidth[0]:=45;
CWidth[1]:=80;
CWidth[2]:=35;
CWidth[3]:=240;
CWidth[4]:=400;
CWidth[5]:=355;
CWidth[6]:=150;
CWidth[7]:=275;
CWidth[8]:=55;
Template := EmptyParam;
NewTemplate := False;
ItemIndex:=1;
WA.Connect;
WA.Visible:=True;
WA.Documents.Add(Template, NewTemplate);
WD.ConnectTo(WA.Documents.Item(ItemIndex));

PageNumberAlignment:=wdAlignPageNumberCenter;
Bool_var:=True;
WA.Selection.Sections.Item(1).Footers.Item(1).PageNumbers.Add(PageNumberAlignment,Bool_Var);

Bool_var:=False;
AdoQryCompany.First;
i:=1;
while not AdoQryCompany.Eof do
begin
WD.Range.InsertAfter(#13);
WD.Tables.Add(WA.selection.Range,9,4);

un_Var:=wdCharacter; //第一行
Start_Var:=1;
End_Var:=4;
ex_Var:=wdExtend;
WA.Selection.MoveRight(un_Var,End_Var,ex_Var);
WA.Selection.Cells.Merge;
WA.Selection.TypeText(AdoQryCompany.FieldByName('province').AsString);
WA.Selection.Cells.Item(1).SetWidth(CWidth[4],wdAdjustNone);
WA.Selection.ParagraphFormat.Alignment:=wdAlignParagraphCenter;

un_DownVar:=wdLine;
Down_Var:=1;
ex_Var:=wdMove;
WA.Selection.MoveRight(un_Var,Start_Var,ex_Var);
WA.Selection.MoveRight(un_Var,Start_Var,ex_Var); //第二行
WA.Selection.Cells.Item(1).SetWidth(CWidth[0],wdAdjustNone);
WA.Selection.ParagraphFormat.Alignment:=wdAlignParagraphCenter;
WA.Selection.MoveRight(un_Var,Start_Var,ex_Var);
WA.Selection.Cells.Item(1).SetWidth(CWidth[0],wdAdjustNone);
WA.Selection.MoveRight(un_Var,Start_Var,ex_Var);
WA.Selection.Cells.Item(1).SetWidth(CWidth[2],wdAdjustNone);
WA.Selection.ParagraphFormat.Alignment:=wdAlignParagraphCenter;
WA.Selection.MoveRight(un_Var,Start_Var,ex_Var);
WA.Selection.Cells.Item(1).SetWidth(CWidth[7],wdAdjustNone);

WA.Selection.MoveRight(un_Var,Start_Var,ex_Var);
WA.Selection.MoveRight(un_Var,Start_Var,ex_Var);
WA.Selection.Cells.Item(1).SetWidth(CWidth[0],wdAdjustNone);
WA.Selection.ParagraphFormat.Alignment:=wdAlignParagraphCenter;
Start_Var:=1;
End_Var:=3;
ex_Var:=wdMove;
WA.Selection.MoveRight(un_Var,Start_Var,ex_Var);
ex_Var:=wdExtend;
WA.Selection.MoveRight(un_Var,End_Var,ex_Var);
WA.Selection.Cells.Merge;
WA.Selection.Cells.Item(1).SetWidth(CWidth[5],wdAdjustNone);

ex_Var:=wdMove;
WA.Selection.MoveRight(un_Var,Start_Var,ex_Var);
WA.Selection.MoveRight(un_Var,Start_Var,ex_Var);

WA.Selection.Cells.Item(1).SetWidth(CWidth[0],wdAdjustNone); //第四行
WA.Selection.ParagraphFormat.Alignment:=wdAlignParagraphCenter;
WA.Selection.MoveRight(un_Var,Start_Var,ex_Var);
Count_Var:=3;
WA.Selection.Cells.Split(Down_var,Count_var,Bool_Var);
WA.Selection.MoveLeft(un_Var,Start_Var,ex_Var);
WA.Selection.Cells.Item(1).SetWidth(CWidth[1],wdAdjustNone);
WA.Selection.MoveRight(un_Var,Start_Var,ex_Var);
WA.Selection.Cells.Item(1).SetWidth(CWidth[2],wdAdjustNone);
WA.Selection.ParagraphFormat.Alignment:=wdAlignParagraphCenter;
WA.Selection.MoveRight(un_Var,Start_Var,ex_Var);
WA.Selection.Cells.Item(1).SetWidth(CWidth[6],wdAdjustNone);
WA.Selection.MoveRight(un_Var,Start_Var,ex_Var);
WA.Selection.Cells.Item(1).SetWidth(CWidth[0],wdAdjustNone);
WA.Selection.ParagraphFormat.Alignment:=wdAlignParagraphCenter;
WA.Selection.MoveRight(un_Var,Start_Var,ex_Var);
WA.Selection.Cells.Item(1).SetWidth(CWidth[0],wdAdjustNone);

WA.Selection.MoveRight(un_Var,Start_Var,ex_Var);
WA.Selection.MoveRight(un_Var,Start_Var,ex_Var);
WA.Selection.Cells.Item(1).SetWidth(CWidth[0],wdAdjustNone); //第五行
WA.Selection.ParagraphFormat.Alignment:=wdAlignParagraphCenter;
WA.Selection.MoveRight(un_Var,Start_Var,ex_Var);
WA.Selection.Cells.Item(1).SetWidth(CWidth[1],wdAdjustNone);
WA.Selection.MoveRight(un_Var,Start_Var,ex_Var);
WA.Selection.Cells.Item(1).SetWidth(CWidth[2],wdAdjustNone);
WA.Selection.ParagraphFormat.Alignment:=wdAlignParagraphCenter;
WA.Selection.MoveRight(un_Var,Start_Var,ex_Var);
WA.Selection.Cells.Item(1).SetWidth(CWidth[3],wdAdjustNone);

ex_Var:=wdMove;
WA.Selection.MoveRight(un_Var,Start_Var,ex_Var); //第六行
WA.Selection.MoveRight(un_Var,Start_Var,ex_Var);
WA.Selection.Cells.Item(1).SetWidth(CWidth[0],wdAdjustNone);
WA.Selection.ParagraphFormat.Alignment:=wdAlignParagraphCenter;
WA.Selection.MoveRight(un_Var,Start_Var,ex_Var);
WA.Selection.Cells.Item(1).SetWidth(CWidth[0],wdAdjustNone);
WA.Selection.MoveRight(un_Var,Start_Var,ex_Var);
WA.Selection.Cells.Item(1).SetWidth(CWidth[2],wdAdjustNone);
WA.Selection.ParagraphFormat.Alignment:=wdAlignParagraphCenter;
WA.Selection.MoveRight(un_Var,Start_Var,ex_Var);
WA.Selection.Cells.Item(1).SetWidth(CWidth[7],wdAdjustNone);

ex_Var:=wdMove;
WA.Selection.MoveRight(un_Var,Start_Var,ex_Var);
WA.Selection.MoveRight(un_Var,Start_Var,ex_Var);
WA.Selection.Cells.Item(1).SetWidth(CWidth[0],wdAdjustNone);
WA.Selection.ParagraphFormat.Alignment:=wdAlignParagraphCenter;
WA.Selection.MoveRight(un_Var,Start_Var,ex_Var);
End_Var:=3;
ex_Var:=wdExtend;
WA.Selection.MoveRight(un_Var,End_Var,ex_Var);
WA.Selection.Cells.Merge;
WA.Selection.Cells.Item(1).SetWidth(CWidth[5],wdAdjustNone);

ex_Var:=wdMove;
WA.Selection.MoveRight(un_Var,Start_Var,ex_Var); //第八行
WA.Selection.MoveRight(un_Var,Start_Var,ex_Var);
WA.Selection.Cells.Item(1).SetWidth(CWidth[0],wdAdjustNone); //第七行
WA.Selection.ParagraphFormat.Alignment:=wdAlignParagraphCenter;
WA.Selection.MoveRight(un_Var,Start_Var,ex_Var);
End_Var:=3;
ex_Var:=wdExtend;
WA.Selection.MoveRight(un_Var,End_Var,ex_Var);
WA.Selection.Cells.Merge;
WA.Selection.Cells.Item(1).SetWidth(CWidth[5],wdAdjustNone);

ex_Var:=wdMove;
WA.Selection.MoveRight(un_Var,Start_Var,ex_Var);
WA.Selection.MoveRight(un_Var,Start_Var,ex_Var);
WA.Selection.Cells.Item(1).SetWidth(CWidth[0],wdAdjustNone); //第七行
WA.Selection.ParagraphFormat.Alignment:=wdAlignParagraphCenter;
WA.Selection.MoveRight(un_Var,Start_Var,ex_Var);
End_Var:=3;
ex_Var:=wdExtend;
WA.Selection.MoveRight(un_Var,End_Var,ex_Var);
WA.Selection.Cells.Merge;
WA.Selection.Cells.Item(1).SetWidth(CWidth[5],wdAdjustNone);
ex_Var:=wdMove;

End_Var:=3;
WA.Selection.MoveRight(un_Var,End_Var,ex_Var);

if txtOK then
WD.Tables.Item(i).Cell(2,1).Range.Text:=lblData[0]
else
WD.Tables.Item(i).Cell(2,1).Range.Text:='ID';
WD.Tables.Item(i).Cell(2,2).Range.Text:=AdoQryCompany.FieldByName('ID').AsString;
if txtOK then
WD.Tables.Item(i).Cell(2,3).Range.Text:=lblData[1]
else
WD.Tables.Item(i).Cell(2,3).Range.Text:='Name';
WD.Tables.Item(i).Cell(2,4).Range.Text:=AdoQryCompany.FieldByName('name').AsString;
if txtOK then
WD.Tables.Item(i).Cell(3,1).Range.Text:=lblData[5]
else
WD.Tables.Item(i).Cell(3,1).Range.Text:='Address';
WD.Tables.Item(i).Cell(3,2).Range.Text:=AdoQryCompany.FieldByName('address').AsString;
if txtOK then
WD.Tables.Item(i).Cell(4,1).Range.Text:=lblData[6]
else
WD.Tables.Item(i).Cell(4,1).Range.Text:='Tel';
WD.Tables.Item(i).Cell(4,2).Range.Text:=AdoQryCompany.FieldByName('tel').AsString;
if txtOK then
WD.Tables.Item(i).Cell(4,3).Range.Text:=lblData[7]
else
WD.Tables.Item(i).Cell(4,3).Range.Text:='Fax';
WD.Tables.Item(i).Cell(4,4).Range.Text:=AdoQryCompany.FieldByName('fax').AsString;
if txtOK then
WD.Tables.Item(i).Cell(4,5).Range.Text:=lblData[17]
else
WD.Tables.Item(i).Cell(4,5).Range.Text:='Post No';
WD.Tables.Item(i).Cell(4,6).Range.Text:=AdoQryCompany.FieldByName('postno').AsString;
if txtOK then
WD.Tables.Item(i).Cell(5,1).Range.Text:=lblData[8]
else
WD.Tables.Item(i).Cell(5,1).Range.Text:='LXR';
WD.Tables.Item(i).Cell(5,2).Range.Text:=AdoQryCompany.FieldByName('lxr').AsString;
if txtOK then
WD.Tables.Item(i).Cell(5,3).Range.Text:=lblData[9]
else
WD.Tables.Item(i).Cell(5,3).Range.Text:='Tel';
WD.Tables.Item(i).Cell(5,4).Range.Text:=AdoQryCompany.FieldByName('l_tel').AsString;

if txtOK then
WD.Tables.Item(i).Cell(6,1).Range.Text:=lblData[11]
else
WD.Tables.Item(i).Cell(6,1).Range.Text:='FeedBack';
WD.Tables.Item(i).Cell(6,2).Range.Text:=AdoQryCompany.FieldByName('feedback').AsString;
WD.Tables.Item(i).Cell(6,3).Range.Text:='Email';
WD.Tables.Item(i).Cell(6,4).Range.Text:=AdoQryCompany.FieldByName('email').AsString;

if txtOK then
WD.Tables.Item(i).Cell(7,1).Range.Text:=lblData[16]
else
WD.Tables.Item(i).Cell(7,1).Range.Text:='Memo';
WD.Tables.Item(i).Cell(7,2).Range.Text:=AdoQryCompany.FieldByName('memo').AsString;

if txtOK then
WD.Tables.Item(i).Cell(8,1).Range.Text:=lblData[18]
else
WD.Tables.Item(i).Cell(8,1).Range.Text:='Products';
WD.Tables.Item(i).Cell(8,2).Range.Text:=AdoQryCompany.FieldByName('products').AsString;

if txtOK then
WD.Tables.Item(i).Cell(9,1).Range.Text:=lblData[10]
else
WD.Tables.Item(i).Cell(9,1).Range.Text:='Notice';
WD.Tables.Item(i).Cell(9,2).Range.Text:=AdoQryCompany.FieldByName('notice').AsString;

Down_Var:=1;
ex_Var:=wdMove;

ex_Var:=wdMove;

AdoQryCompany.Next;
inc(i);
end;
end;
 
用scrollbar,则可搞定
 
不是太容易,试试:
把OleContainer放到ScrollBox中,
然后设置OleContainer的SizeMode属性为:smAutoSize
 
用TWebBrowser.Navigate('c:/a.doc');实现比较好
 
我怎麽也弄不出來一個ole的程序,誰有一個簡單的新建、打開、保存word文檔的例子,給我一個好嗎?
要源代碼,可以編譯的,我的mail是:newnewsky@etang.com
有用的話送分,決不食言。
謝謝!
 
> 只能显示一页的文档,太不方便了!

因为没有运行下面的语句,导致OLE实例没有激活,
OleContainer1.DoVerb(ovShow);
也可以设置autoactive 属性试试
 
用olevariant create出來的可以用,但是爲什麽我用delphi6的server component在操縱
office時卻不行。比如open一個word文檔,總是提示參數不足(即使我全部寫上),誰能
給個範例,謝謝!
 
如果用OleContainer1.DoVerb(ovShow);激活后,word的toolsbar就出来了,很不爽
 

Similar threads

后退
顶部