Click here to Skip to main content
15,893,486 members
Articles / Programming Languages / C#
Article

Gios WORD .NET Library (using RTF specification)

Rate me:
Please Sign up or sign in to vote.
4.85/5 (47 votes)
8 Aug 2005LGPL31 min read 362K   4.5K   149   110
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:

C#
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:

C#
myWordDocument.SetFont(new Font("Comic Sans MS",
                                60,FontStyle.Bold));
myWordDocument.SetForegroundColor(Color.Red);
myWordDocument.SetFontBackgroundColor(Color.Yellow);

And now we set some alignment:

C#
myWordDocument.SetTextAlign(WordTextAlign.Center);

To write a text... You can imagine:

C#
myWordDocument.Write("Hello World!");

And, in the end, you output the document!

C#
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:

C#
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.

License

This article, along with any associated source code and files, is licensed under The GNU Lesser General Public License (LGPLv3)


Written By
Web Developer
Italy Italy
Freelance software ASPNET / C# Software Developer

I live in Torino, Italy

my homepage is: http://www.paologios.com

Comments and Discussions

 
GeneralRe: Unicode characters bugfix Pin
urinspiration16-Feb-10 20:24
urinspiration16-Feb-10 20:24 
GeneralRe: Unicode characters bugfix Pin
Masoud Aghdasifam23-May-09 0:03
Masoud Aghdasifam23-May-09 0:03 
GeneralRe: Unicode characters bugfix Pin
Member 819932330-Aug-11 16:08
Member 819932330-Aug-11 16:08 
QuestionMake Table on New Page Pin
Catch Anand31-Jul-07 22:56
Catch Anand31-Jul-07 22:56 
AnswerRe: Make Table on New Page Pin
graciella3-Aug-07 7:34
graciella3-Aug-07 7:34 
Generalproblem with bigger datatables [modified] Pin
mayur sharma8-Jul-07 18:01
mayur sharma8-Jul-07 18:01 
AnswerRe: problem with bigger datatables Pin
graciella3-Aug-07 7:41
graciella3-Aug-07 7:41 
GeneralExcellent and I got what i was looking for. Kiddoo to Gios Pin
shinilkp27-Jun-07 13:26
shinilkp27-Jun-07 13:26 
JokeRe: Excellent and I got what i was looking for. Kiddoo to Gios Pin
Paolo Gios3-Jul-08 2:02
Paolo Gios3-Jul-08 2:02 
QuestionSet Page Number Pin
Catch Anand26-Jun-07 3:36
Catch Anand26-Jun-07 3:36 
AnswerRe: Set Page Number Pin
shinilkp26-Jun-07 12:40
shinilkp26-Jun-07 12:40 
GeneralRe: Set Page Number Pin
yirer30-Jul-07 3:56
yirer30-Jul-07 3:56 
AnswerRe: Set Page Number Pin
j-on22-Aug-08 7:57
j-on22-Aug-08 7:57 
AnswerRe: Set Page Number Pin
Tatjana Ilchenko16-Jul-09 11:02
Tatjana Ilchenko16-Jul-09 11:02 
QuestionBackground color of Table Cell Pin
Catch Anand20-Jun-07 2:38
Catch Anand20-Jun-07 2:38 
AnswerRe: Background color of Table Cell Pin
frankosaurus25-Jun-07 8:30
frankosaurus25-Jun-07 8:30 
GeneralThis has some problems, but the architecture is very nice! [modified] Pin
crazy legs11-Jun-07 15:09
crazy legs11-Jun-07 15:09 
QuestionHelp Pin
nikkymikky4-Jun-07 2:46
nikkymikky4-Jun-07 2:46 
Questionhow can i set Page Setup Properties using GiosWord object like Top ,left, etc.?? Pin
Jay Bhagatwala11-Apr-07 1:48
Jay Bhagatwala11-Apr-07 1:48 
QuestionSave word has function table of content (TOC) and bullet & number Pin
Tuan Tai4-Apr-07 15:54
Tuan Tai4-Apr-07 15:54 
AnswerRe: Save word has function table of content (TOC) and bullet & number Pin
vavavivi1-Jul-08 23:41
vavavivi1-Jul-08 23:41 
GeneralRe: Save word has function table of content (TOC) and bullet & number Pin
vavavivi2-Jul-08 3:35
vavavivi2-Jul-08 3:35 
GeneralRe: Save word has function table of content (TOC) and bullet & number Pin
emarti4-Jun-11 13:01
emarti4-Jun-11 13:01 
QuestionHTML contents Pin
martyneee28-Mar-07 20:40
martyneee28-Mar-07 20:40 
GeneralReading header and footer from the rtf template Pin
nep4uk20-Mar-07 0:37
nep4uk20-Mar-07 0:37 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.