在网页内如何很好的嵌入WORD或EXCEL(100分)

  • 主题发起人 主题发起人 PaulBlue
  • 开始时间 开始时间
P

PaulBlue

Unregistered / Unconfirmed
GUEST, unregistred user!
我想在网页中以嵌入ACTIVEX的形式嵌入WORD,
就是类似<object>..</object>的形式
可是我试了WORD.APPLICATION,好象不是的,那我该用什么GUID呢?
或者更好的提议?
 
整个文件直接访问我倒知道怎么做,你说的方式我想学学。
 
有一个pulgtogyid的函数用他可以得到guid,在在潜入网也,不知可否
 
用WebBrowser
 
yuedaxia:

愿闻其详
 
StringToGUID('word.application')StringToGUID('word.basic')可以得到guid
当然也可以自己到注册表查询
 
可以用画中画的方法,在web页面中嵌入一个小的浏览器,小画面显示需要的word文档;代码如下:
<object id="browserIcons"
classid="clsid:EAB22AC3-30C1-11CF-A7EB-0000C05BAE0B"
align="baseline" border="0" width="452" height="161">
<param name="ExtentX" value="11959">
<param name="ExtentY" value="4260">
<param name="ViewMode" value="1">
<param name="Offline" value="0">
<param name="Silent" value="0">
<param name="RegisterAsBrowser" value="0">
<param name="RegisterAsDropTarget" value="0">
<param name="Height" value="361">
<param name="Width" value="652">
<param name="AutoArrange" value="0">
<param name="NoClientEdge" value="0">
<param name="AlignLeft" value="1">
<param name="ViewID" value="{0057D0E0-3573-11CF-AE69-08002B2E1262}">
<param name="Location" value="http://localhost/test.doc">
</object>
 
多谢指点,试验成功,但是还有些问题:
1.打开WORD文档后,关闭浏览器窗口时很容易出现非法操作,
不知原因何在,是否有解决办法?

2.在浏览器中直接打开WORD文档时,浏览器菜单会自动变成
WORD菜单,但用嵌入式浏览器就不会有,那在两种情况下,如果
我想自定义显示WORD的菜单和控制是否显示工具栏,该怎么作呢?

3.我的本意是在服务器上开辟一个只读目录来放各种文档的模板,在
浏览器中打开模板后,用户进行编辑,保存的时候并不改动只读目录里的
模板,而是由程序自动将文件内容以特定名字存入数据库中,这在原先传统的
调用WORD.Application启动WORD的执行方式中很容易做到,而在目前这种
浏览器嵌入WORD的情况下,这种方式可能行不通,因为这个WORD并不是
一个实际的嵌入式ActiveX对象,所以我找不到接口,那我该怎么办呢?
 
to:PaulBlue
你的第三个想法我也曾经试过,不过没有成功。
我认为比较可行的办法是用OleContainer来实现。

另外有一位高手提供了一个DBOleContainer控件,你可以实验一下,如果成功的话,把你的代码也
给我mail一份:watter@sina.com

控件DBOleContainer的单元文件代码:

unit DBOleContainer;

interface

uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
OleCtnrs, DB, DBCtrls, dbtables;

type
TDBOleContainer = class(TOleContainer)
private
FFixedOleClassName : String;
FConfirmDelete:Boolean;
FDataLink :TFieldDataLink;
FLocked: Boolean
FOLEEditing:Boolean;
procedure DataChange(Sender :TObject);
function GetDataField:string;
function GetDataSource:TDataSource;
function GetField:TField;
function GetReadOnly: Boolean;
procedure SetDataField(Value:string);
procedure SetDataSource(Value:TDataSource);
procedure SetReadOnly(Value:Boolean);
procedure UpdateData(Sender :TObject);
procedure CMExit(var Message:TWMNoParams);MESSAGE CM_Exit;
protected
procedure Changed;override;
procedure DblClick;override;
procedure Notification(AComponent: TComponent;
Operation: TOperation)
override;
public
property Field:TField read GetField;
constructor Create(Owner:TComponent);override;
destructor Destroy;override;
procedure Active;
procedure KeyUp(var Key: Word
Shift: TShiftState)
override;
published
property ConfirmDelete:Boolean read FConfirmDelete write FConfirmDelete default True;
property DataField:string read GetDataField write SetDataField;
property DataSource:TDataSource read GetDataSource write SetDataSource;
property ReadOnly:Boolean read GetReadOnly write SetReadOnly default false;
end;

procedure Register;

implementation


procedure Register;
begin
RegisterComponents('User Controls', [TDBOleContainer]);
end;

//---------------------------------------------------------------------------
constructor TDBOleContainer.Create(Owner:TComponent);
begin
inherited Create(Owner);
ConfirmDelete:=True;
ControlStyle := ControlStyle + [csReplicatable];
FDataLink := TFieldDataLink.create;
FDataLink.Control := self;
FDataLink.OnDataChange := DataChange;
FDataLink.OnUpdateData := UpdateData;

AllowInPlace:=False;
FLocked:=False;
FOLEEditing:=False;
FFixedOleClassName:='';
end;
//---------------------------------------------------------------------------
destructor TDBOleContainer.Destroy;
begin
FDataLink.Control := nil;
FDataLink.OnDataChange := nil;
FDataLink.OnUpdateData := nil;
FDataLink.free;

inherited Destroy;
end;
//---------------------------------------------------------------------------
procedure TDBOleContainer.Changed;
begin
if FOLEEditing then Exit;
if (csDesigning in ComponentState) then
FFixedOleClassName:=inherited OleClassName
else if not FLocked then
begin
if FDataLink.Active and (not FDataLink.ReadOnly) then
begin
if not FDataLink.Editing then
begin
FDataLink.OnDataChange := nil;
FDataLink.Edit;
FDataLink.OnDataChange := DataChange;
end;
if FDataLink.Editing then
begin
FDataLink.Modified;
inherited Changed;
end
else
DataChange(nil);
end
else
DataChange(nil);
end;
end;

procedure TDBOleContainer.Active;
begin
if not (State in [osEmpty]) then
begin
FDataLink.OnDataChange := nil;
try
DoVerb(ovShow);
except
FDataLink.DataSet.Edit;
try
DoVerb(ovShow);
except
end;
end;
FDataLink.OnDataChange := DataChange;
end
else (*if FDataLink.CanModify and InsertObjectDialog then
begin
if not FDataLink.Editing then
begin
FDataLink.OnDataChange := nil;
FDataLink.Edit;
FDataLink.OnDataChange := DataChange;
end;
DoVerb(ovShow);
end;
*)
if FDataLink.CanModify then
begin
FOLEEditing:=True;
if InsertObjectDialog then
begin
inherited DblClick;
if not FDataLink.Editing then
begin
FDataLink.OnDataChange := nil;
FDataLink.Edit;
FDataLink.OnDataChange := DataChange;
end;
end;
FOLEEditing:=False;
Changed;
end;
end;
//---------------------------------------------------------------------------
procedure TDBOleContainer.DblClick;
begin
{$IFDEF OLD_VER}
if not (State in [osEmpty]) then
DoVerb(ovShow)
else
begin
if FDataLink.CanModify and InsertObjectDialog then
begin
inherited DblClick;
if not FDataLink.Editing then
begin
FDataLink.OnDataChange := nil;
FDataLink.Edit;
FDataLink.OnDataChange := DataChange;
end;
end;
end;
{$ELSE}
if not (State in [osEmpty]) then
DoVerb(ovShow)
else
begin
if FDataLink.CanModify then
begin
FOLEEditing:=True;
if InsertObjectDialog then
begin
inherited DblClick;
if not FDataLink.Editing then
begin
FDataLink.OnDataChange := nil;
FDataLink.Edit;
FDataLink.OnDataChange := DataChange;
end;
end;
FOLEEditing:=False;
Changed;
end;
end;
{$ENDIF}
end;
//---------------------------------------------------------------------------
procedure TDBOleContainer.DataChange(Sender :TObject);
var
Stream: TStream;
begin
if (csDesigning in ComponentState) then exit;

FLocked:=True;
Self.Iconic:=False;
Self.AllowInPlace:=False;
if not (State in [osEmpty]) then
Self.DestroyObject;
if FDataLink.Active and Assigned(FDataLink.Field) and
(not FDataLink.Field.IsNull) and (FDataLink.Field.IsBlob) then
begin
Stream:=FDataLink.DataSet.CreateBlobStream(FDataLink.Field,bmRead);
try
LoadFromStream(Stream);
except
end;
Stream.Free;
end
else if (FFixedOleClassName<>'') then
CreateObject(FFixedOleClassName,Self.Iconic);
Self.Modified:=False;
Self.Iconic:=False;
FLocked:=False;
end;
//---------------------------------------------------------------------------
function TDBOleContainer.GetDataField:string;
begin
result := FDataLink.FieldName;
end;
//---------------------------------------------------------------------------
function TDBOleContainer.GetDataSource:TDataSource;
begin
result :=FDataLink.DataSource;
end;
//---------------------------------------------------------------------------
function TDBOleContainer.GetField:TField;
begin
result := FDataLink.Field;
end;
//---------------------------------------------------------------------------
function TDBOleContainer.GetReadOnly: Boolean;
begin
Result:=FDataLink.ReadOnly;
end;
//---------------------------------------------------------------------------
procedure TDBOleContainer.SetDataField(Value:string);
begin
FDataLink.FieldName := Value;
end;

//---------------------------------------------------------------------------
procedure TDBOleContainer.KeyUp(var Key: Word
Shift: TShiftState);
begin
if(Key in [VK_DELETE,VK_SPACE]) and (not (State in [osEmpty])) and
(not FDataLink.ReadOnly) and FDataLink.CanModify and FConfirmDelete and
(Application.MessageBox('删除OLE文档内容?','确认',
MB_YESNO+MB_DEFBUTTON1+MB_ICONQUESTION)=IDYES) then
begin
if not FDataLink.Editing then
begin
FDataLink.OnDataChange := nil;
FDataLink.Edit;
FDataLink.OnDataChange := DataChange;
end;
if FDataLink.Editing then
begin
Self.DestroyObject;
FDataLink.Modified;
end;
end;
inherited;
end;
//---------------------------------------------------------------------------
procedure TDBOleContainer.SetDataSource(Value:TDataSource);
begin
if (Value <> nil) then
Value.FreeNotification(self);
FDataLink.DataSource := Value;
end;
//---------------------------------------------------------------------------
procedure TDBOleContainer.SetReadOnly(Value:Boolean);
begin
FDataLink.ReadOnly:=Value;
end;
//---------------------------------------------------------------------------
procedure TDBOleContainer.UpdateData(Sender :TObject);
var
Stream: TStream;
begin
if (FDataLink.Field.IsBlob) and FDataLink.DataSource.AutoEdit then
begin
if State in [osEmpty] then
Field.Clear
else
begin
Stream:=FDataLink.DataSet.CreateBlobStream(FDataLink.Field,bmReadWrite);
try
SaveToStream(Stream);
finally
Stream.Free;
end;
end;
end;
end;
//---------------------------------------------------------------------------
procedure TDBOleContainer.CMExit(var Message:TWMNoParams);
begin
try
FDataLink.UpdateRecord;
except
if CanFocus then
SetFocus;
raise;
end;
end;
//---------------------------------------------------------------------------
procedure TDBOleContainer.Notification(AComponent: TComponent;
Operation: TOperation);
begin
inherited Notification(AComponent, Operation);
if (Operation = opRemove) and (FDataLink <> nil) and
(AComponent = DataSource) then DataSource := nil;
end;

end.
 
我试一试吧,不过我也想知道不与DELPHI无关的解决办法
 
接受答案了.
 
后退
顶部