Gios WORD .NET Library (using RTF specification)






4.85/5 (43 votes)
A .NET library for generating Word documents (.DOC) using the RTF (Rich Text Format) specification.
This is the output of "Example 1", included in the library.
Introduction
The Gios WORD .NET is the second thing that a good C# developer needs to deploy in his business projects... The first one?!? You probably know it is the Gios PDF .NET library!
So, that's why I decided to develop this library: after the need for generating PDFs, you will need the same for WORDs!
Gios WORD .NET supports:
- Tables with rows and columns span.
- Images
- Header and Footer
- Line indent - paragraph
- Custom Control Words (See the Rich Text Format (RTF) Specification for this implementation.)
- Output to a generic
System.IO.Stream
object.
Background
Building a library for exporting documents in the Rich Text Format is quite easier than for PDFs. In fact, the Rich Text Format (RTF) Specification, version 1.8 shows how simple it is to generate a word document with all the well known features. I used the version 1.5 (which is fully compatible with WORD 97).
Using the code
The library is very simple to be used! The first thing you need to do is instantiating a new WordDocument
:
WordDocument myWordDocument=
new WordDocument(WordDocumentFormat.Letter_8_5x11);
and with the WordDocument
object you can start with the description of the document. It's like an automation. For example, if you want to set the font, you can write:
myWordDocument.SetFont(new Font("Comic Sans MS",
60,FontStyle.Bold));
myWordDocument.SetForegroundColor(Color.Red);
myWordDocument.SetFontBackgroundColor(Color.Yellow);
And now we set some alignment:
myWordDocument.SetTextAlign(WordTextAlign.Center);
To write a text... You can imagine:
myWordDocument.Write("Hello World!");
And, in the end, you output the document!
myWordDocument.SaveToFile("HelloWorld.doc");
And this is the result:
Remember, you can also output the WORD Document to a generic stream. These are the lines for a web response:
Response.ClearHeaders();
Response.AppendHeader("Content-disposition",
"attachment;filename=HelloWorld.doc");
Response.ContentType="application/msword";
myPdfDocument.SaveToStream(Response.OutputStream);
Response.End();
To continue with the training, please download the library and follow the examples!
History
- August 8th, 2005 - First release.