procedure Tfrmdyqk1.BitBtn2Click(Sender: TObject);
用一个Opendialog控件!
begin
if Opendialog1.execute then
begin
OleContainer1.CreateObjectFromFile(OpenDialog1.FileName,false);
Olecontainer1.Doverb(ovShow);
// OleContainer1.Run;
end;
end;
用一个Opendialog控件!
begin
if Opendialog1.execute then
begin
OleContainer1.CreateObjectFromFile(OpenDialog1.FileName,false);
Olecontainer1.Doverb(ovShow);
// OleContainer1.Run;
end;
end;
解决方案 »
- 求助:ListView_GetSubItemRect 在Delphi中编译报错:Undeclared identifier: 'ListView_GetSubItemRect'
- 我如何才能在DELPHI下面看到VCL的源代码呢?
- 我想问一下在那本书里有关于动态连接数据库的讲座?
- 各位高手快快进来!帮忙看一下这个问题.这是同一个问题开的第二个贴子了!总分有150分!不够再加!
- 非常急,调用.dll不返回值,也不提示错误
- 怎么才能给Listview中的每一行都加一个图标,怎样引用Listview中每一行???
- 如何对QReport进行修改
- 都进来看看这种算法!!哈哈哈
- 为什么我在TADODataSet中加入计算字段失败的?!
- 请问:adoquery不支持@@identity操作吗?
- !!!记录过滤问题,还是搞不明白
- 关于DELPHI的网络编程,大家近来讨论讨论啊
现成的例子,自己看吧。
我说第一种巴:
在form上放一个TWordApplication,TWordDocument
WordApplication1.Visible:=True;
WordDocument1.ConnectTo(WordApplication1.ActiveDocument);//喆是连接当前文件!
begin
if not Assigned(WordObject) then begin
WordObject := TWordObject.Create;
with WordObject do begin
Caption := 'Delphi is RAD!';
Visible := True;
OnQuit := AppQuit;
OnDocumentChange := AppDocumentChange;
OnNewDocument := DocNew;
OnOpenDocument := DocOpen;
OnCloseDocument := DocClose;
end;
LaunchButton.Enabled := False;
CloseButton.Enabled := True;
NewDocButton.Enabled := True;
end;
end;procedure TForm1.NewDocButtonClick(Sender: TObject);
begin
if opendialog1.Execute then
try
WordObject.NewDoc(opendialog1.FileName);
except
ShowMessage('It seems like somebody killed Word and didn''t tell me about it...');
if Assigned(WordObject) then begin
LaunchButton.Enabled := True;
CloseButton.Enabled := False;
NewDocButton.Enabled := False;
TypeTextButton.Enabled := False;
WordObject.Free;
WordObject := nil;
end;
end;
end;
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
Buttons, Word97, OleServer;type
TForm1 = class(TForm)
App: TWordApplication;
Doc: TWordDocument;
SpeedButton1: TSpeedButton;
SpeedButton2: TSpeedButton;
SpeedButton3: TSpeedButton;
SpeedButton4: TSpeedButton;
SpeedButton5: TSpeedButton;
odDoc: TOpenDialog;
SpeedButton6: TSpeedButton;
procedure SpeedButton1Click(Sender: TObject);
procedure SpeedButton2Click(Sender: TObject);
procedure SpeedButton3Click(Sender: TObject);
procedure SpeedButton4Click(Sender: TObject);
procedure SpeedButton5Click(Sender: TObject);
procedure SpeedButton6Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;var
Form1: TForm1;implementation{$R *.DFM}procedure TForm1.SpeedButton1Click(Sender: TObject);
begin
APP.Connect;
app.Visible := true;
end;procedure TForm1.SpeedButton2Click(Sender: TObject);
var Index,sFile,bFlag:OleVariant;
begin
if odDoc.Execute then
begin
sFile:=odDoc.FileName;
bFlag := False;
App.Documents.Open(sFile,bFlag,EmptyParam,EmptyParam,EmptyParam,EmptyParam,EmptyParam,EmptyParam,EmptyParam,EmptyParam);
index :=1;
Doc.ConnectTo(App.Documents.Item(index));
end
else
begin
///Documents.Add DocumentType:=wdNewBlankDocument
// ShowVisualBasicEditor = True
///
app.Documents.Add(EmptyParam,EmptyParam);
end;
end;procedure TForm1.SpeedButton3Click(Sender: TObject);
begin
Doc.PrintPreview;
end;procedure TForm1.SpeedButton4Click(Sender: TObject);
begin
// Selection.TypeText Text:="uiyuiyuiyuiyuyuyui"
///这是我录的插入字符的宏
// 思想:宏转换在 vb转换要容易些
app.Selection.TypeText('dfjalfda;fdsajfla');end;procedure TForm1.SpeedButton5Click(Sender: TObject);
var
LinkToFile, SaveWithDocument:OleVariant;
begin
// Selection.InlineShapes.AddPicture FileName:="F:\新建文件夹 (2)\BLOW4.JPG", _
// LinkToFile:=False, SaveWithDocument:=True
odDoc.FileName :='F:\新建文件夹 (2)\BLOW4.JPG';
if odDoc.Execute then
begin
LinkToFile:=False; SaveWithDocument:=True;
app.Selection.InlineShapes.AddPicture(odDoc.FileName,LinkToFile,SaveWithDocument,EmptyParam); end;
{插入表格也类是 用range 可以控制插入的位置}
end;procedure TForm1.SpeedButton6Click(Sender: TObject);
var
append,FileName, Range, Item, Copies, Pages, PageType , ManualDuplexPrint
, Collate, Background, PrintToFile , PrintZoomColumn, from,to_ ,
PrintZoomRow, PrintZoomPaperWidth, PrintZoomPaperHeight:OleVariant;begin
{'
' Macro3 Macro
' 宏在 2001-7-24 由 yj 录制
'
Application.PrintOut FileName:="", Range:=wdPrintRangeOfPages, Item:= _
wdPrintDocumentContent, Copies:=1, Pages:="11", PageType:=wdPrintAllPages _
, ManualDuplexPrint:=False, Collate:=True, Background:=True, PrintToFile _
:=False, PrintZoomColumn:=0, PrintZoomRow:=0, PrintZoomPaperWidth:=0, _
PrintZoomPaperHeight:=0
}
FileName:=''; Range:='wdPrintRangeOfPages'; Item:='wdPrintDocumentContent';
Copies:=1; Pages:=2; PageType:='wdPrintAllPages';
ManualDuplexPrint:=False; Collate:=True; Background:=True; PrintToFile :=False; PrintZoomColumn:=0; PrintZoomRow:=0;
PrintZoomPaperWidth:=0;
PrintZoomPaperHeight:=0 ;
append:=false;
from:=2;
to_:=2;
app.PrintOut(Background,Append , Range, filename, from, to_, Item, Copies, Pages, PageType, PrintToFile, Collate, FileName, EmptyParam, ManualDuplexPrint)//, PrintZoomColumn, PrintZoomRow, PrintZoomPaperWidth, PrintZoomPaperHeight) {(Background,EmptyParam,EmptyParam,filename,EmptyParam,
EmptyParam,EmptyParam,EmptyParam,pages,EmptyParam,EmptyParam);}
end;end.
另外值得注意的是你的word应用程序的路径若不是默认安装的路径,那么在倒数第二个参数要指定word应用程序路径!