views:

1479

answers:

6

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.

+1  A: 

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

tvanfosson
Thanks for the quick response. However, I was looking for free solution so I don't have to worry about licensing issues.
Aspose is licensed per developer or site and one type of license allows distribution to any number of physical sites (developer or site OEM license).
tvanfosson
This aspect of our application is not really important enough to justify paying for an extensive plugin. Do you know of any free alternatives?
A: 

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

Chris
That requires you to open the Word application, which is not really an option at this point.
@Vanstee, you can change the code to work from a console application, and never show Word by setting it's Visibility to false. Would you like an example?
Chris
Showing Word isn't really the problem. To access newer versions of Word from a web application you have to give it some high level permissions. Our Server Admin refuses to do so, and after reading about it I don't blame him. Thanks anyways.
@Vanstee, I take it back, I didn't see the part about the web application, perhaps update the title of your question or bold that part. You could preform the mail merge and then inspect the document. Check this video out: channel9.msdn.com/posts/LarryLarsen/…, the guy mentions a tool to look at documents. Once you've done that, you can see the XML word generates, and attempt to duplicate that. A third party library might be a better choice in this case.
Chris
A: 

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.

David Robbins
+1  A: 

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.

FromTheMountain
A: 

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?

beakersoft
+3  A: 

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

OpenXml SDK 2.0 is still in CTP and licensing is for testing purposes only (prop until Office 14 comes out)
foson