Creating Word Documents by Using C# and XML Wyoming

This article tells you how to create word documents in your application without using Office Interop or third-party libraries.

Local Companies

New Ideas Consulting Inc
303-920-1543
805 N Point Circle Unit B
Riverton, WY

In today's web applications, quite often you run into the need to create a Word document that user can download. The two most common ways of accomplish this is to install a copy of Word with Office Interop on the server or use a third-party library. Both of these options have significant downsides; however, there is a far simpler way to create Word Documents using XML. Because Word natively has the ability to read/write Word documents in XML, you can utilize all of the XML/XSLT tools in .NET to create them.

The first step is to create a normal Word document to be used as a template. Figure 1 shows a simple Word doc with which you will start to produce a report for Sales Territories from the Adventure Works sample database.


Figure 1: Word Document Template

Although this document does not make much sense at this point, you will use the markers in the document to help build the XSLT. To save this document to an XML file, you will need to save the file in the Word 2003 XML Document format shown in Figure 2.


Figure 2: Save as Word XML



Creating the XSLT



Now that you have an XML file, you can start the process of creating an XSLT (EXtensible Stylesheet Language Transformation). First, change the extension of the file from XML to XSLT. Then, open the XSLT in an XML editing tool. Next, you need to add a couple of tags at the top and bottom so that you can call this a XSLT. At this point, the top of the XSLT document should show the following couple of tags:




<?xml version="1.0" encoding="utf-8"?>
<w:wordDocument xmlns:aml=
"http://schemas.microsoft.com/aml/2001/core" ...


Read the Rest of this Article at Developer.com

Featured Local Company

New Ideas Consulting Inc

303-920-1543
805 N Point Circle Unit B
Riverton, WY
http://www.newideasconsulting.com

Providing premier ACT! database services to assist in every business situation - whether it involves purchasing ACT!, installation, E-marketing or training.

Related Local Events
Ag, Energy & Natural Resource Committee Meeting
Dates: 4/5/2010 - 4/5/2010
Location: Chamber of Commerce
Gillette, WY
View Details

Public Policy Committee Meeting
Dates: 5/6/2010 - 5/6/2010
Location: Chamber of Commerce
Gillette, WY
View Details

Retail Committee Meeting
Dates: 6/1/2010 - 6/1/2010
Location: Chamber of Commerce
Gillette, WY
View Details

NEWCA Board Meeting
Dates: 6/3/2010 - 6/3/2010
Location: Chamber of Commerce
Gillette, WY
View Details

Executive Board Meeting
Dates: 10/13/2010 - 10/13/2010
Location: Chamber of Commerce
Gillette, WY
View Details

Topics: 
Architecture & Design Languages & Tools Project Management Web Services
Database Microsoft & .NET Security Wireless
Java Open Source Techniques XML