Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Load MSWord from a memory file

375 views
Skip to first unread message

GW

unread,
Jun 9, 2003, 2:53:09 PM6/9/03
to
In Delphi 7pro, I need to open and view a Word document in MSWord from
memory (binary stream-retrieved from database). In the past, for lacking a
better way of doing it, I just saved the stream to a temp file and then ask
MSWord to open the temp file. I think there must be a way of sending the
stream directly from memory to Word, sort of a loadFromStream method. Can
anyone help? Thanks.

--George


Oliver Townshend

unread,
Jun 9, 2003, 8:28:41 PM6/9/03
to

Loading from a temp file is the best you can get if you use Word.

Oliver Townshend


Mike Shkolnik

unread,
Jun 10, 2003, 5:58:14 AM6/10/03
to
You may use TOLEContainer and load a document from any stream (including
memory stream)

--
With best regards, Mike Shkolnik
EMail: mshk...@scalabium.com
http://www.scalabium.com

"GW" <georg...@justice.com> сообщил/сообщила в новостях следующее:
news:3ee4d793$1...@newsgroups.borland.com...

Mike Manning

unread,
Jun 10, 2003, 7:57:43 AM6/10/03
to

Hi George
I had the same problem last year and thought there must be an answer, but
couldn't find one (didn't want to use TOLEContainer - wanted to open Word
itself).
I also tried loading from the database into TMemoryStream, then
TMemoryStream to clipboard, then paste to the Word Doc.
From memory there were some problems with that relating to clipboard formats
and I ended up loading from a file.
If you find a better way let us know.
Mike M


"GW" <georg...@justice.com> wrote in message
news:3ee4d793$1...@newsgroups.borland.com...

GW

unread,
Jun 10, 2003, 10:23:21 AM6/10/03
to
Thank you all for your response. I guess MS just doesn't want to expose a
method which is really useful (in my view, anyway). -George

"Mike Manning" <NOMOR...@nowhere.com.au> wrote in message
news:3ee5c738$1...@newsgroups.borland.com...

GW

unread,
Jun 10, 2003, 10:39:28 AM6/10/03
to
Mike,
Thank you for the suggestion of using TOLEContainer. As I have never tried
this COM, I'd appreciate it very much, if you would provide me some
exemplary usage of this object (if you have some available). Thanks.

--George

"Mike Shkolnik" <mshkol...@ukr.net> wrote in message
news:3ee5...@newsgroups.borland.com...

Marin Atanasov

unread,
Jun 27, 2003, 7:12:44 AM6/27/03
to
Hi, George!
Hope, I'm not too late with the answer.

Yes, MSWord cannot load it's document from any place, but the file.
But!
I solved problem, getting different point of view on it.
I needed to Hold documents in a database, but their sources(originals) are
word files.
So I read them and put in the database, so I can read them back later.

Here you are some code illustrating my words, because my English is too bad
:

Assume that:
"OLE1" is an OLEContainer.

===== 1 ====== Opening DOC file and saving it into database :

procedure TfrmMain.DocFileImport(aFileName: String; Qry: TQuery);
var
BlobMemStream:TMemoryStream;
.....
begin
OLE1.CreateObjectFromFile(aFileName,false);
OLE1.Close;
BlobMemStream:=TMemoryStream.Create;
OLE1.SaveToStream(BlobMemStream);
BlobMemStream.Seek( 0, soFromBeginning);

With uQry do
begin
Close;
SQL.Text := 'INSERT INTO MyTable VALUES ( :docBody)';
ParamByName(aParamName).LoadFromStream(aStream, ftBlob);
ExecSQL;
FreeAndNil(BlobMemStream);
end;
end;

===== 2 ====== Loading DOC from database in OLEContainer :
Procedure LoadDatabaseDoc( Qry : TQuery);
Var
MemBlobStream : TStream;
begin
With Qry do
begin
Close;
SQL.Text := 'SELECT docBody FROM MyTable';
Open;
try
try

MemBlobStream:=Qry.CreateBlobStream(Qry1.FieldByName('advTemplateBody'),bmRe
ad);
MemBlobStream.Seek( 0, soFromBeginning);
OLE1.LoadFromStream( MemBlobStream);
finally
FreeAndNil( MemBlobStream);
end;
finally
Close;
end;
end;

In other words, you save OLEContainer's content to stream which is OLE
Header + OLE Document, which gives you ability to load it later. Word as an
application cannot load document from stream, but OLEContainer can read any
ole object data and construct ole object depending on data. (of course OLE
Server must present in order to edit document e.g. you must have Word
installed on the computer which need to run your program if program requires
document editing).

Hope, it will help you,
Marin


"GW" <georg...@justice.com> wrote in message
news:3ee4d793$1...@newsgroups.borland.com...

0 new messages