Does WDG work with templates .docm?

Apr 29, 2013 at 9:23 PM
Edited Apr 30, 2013 at 5:57 PM
I have defined a macro to remove placeholders after template proccessing (on file openning event).

But... the Word 2007 does not open the resulting file, it looks like corrupted.

Are there any restrictions on using macros?
May 6, 2013 at 5:32 PM
Replying myself:
Since WDG can read macro enabled documents, and it generates "non macro-enable", I achieve the expected result just by changing the result document to macro-enabled and everything just worked fine.
byte[] bytes = sampleGenericDocumentGeneratorUsingXml.GenerateDocument();
            if (templateName.ToLower().EndsWith(".docm"))
            {
                using (MemoryStream mem = new MemoryStream())
                {
                    mem.Write(bytes, 0, (int)bytes.Length);
                    using (WordprocessingDocument document = WordprocessingDocument.Open(mem, true))
                    {
                        document.ChangeDocumentType(WordprocessingDocumentType.MacroEnabledDocument);
                    }
                    bytes = mem.ToArray();
                }
            }
Enjoy!
May 6, 2013 at 5:36 PM
The best thing, however, would be WDG (Word Doc Generator) produces output based on template type (.DOCX or .DOCM) and not assume the resulting will always be .DOCX. In this case, the above code would be removed.

That´s my sugestion for while.

Best regards,

Thiago.