Use a Document Template (.dotx) as Base for GenerateDocument

Jul 22, 2012 at 3:15 AM

Is possible to use a .dotx as source for the Export to Word?

Aug 2, 2012 at 1:58 PM

Technically, you can use a dotx as a source for GenerateDocument, but the process will modify the template rather than create a new document based on the template (which I'm assuming is your desired outcome). GenerateDocument doesn't save the document however. So, as a workaround, you could use GenerateDocument (which returns a Document object) and then, in your LightSwitch code, use Word's Document.SaveAs method to save it to the correct format.




Aug 3, 2012 at 4:21 PM

Any chance this became a feature for future Version?

Aug 3, 2012 at 4:42 PM

Sure - we're currently evaluating ideas for another release. I'll add this to the list.

Apr 6, 2013 at 10:43 PM
Can't believe I"m stumped by what should be so simple a thing as implementing "save as" for a Word docx or dotx. Could someone kindly post a few lines of sample code as to how we can save or saveas the word document that is returned by GenerateDocument?

The Office Integration Pack is very helpful and can't complain about the price, but why it has a method to save as a pdf but not a Word document is very curious. Any help here would be much appreciated. Thanks.
Apr 7, 2013 at 12:03 AM
Edited Apr 7, 2013 at 1:51 PM
If you want to use a .dotx file as source for GenerateDocument to create a new docx, make sure that the saveas method has the correct file format as the second parameter. The correct fileformat parameter for docx is wdFormatXMLDocument, which is a const equivalent to the number 12.
Dim doc As Object = OfficeIntegration.Word.GenerateDocument(wordFile, Me.Visit, custFields)
Dim word = OfficeIntegration.Word.GetWord
doc.saveas(myDocs & "\WordExportTest\mytesting3.docx", 12)
I'm using VS 2012 Lightswitch and Word 2013. While the saveas method apparently works to save a .docx file from a source .dotx without the fileformat parameter, that file will not open successfully in Word. (At least it wouldn't for me.) If your source for GenerateDocument is a .docx, then everything works fine without the fileformat parameter.