Click here to Skip to main content
Licence LGPL3
First Posted 8 Aug 2005
Views 157,638
Downloads 970
Bookmarked 132 times

Gios WORD .NET Library (using RTF specification)

By Paolo Gios | 8 Aug 2005
A .NET library for generating Word documents (.DOC) using the RTF (Rich Text Format) specification.
2 votes, 4.8%
1
1 vote, 2.4%
2
1 vote, 2.4%
3
4 votes, 9.5%
4
34 votes, 81.0%
5
4.81/5 - 42 votes
3 removed
μ 4.64, σa 1.77 [?]

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)

About the Author

Paolo Gios

Web Developer

Italy Italy

Member
Freelance software ASPNET / C# Software Developer
 
I live in Torino, Italy
 
my homepage is: http://www.paologios.com

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
QuestionIssues on clean Windows 7 (32 bit) system? Pinmemberkembo15:53 25 Aug '11  
BugAutoFitBehavior (wdAutoFitContent) Pinmembermail-222:47 16 Aug '11  
GeneralTurkish Encoding Problem is solved simply. Pinmemberemarti12:18 4 Jun '11  
QuestionHow do I set the First Page Header Or Footer Different with other page on word document by using this library? Pinmemberlin ma597:05 23 Jul '09  
QuestionOpen an existing document? PinmemberTommy W1:17 13 May '09  
GeneralDocument won't show correctly in WordPad (or RichtextBox) PinmemberMember 45269125:54 27 Oct '08  
GeneralRe: Document won't show correctly in WordPad (or RichtextBox) PinmemberNever Winter18:18 5 Jan '09  
GeneralRender to image Pinmemberjosepaulino19:36 19 Aug '08  
GeneralChange table size and Aligment PinmemberTai Fei Pao9:12 18 Aug '08  
GeneralSolution for Table of contents Pinmembervavavivi5:07 3 Jul '08  
GeneralPage Current Number Pinmembervavavivi2:56 3 Jul '08  
GeneralRe: Page Current Number PinmemberPaolo Gios3:01 3 Jul '08  
GeneralRe: Page Current Number Pinmembervavavivi3:31 3 Jul '08  
GeneralRe: Page Current Number PinmemberTatjana Pede11:57 16 Jul '09  
QuestionHow to add checkbox? Pinmembergkee17:42 28 Apr '08  
Generaladding landscape page and portrait page in same document. PinmemberNajeed18:24 12 Dec '07  
GeneralRTF to PDF Converter for .NET Pinmemberflchivu16:19 3 Sep '07  
GeneralUnicode characters bugfix Pinmemberdejandular5:28 12 Aug '07  
GeneralRe: Unicode characters bugfix PinmemberHamid Reza Mohammadi20:32 23 Sep '07  
GeneralRe: Unicode characters bugfix PinmemberSimon Pham18:17 1 Jan '08  
GeneralRe: Unicode characters bugfix Pinmemberinormis21:24 16 Feb '10  
GeneralRe: Unicode characters bugfix PinmemberMasoud Aghdasi Fam1:03 23 May '09  
GeneralRe: Unicode characters bugfix PinmemberMember 819932317:08 30 Aug '11  
QuestionMake Table on New Page PinmemberCatch Anand23:56 31 Jul '07  
AnswerRe: Make Table on New Page Pinmembergraciella8:34 3 Aug '07  

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.

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