ADO Stream and Word

S

Smalltalker

There are several articles on placing Word Documents into SQL Server and
using streams for placing them there. But what about the other way around
i.e. loading a Word Document blob from SQl Server into Word.

The only articles I have been able to find involved reading the blob and
creating a file and then loading that file into Word. Is there any object in
Word that will accept a stream contents????? If not, this would be suprising
since a Word file document uses structured storage which consists of stream
internally.

Thanks for any insights.
 
C

Cindy M -WordMVP-

Hi =?Utf-8?B?U21hbGx0YWxrZXI=?=,
There are several articles on placing Word Documents into SQL Server and
using streams for placing them there. But what about the other way around
i.e. loading a Word Document blob from SQl Server into Word.

The only articles I have been able to find involved reading the blob and
creating a file and then loading that file into Word. Is there any object in
Word that will accept a stream contents????? If not, this would be suprising
since a Word file document uses structured storage which consists of stream
internally.
No, that's not something Word supports. If you could convert it to the
Clipboard, then you could insert it into an existing Word document.

The only other possibility, if Word 2003 is involved, would be to store the
Word document as XML. Word does support inserting its native XML as a stream
into a document.

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 8 2004)
http://www.word.mvps.org

This reply is posted in the Newsgroup; please post any follow question or reply
in the newsgroup and not by e-mail :)
 
S

Smalltalker

Cindy,

Thank you for responding. I have struck an issue. Say I save a word document
as XML and load this into SQL Server. This is the complete document with
margins set for each page. I created the test macro below (currently loading
from a file to simulate the stream actions). Margins in the save document are
set as top=0.5" bottom=1" left=1" right=1". After executing the macro below
(which is intended to replace the ActiveDocument with the XML document), the
margins have NOT been changed from the default blank document which is top=1"
bottom=1" left=1.25" right="1.25". So it looks like the document has been
inserted only and does not replace the current document. Am I going about
this the wrong way? Is there another solution?

Thanks, dave

Sub Macro10()
Dim strm As New ADODB.stream
strm.Open
strm.Type = adTypeText
strm.Charset = "UTF-8"
strm.LoadFromFile "testdoc.xml"
ActiveDocument.Range(0, ActiveDocument.Characters.Count).InsertXML
xml:=strm.ReadText
End Sub
 
C

Cindy M -WordMVP-

Hi dave,

OK, I believe I understand your problem. Word documents are divided into
STORIES, or StoryRanges. For example, the headers and footers are separate
stories, so when you invoke ActiveDocument, they aren't affected. Same for
Drawing object, footnotes, etc.

The problem you're running into is that the margins aren't controlled within the
StoryRange. They're PageSetup settings, and are controlled through the SECTION.
When you replace the InnerXML, all you're affecting is the body text.

Essentially, I don't think it's possible to replace the current document with
another one by changing the XML property of the ActiveDocument. I believe you'd
have to serialize the document to disk, then open it.

*Possibly* you could get a similar looking document if you inserted a section
break at the very end of the XML document, containing the margin settings. This
section WOULD insert into the ActiveDocument, and retain those settings. Under
certain circumstances, however, the results could be... odd.
Thank you for responding. I have struck an issue. Say I save a word document
as XML and load this into SQL Server. This is the complete document with
margins set for each page. I created the test macro below (currently loading
from a file to simulate the stream actions). Margins in the save document are
set as top=0.5" bottom=1" left=1" right=1". After executing the macro below
(which is intended to replace the ActiveDocument with the XML document), the
margins have NOT been changed from the default blank document which is top=1"
bottom=1" left=1.25" right="1.25". So it looks like the document has been
inserted only and does not replace the current document. Am I going about
this the wrong way? Is there another solution?

Thanks, dave

Sub Macro10()
Dim strm As New ADODB.stream
strm.Open
strm.Type = adTypeText
strm.Charset = "UTF-8"
strm.LoadFromFile "testdoc.xml"
ActiveDocument.Range(0, ActiveDocument.Characters.Count).InsertXML
xml:=strm.ReadText
End Sub

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 8 2004)
http://www.word.mvps.org

This reply is posted in the Newsgroup; please post any follow question or reply
in the newsgroup and not by e-mail :)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top