T
tysea
Unregistered / Unconfirmed
GUEST, unregistred user!
我的程序界面上有一个Toolbar,Toolbar上有两个button,一个“打开文档”,一个“保存文档”,一个TreeView,一个Splitter,一个OleContainer
有几个问题,查了很多资料,一直没有很好的解决,几天来一直被困扰,很是苦恼。
(1)如何在程序启动时在激活的OleContainer里Create一个空的Word文档,而不是OleContainer1.CreateObjectFromFile('C:/temp.doc',false); Container1.DoVerb(ovShow);这样打开一个指定的空文档。
(2)打开的Word工具栏是在ToolBar下独占了一行显示,怎么样才能与左边的TreeView的Top相同,不独占一行。
(3)打开两个Word文档前后Word工具栏先消失再显现出来,很不美气请问怎样才能不让工具栏刷新,一直处在正常显示状态
(4)打开文档的速度很慢,记得以前有人说启动一个Word进程(具体什么记的不是很清楚了),请问怎么启动。
单位一个老前辈的作品里这些问题都很好的处理,给人的感觉就是把Word缩小了放到OleContainer里了,可惜现在一直联系不到他,不能得到指点(555),请大家帮忙,高手指点一二,分不够我再给。
源码如下:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ComCtrls, StdCtrls, ToolWin, dxtree, ExtCtrls,
OleCtnrs, DB, ADODB;
type
TForm1 = class(TForm)
OleContainer1: TOleContainer;
Splitter1: TSplitter;
ToolBar1: TToolBar;
btnOpen: TButton;
btnSave: TButton;
ADOConnection1: TADOConnection;
DataSource1: TDataSource;
ADOQuery1: TADOQuery;
TreeView1: TTreeView;
ADOTable1: TADOTable;
procedure FormCreate(Sender: TObject);
procedure FormShow(Sender: TObject);
procedure btnOpenClick(Sender: TObject);
procedure btnSaveClick(Sender: TObject);
private
{ Private declarations }
function GetDocName: String;
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.FormCreate(Sender: TObject);
begin
OleContainer1.CreateObjectFromFile('C:/temp.doc',false);
end;
procedure TForm1.FormShow(Sender: TObject);
begin
OleContainer1.DoVerb(ovShow);
end;
function TForm1.GetDocName: String;
var
MyExePath, FileName: String;
begin
Result := '';
MyExePath := ExtractFilePath(Application.ExeName);
FileName := MyExePath + '图书文档.Doc';
try
TBlobField(ADOQuery1.FieldByName('图书文档')).SaveToFile(FileName);
Result := FileName;
except
end;
end;
procedure TForm1.btnOpenClick(Sender: TObject);
var
SqlStr: String;
begin
SqlStr := 'select * from docManager where 图书名称=' +
TreeView1.Selected.Text;
with ADOQuery1 do begin
SQL.Clear;
SQL.Add(SqlStr);
Open;
end;
if ADOQuery1.FieldByName('图书文档').AsVariant = '' then exit;
if GetDocName <> '' then begin
OleContainer1.CreateObjectFromFile(GetDocName,False);
OleContainer1.DoVerb(ovShow);
end;
end;
procedure TForm1.btnSaveClick(Sender: TObject);
var
tSaveFile, Doc_FileName: String;
begin
tSaveFile := 'C:/TempSave.DOC';
try
OleContainer1.SaveAsDocument(tSaveFile);
with ADOTable1 do begin
Edit;
Doc_FileName := TreeView1.Selected.Text;
FieldByName('图书名称').AsString:=Doc_FileName;
TBlobField(FieldByName('图书名称')).LoadFromFile(tSaveFile);
Post;
end;
except
end;
end;
end.
有几个问题,查了很多资料,一直没有很好的解决,几天来一直被困扰,很是苦恼。
(1)如何在程序启动时在激活的OleContainer里Create一个空的Word文档,而不是OleContainer1.CreateObjectFromFile('C:/temp.doc',false); Container1.DoVerb(ovShow);这样打开一个指定的空文档。
(2)打开的Word工具栏是在ToolBar下独占了一行显示,怎么样才能与左边的TreeView的Top相同,不独占一行。
(3)打开两个Word文档前后Word工具栏先消失再显现出来,很不美气请问怎样才能不让工具栏刷新,一直处在正常显示状态
(4)打开文档的速度很慢,记得以前有人说启动一个Word进程(具体什么记的不是很清楚了),请问怎么启动。
单位一个老前辈的作品里这些问题都很好的处理,给人的感觉就是把Word缩小了放到OleContainer里了,可惜现在一直联系不到他,不能得到指点(555),请大家帮忙,高手指点一二,分不够我再给。
源码如下:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ComCtrls, StdCtrls, ToolWin, dxtree, ExtCtrls,
OleCtnrs, DB, ADODB;
type
TForm1 = class(TForm)
OleContainer1: TOleContainer;
Splitter1: TSplitter;
ToolBar1: TToolBar;
btnOpen: TButton;
btnSave: TButton;
ADOConnection1: TADOConnection;
DataSource1: TDataSource;
ADOQuery1: TADOQuery;
TreeView1: TTreeView;
ADOTable1: TADOTable;
procedure FormCreate(Sender: TObject);
procedure FormShow(Sender: TObject);
procedure btnOpenClick(Sender: TObject);
procedure btnSaveClick(Sender: TObject);
private
{ Private declarations }
function GetDocName: String;
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.FormCreate(Sender: TObject);
begin
OleContainer1.CreateObjectFromFile('C:/temp.doc',false);
end;
procedure TForm1.FormShow(Sender: TObject);
begin
OleContainer1.DoVerb(ovShow);
end;
function TForm1.GetDocName: String;
var
MyExePath, FileName: String;
begin
Result := '';
MyExePath := ExtractFilePath(Application.ExeName);
FileName := MyExePath + '图书文档.Doc';
try
TBlobField(ADOQuery1.FieldByName('图书文档')).SaveToFile(FileName);
Result := FileName;
except
end;
end;
procedure TForm1.btnOpenClick(Sender: TObject);
var
SqlStr: String;
begin
SqlStr := 'select * from docManager where 图书名称=' +
TreeView1.Selected.Text;
with ADOQuery1 do begin
SQL.Clear;
SQL.Add(SqlStr);
Open;
end;
if ADOQuery1.FieldByName('图书文档').AsVariant = '' then exit;
if GetDocName <> '' then begin
OleContainer1.CreateObjectFromFile(GetDocName,False);
OleContainer1.DoVerb(ovShow);
end;
end;
procedure TForm1.btnSaveClick(Sender: TObject);
var
tSaveFile, Doc_FileName: String;
begin
tSaveFile := 'C:/TempSave.DOC';
try
OleContainer1.SaveAsDocument(tSaveFile);
with ADOTable1 do begin
Edit;
Doc_FileName := TreeView1.Selected.Text;
FieldByName('图书名称').AsString:=Doc_FileName;
TBlobField(FieldByName('图书名称')).LoadFromFile(tSaveFile);
Post;
end;
except
end;
end;
end.