Managing WinWord document content for badges printing application. Best practice
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!
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.
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...
- 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
- Code the program to write the data needed for the name tags to a text file, based on the employees selected in my UI.
- 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.)
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.
精彩评论