Coding Infopath to Word

K

K''''ur

Hi,

Is it possible to take the Template.XML file of the infopath form and
convert that into MS word format, completely by custom coding but by an
automated process. What we want is:

- Create an infopath form which will be populated with variety of data
coming from differeent sources through webservices.

- Once the form is opened the user will be able to add in some of his/her
own data to certain fields

- After that we would like to store the infopath form as it is (i.e. with
whatever data is filled) in infopath format and a button which will generate
a customized .doc file of the form with the filled data.

How do we do this. A detailed answer will be greatly appreciated.
Thanks,
Keyur Shah
 
G

G. Tarazi

If it is just normal fields, yes



Once you have rich text boxes, repeatable sections, etc, ... forget it :)
 
K

K''''ur

Hi, I would greatly appreciate if you could be little more specific. I need
to explain this to someone else.

Thanks in anticipation,
Keyur
 
T

Tim Larson

This is possible.
1) Add a button to your IP form.
2) Add managed code to open a word application object.
Private wordApp As Microsoft.Office.Interop.Word.Application
Private wordDoc As Microsoft.Office.Interop.Word.Document

<InfoPathEventHandler(MatchPath:="launch_Word",
EventType:=InfoPathEventType.OnClick)> _
Public Sub launch_Word(ByVal e As DocActionEvent)
'save file file so it can be opened by Word. Cannot have it open in IP and
Word 'simulataneously
thisXDocument.SaveAs(pathway + thisFilename + ".xml")
'save file again IP but in another name
thisXDocument.SaveAs(pathway + thisFilename + DOVString + ".xml")
Try
wordDoc = wordApp.Documents.Open(pathway + thisFilename +
".xml")
Catch ex As Exception
'so you don't get multipal wordapp objects open
wordApp = CType(CreateObject("Word.Application"),
Microsoft.Office.Interop.Word.Application)
wordDoc = wordApp.Documents.Open(pathway + thisFilename +
".xml")
End Try
wordDoc.SaveAs(pathway + "word files\" + thisFilename +
DOVString + ".doc")
wordDoc.Application.Visible = True
wordDoc.ActiveWindow.Activate()
end sub

3) word will open the xml file But you have to have: added the IP schema
(usually mySchema.xsd) to the Word thru the Tools menu drop down -> the
templates and add-ins as well your .xsl file that uses wordML to translate
the .xml file generated by IP. You add this .xsl file through the schema
library. Select mySchema then add solution and then browse to your .xsl file.

Lastly I know I had to get permissions as a trusted source for the managed
code to be opening Word. that is another topic and it is addressed elsewhere.

Hope this helps
 
G

G. Tarazi

Ok, here is a bit more about Word and InfoPath compatibility.



Ok, let's start from the beginning, the InfoPath Form, is an xslt template
that receives an XML file and generates an HTML file.



The InfoPath product, is Internet Explorer enhanced, redesigned to view
these html files the way you see them in the product (using mshtml.dll).



Microsoft Word is a document processing product; it has some internal
presentation language to describe how the document looks like.



Microsoft created an XML implementation of this language, and now it is
called Word ML, and there is an internal hidden converter from Word ML to
the internal document language of Word (inside the product itself).



In other words, when you double click the WordML file, an internal
conversion is happening immediately from Word ML to whatever that product
uses.



Now about compatibility.



InfoPath stores the data of the rich text boxes as XHTML, Microsoft WordML
has no clue of how to display XHTML, Microsoft Word itself has a basic idea,
but not able to do that correctly either.



In other words, if you build the WordML file manually, and inject the XHTML
inside, Word won't be able to display it.

And if you call word directly (using the word object module), and use it to
transform the XHTML (the contents of the rich text box), you will get a
crappie transformation, missing contents, or improperly aligned tables,
or ... you name it, they have it.



In other words, the nicely formatted contents of InfoPath, are not nicely
formatted in Word after the transformation (if you get it to work).



And that was just about one type of fields only



Now take this to the rest of the product, and you will find a different
problem with each filed, either minor, or major.



I just don't understand the product managers of Office when they talk about
computability of the office products, and how can you use InfoPath and Word
together, yeh right, good luck :)
 
K

K''''ur

Thanks a lot to all of you. I will try with all this different options, and
might have more questions. hopefully not.

Thanks again,
Keyur
 

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