views:

36

answers:

3

I have to generate winword document for badges printing application.

Basic scenario is the following: User selects employees from list, click "print badges", winword appears to allow user make some editions before printing. Badges should be represented as table with some columns. Every table cell has image background (badge), some text (company, year), user name & user photo upon the badge background. It's also required to have badge template editable for user via winword.

I'm not very fond of MS Word automation COM interfaces because they are pretty slow, tends to hang. May be I should play with winword XML document content via XML DOM. May be there is a good free library that wraps winword DOM or some libraries provided with Studio 2010 out of the box? What will you suggest?

Thank you in advance!

+2  A: 

Here's a link to the Office XML SDK for manipulating Office 2007/2010 documents.

http://msdn.microsoft.com/en-us/library/bb448854.aspx

This SDK facilitates working with Office documents without installing Word or doing COM interop, but generally seems (to me) to require a little more effort to accomplish some kinds of tasks.

kbrimington
+1 for the link... I've never even looked into that before... It still looks to me like learning it would be more work than is necessary for this simple scenario, but it's a good resource. Thank you!
David Stratton
@David-Stratton: Yeah, I hear you. It beats pounding out all the XML by hand, but lacks the elegance of COM interop.
kbrimington
+2  A: 

This may not be what you're after, but I absolutely hate automating Office (or other third party apps) from .Net code. Not only is it messy, but it's usually much more difficult than it has to be. In this case, Word has the ability to do everything except allow you to select a list of employees, so I'd go around the problem. Instead of having the app create the Word doc, I would...

  1. Set up a Word doc to use the already built-in capabilities to print name tags from a list as described here: http://www.ehow.com/how_5085472_make-name-tags-microsoft-word.html
  2. Code the program to write the data needed for the name tags to a text file, based on the employees selected in my UI.
  3. Have the program just load the Word doc and run the macro to print out the tags. (You could even do this using a System.Diagnostics.Process class for simplicity sake. That's explained in this post from another forum and this MSDN entry.)
David Stratton
+2  A: 

I'd go with Visual Studio Tools for Office for this one. You can soogle (that means "search SO" - I just made it up) the VSTO Tag on SO for it. There are pros and cons of it, like anything, but for your situation, it's exactly what you need. This page has many good articles on it the subject.

Otaku