Click here to Skip to main content
11,583,865 members (46,243 online)
Click here to Skip to main content

Gios WORD .NET Library (using RTF specification)

, 8 Aug 2005 LGPL3 238.2K 3.8K 144
Rate this:
Please Sign up or sign in to vote.
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.

License

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

Share

About the Author

Paolo Gios
Web Developer
Italy Italy
Freelance software ASPNET / C# Software Developer

I live in Torino, Italy

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

You may also be interested in...

Comments and Discussions

 
QuestionEncoding using unicode Pin
FandaCZ1-Feb-14 0:01
memberFandaCZ1-Feb-14 0:01 
QuestionHelp Pin
Member 102652662-Dec-13 14:31
memberMember 102652662-Dec-13 14:31 
QuestionIs support Excel Pin
Wisen Technologies8-Aug-13 15:26
groupWisen Technologies8-Aug-13 15:26 
QuestionError if more than 200 pages Pin
thomaszae14-Jun-12 1:50
memberthomaszae14-Jun-12 1:50 
QuestionIssues on clean Windows 7 (32 bit) system? Pin
kembo25-Aug-11 14:53
memberkembo25-Aug-11 14:53 
BugAutoFitBehavior (wdAutoFitContent) Pin
mail-2216-Aug-11 1:47
membermail-2216-Aug-11 1:47 
GeneralTurkish Encoding Problem is solved simply. Pin
emarti4-Jun-11 11:18
memberemarti4-Jun-11 11:18 
QuestionHow do I set the First Page Header Or Footer Different with other page on word document by using this library? Pin
lin ma5923-Jul-09 6:05
memberlin ma5923-Jul-09 6:05 
QuestionOpen an existing document? Pin
Tommy W13-May-09 0:17
memberTommy W13-May-09 0:17 
GeneralDocument won't show correctly in WordPad (or RichtextBox) Pin
Member 452691227-Oct-08 4:54
memberMember 452691227-Oct-08 4:54 
GeneralRe: Document won't show correctly in WordPad (or RichtextBox) Pin
Never Winter5-Jan-09 17:18
memberNever Winter5-Jan-09 17:18 
GeneralRender to image Pin
josepaulino19-Aug-08 18:36
memberjosepaulino19-Aug-08 18:36 
GeneralSolution for Table of contents Pin
vavavivi3-Jul-08 4:07
membervavavivi3-Jul-08 4:07 
GeneralRe: Solution for Table of contents Pin
thomaszae14-Jun-12 12:15
memberthomaszae14-Jun-12 12:15 
AnswerRe: Solution for Table of contents Pin
Dannon DMello12-Oct-13 6:25
memberDannon DMello12-Oct-13 6:25 
GeneralPage Current Number Pin
vavavivi3-Jul-08 1:56
membervavavivi3-Jul-08 1:56 
GeneralRe: Page Current Number Pin
Paolo Gios3-Jul-08 2:01
memberPaolo Gios3-Jul-08 2:01 
GeneralRe: Page Current Number Pin
vavavivi3-Jul-08 2:31
membervavavivi3-Jul-08 2:31 
GeneralRe: Page Current Number Pin
Tatjana Pede16-Jul-09 10:57
memberTatjana Pede16-Jul-09 10:57 
QuestionHow to add checkbox? Pin
gkee28-Apr-08 16:42
membergkee28-Apr-08 16:42 
Generaladding landscape page and portrait page in same document. Pin
Najeed12-Dec-07 17:24
memberNajeed12-Dec-07 17:24 
GeneralRTF to PDF Converter for .NET Pin
flchivu13-Sep-07 5:19
memberflchivu13-Sep-07 5:19 
GeneralUnicode characters bugfix Pin
dejandular12-Aug-07 4:28
memberdejandular12-Aug-07 4:28 
GeneralRe: Unicode characters bugfix Pin
Hamid Reza Mohammadi23-Sep-07 19:32
memberHamid Reza Mohammadi23-Sep-07 19:32 
GeneralRe: Unicode characters bugfix Pin
Simon Pham1-Jan-08 17:17
memberSimon Pham1-Jan-08 17:17 
GeneralRe: Unicode characters bugfix Pin
inormis16-Feb-10 20:24
memberinormis16-Feb-10 20:24 
GeneralRe: Unicode characters bugfix Pin
Masoud Aghdasi Fam23-May-09 0:03
memberMasoud Aghdasi Fam23-May-09 0:03 
GeneralRe: Unicode characters bugfix Pin
Member 819932330-Aug-11 16:08
memberMember 819932330-Aug-11 16:08 
QuestionMake Table on New Page Pin
Catch Anand31-Jul-07 22:56
memberCatch Anand31-Jul-07 22:56 
AnswerRe: Make Table on New Page Pin
graciella3-Aug-07 7:34
membergraciella3-Aug-07 7:34 
Generalproblem with bigger datatables [modified] Pin
mayur sharma8-Jul-07 18:01
membermayur sharma8-Jul-07 18:01 
AnswerRe: problem with bigger datatables Pin
graciella3-Aug-07 7:41
membergraciella3-Aug-07 7:41 
GeneralExcellent and I got what i was looking for. Kiddoo to Gios Pin
shinilkp27-Jun-07 13:26
membershinilkp27-Jun-07 13:26 
JokeRe: Excellent and I got what i was looking for. Kiddoo to Gios Pin
Paolo Gios3-Jul-08 2:02
memberPaolo Gios3-Jul-08 2:02 
QuestionSet Page Number Pin
Catch Anand26-Jun-07 3:36
memberCatch Anand26-Jun-07 3:36 
AnswerRe: Set Page Number Pin
shinilkp26-Jun-07 12:40
membershinilkp26-Jun-07 12:40 
GeneralRe: Set Page Number Pin
yirer30-Jul-07 3:56
memberyirer30-Jul-07 3:56 
AnswerRe: Set Page Number Pin
j-on22-Aug-08 7:57
memberj-on22-Aug-08 7:57 
AnswerRe: Set Page Number Pin
Tatjana Pede16-Jul-09 11:02
memberTatjana Pede16-Jul-09 11:02 
QuestionBackground color of Table Cell Pin
Catch Anand20-Jun-07 2:38
memberCatch Anand20-Jun-07 2:38 
AnswerRe: Background color of Table Cell Pin
frankosaurus25-Jun-07 8:30
memberfrankosaurus25-Jun-07 8:30 
GeneralThis has some problems, but the architecture is very nice! [modified] Pin
crazy legs11-Jun-07 15:09
membercrazy legs11-Jun-07 15:09 
QuestionHelp Pin
nikkymikky4-Jun-07 2:46
membernikkymikky4-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
memberJay Bhagatwala11-Apr-07 1:48 
QuestionSave word has function table of content (TOC) and bullet & number Pin
Tuan Tai4-Apr-07 15:54
memberTuan Tai4-Apr-07 15:54 
AnswerRe: Save word has function table of content (TOC) and bullet & number Pin
vavavivi1-Jul-08 23:41
membervavavivi1-Jul-08 23:41 
GeneralRe: Save word has function table of content (TOC) and bullet & number Pin
vavavivi2-Jul-08 3:35
membervavavivi2-Jul-08 3:35 
GeneralRe: Save word has function table of content (TOC) and bullet & number Pin
emarti4-Jun-11 13:01
memberemarti4-Jun-11 13:01 
QuestionHTML contents Pin
martyneee28-Mar-07 20:40
membermartyneee28-Mar-07 20:40 
GeneralReading header and footer from the rtf template Pin
nep4uk20-Mar-07 0:37
membernep4uk20-Mar-07 0:37 

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

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

| Advertise | Privacy | Terms of Use | Mobile
Web04 | 2.8.150603.1 | Last Updated 8 Aug 2005
Article Copyright 2005 by Paolo Gios
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid