It’s not exactly like it’s something that hasn’t been solved in the past but in my experience people usually solve it for a solution “not what we’ve been missing around the office”. Here’s what we wanted it to do:
- Generate Microsoft Word documents programmatically.
- Generation is through a MVC 3/4(whatever) website. Basically ASP.NET
- Generate without installing Office on the server which is a big no-no that people typically end up ignoring and gambling with.
- Do it in a way that you can teach someone else to support and reproduce easily.
Well I solved it through delegation. By delegation I mean myself and the other developer lead had taken seperate 1-2 day stabs at the problem before we got overrun with business as usual and we finally got another resource we could delegate it to without his time getting consumed by some panicked manager worried about XYZ business owner on product ABC. I handed him the problem with a few possible solutions such as Open XML, Infragistics, Telerik, Automation Factory and some others who’s memory I’ve probably already drank away by now.
Well after a week or so of research our guy came up with using this:
Open XML SDK 2.0 for Microsoft Office (specifically the Open XML SDK Tool but yeah you probably want it all)
It works. Essentially you template out whatever you’re trying to produce in Microsoft Word and then run it through this tool. It will produce the C# code you need as a starting point to produce the documents you need. It’s great and head and shoulders over the Open XML tutorials/examples I’ve seen out there that only show you how to self code a 4 line Word document. You still have to doctor it some since it only produces code for the document you’ve templated out but it gives you an in depth starting point and really lays out some of the “layered” aspects of generating Word objects.
At a later date I hope to piece together an actual demo but for now this should help anyone with the same problem.