Question

Given a list of mailing addresses, I need to open an existing Word document, which is formatted for printing labels, and then insert each address into a different cell of the table. The current solution opens the Word application and moves the cursor to insert the text. However, after reading about the security issues and problems associated with opening the newer versions of Word from a web application, I have decided that I need to use another method.

I have looked into using Office Open XML, but I have not found any good resources that provide concrete information on exactly how to use it. Also, someone suggested that I use SQL reporting services, but searching for information on how to use them, lead me nowhere.

Which method do you think is the most appropriate for my problem?

Code samples and links to good tutorials would be extremely helpful.

Was it helpful?

Solution

Thanks for all the answers, but I really did not want to pay for a plugin and using Word automation was out of the question. So I kept searching and eventually, through some trial and error, found some answers.

After throughly searching through Microsoft's site, I found some newer articles on the Office Open XML SDK. I downloaded the new tools and just started going through each them.

I then found the Document Reflector, which creates a class to generate XML code based off an existing Word Document (.docx). Using my Label Template Document and the code this tool generated, I went through and added a loop that appends table cells for each address. It actually proved to be fairly simple and way faster than using Word automation.

So, if you're still using Word automation check out the Office Open XML tools. Their surprisingly extensive for a free download from Microsoft.

Office Open XML SDK 2.0 Download

OTHER TIPS

I use the Words plugin from Aspose.com to do mail merges (programming guide).

You can take a look show 137 and 138 on dnrTV (www.dnrtv.com). In these video's Beth Massi shows how to do some editing and mail merging with OpenXML. She does this by using the Open XML SDK and xml literals in VB. It requires no third party components. Also it doesn't require MS Office to be installed on the machine.

This video inspired me as a C# developed (and no VB experience) to do some XML manipulation in a separate dll in VB. I call into this dll from my C# application.

It is worth a try.

We have the product Aspose that tvanfosson has mentioned. The edition that we purchased works with SQL Reporting Services so it can be used with the scheduler for creating output. It is really a great product and we used in a system that needed to support Korean characters in the final document. It works great and was under $1K with support. Not bad.

The advantage of using a product like this is that you can continue to manage your data and the skill set required to produce the documents is at a level where a variety of developers can support its use.

Vanstee,

If you really want to do this in code, check out this post I just found on Google

http://kellychronicles.spaces.live.com/blog/cns!A0D71E1614E8DBF8!1364.entry

If you are using reporting services cant you just move the information in the word doc into a database table and read it from there, taking word out of the equation?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top