Dirk586818

Hello all,

I have a question reguarding InsertXML().

I am working with VS 2005, Office 2003.

I am trying to stream a document from a database. The database is SQL 2000. My goal is to actually display the Word document in my application. In order to do this I am using the DSOFramer control. The control, so far, has worked great - and it has an ActiveDocument property that allows me to get ahold of a Word.Document object. The only issue is that the page setting do not come back.

Here is what I do:

'// This causes the DSOFramer to create a new word document

mDsoFramer.CreateNew("Word.Document")

'// Grab a reference to the word document

Dim doc as Word.Document = Ctype(mDsoFramer.ActiveDocument, Word.Document)

doc.Range.InsertXML(my_xml_variable)

The "my_xml_variable" holds the XML streamed from the database. I am very sure the XML is formatted properly because I first saved it by examining the document's XML property.. For example,

Dim app as new Word.Application

Dim doc as Word.Document = app.Open("C:\some actual word document.doc")

Dim save_this_xml as String = doc.Range.XML

the "save_this_xml" is what I save to the SQL database.

Like I said, this all works, except the page settings do not come back. If I write the xml to a text file, and then open it with Word, it all works fine, page settings and all. Even opening the text in notepad shows that the tags for the margins ARE there.

I think that when I tell the DSOFramer to create a new word document.

mDsoFramer.CreateNew("Word.Document")

it is reading the Normal.dot settings,... but the InsertXML never overwrites them. Is there a way to overwrite the ENTIRE word document with InsertXML

Thanks,

Dirk



Re: Visual Studio Tools for Office InsertXML and the page settings

Cindy Meister

This behavior comes from the way Word handles certain formatting: margins, headers, footers, page size, orientation are all section-level formatting. This is stored in section breaks (Insert/Break).

One possibility is to place a (continuous) section break at the beginning of the source document (the XML). This will maintain the section level formatting when you insert the XML, and after insertion the break can be removed.

An alternate approach would be to use XPath to read the formatting from the XML and apply it to the resulting document using Automation.






Re: Visual Studio Tools for Office InsertXML and the page settings

Dirk

Interesting!

The second option sounds better to me. Maybe its because of my inexperience with this, but editing the XML coming from the database to include a section break, sounds like more of a trial and error/debugging experience.

However, I *know* for a fact that once the document is in place I can change the margins and page setting all I want. Actually, I can do this before the InsertXML takes place and it applies to the entire document:

doc.Range.PageSetup.RightMargin = 0 works fine for example.

However, I am unfamilar with "use XPath".. this a property, member, another class Sorry for my inexperience.

Dirk





Re: Visual Studio Tools for Office InsertXML and the page settings

Cindy Meister

Hi Dirk

XPath is the way to "parse" an XML file to extract information from a certain set of xml tags. Basically, you say get me the information from this "path" to the elements I want to access. This is part of XML, not of Word, Office or VSTO.






Re: Visual Studio Tools for Office InsertXML and the page settings

Dirk

Thanks!

I'll look into this method.

Dirk





Re: Visual Studio Tools for Office InsertXML and the page settings

Dirk

Update!

Using some of the XML .NET classes, I was able to extract the elements from the XML document and re-apply them in the DSOFramer. This method worked.

Dirk





Re: Visual Studio Tools for Office InsertXML and the page settings

Cindy Meister

Thanks for the confirmation. Glad you're up and running!