|
|||||||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||||||
|
Announcements
Want a new Job?
Chapters
Services
Feature Zones
|
IntroductionWord 2007 is becoming quite widespread even before becoming a production release. There have been over 3 million downloads of Beta 2 already as at July 2007. This article demonstartes a system for creating simple Word 2007 documents based solely on the packaging and XML formats. This can run on the desktop or a server and requires no installation of Word. BackgroundIt is quite common to see articles talking about using Word on a server to create or manipulate Microsoft Word documents. Often these applications are only tested on a developers machine, as they will fail in a production environment, as this usually requires running multiple threads. Only one instance of Word can run at a time, so the app must maintain a queue, and process as Word becomes free. This is especially problematic in a web server environment. Add to this the fact that many System Administrators will either not install Word on a server, or require an in depth business case to be provided, it is often not as simple as it could be. Using the codeA Word 2007 document usually has the extension
This is a very simple word document, and the structure can get a lot more complex. The text content of the word document is found in the The code will create the package, but takes a very simple approach, creating the
We begin by creating a // The document object represents the word document, without the Word 2007
Now we can add objects that derive from doc.Paragraphs.Add(new Heading1("Document maker"));
A paragraph contains only plain text. If formatted text is required, then a // Add a paragraph that is italic, using an overloaded constructor
doc.Paragraphs.Add(new Paragraph("By Mark Focas, July 2006",
TextFormats.Format.Italic));
// Or Create a Paragraph object and add Runs ro it.
Paragraph p=new Paragraph();
p.Runs.Add(new Run("Text can have multiple format styles, they can be "));
p.Runs.Add(new Run("bold and italic",
TextFormats.Format.Bold | TextFormats.Format.Italic));
doc.Paragraphs.Add(p);
Note how the p.Runs.Add(new Run("bold and italic",
TextFormats.Format.Bold | TextFormats.Format.Italic));
Once the document has been created, it needs to be packaged to be of any use. For maximum flexibility, // A document is of little use unless pacakged in the Word 2007
There are not many objects in the solution, most of them have been described above.
Points of InterestThe Microsoft XML model for Word appears complex, but in some ways is quite simple. Every object is a paragraph, all headings, list items etc. This makes it extremely simple to generate word documents, but extremely complex to process using XSLT. The approach I took with the I remain completely neutral about, and do not wish to enter in any debate on whether Word XML is better that Open Document Language or vice versa. This article should not be viewed as claiming Microsoft Word is any better or worse than Open Office. It could easily be adapted to output Open Office format if you require that. Having said that, I am rather disappointed that Microsoft are intending to charge for downloads of Office 2007 beta 2 from August. History30 July 2006 - Version 1.0.0
|
||||||||||||||||||||||||||||||