Click here to Skip to main content
6,291,522 members and growing! (13,362 online)
Email Password   helpLost your password?
General Programming » String handling » Strings     Intermediate License: The GNU Lesser General Public License

Gios WORD .NET Library (using RTF specification)

By Paolo Gios

A .NET library for generating Word documents (.DOC) using the RTF (Rich Text Format) specification.
C#, Windows, .NET 1.1VS.NET2003, Dev
Posted:8 Aug 2005
Views:95,012
Bookmarked:106 times
Announcements
Loading...
 
Search    
Advanced Search
printPrint   Broken Article?Report       add Share
  Discuss Discuss   Recommend Article Email
36 votes for this article.
Popularity: 7.18 Rating: 4.61 out of 5
2 votes, 5.6%
1
1 vote, 2.8%
2
1 vote, 2.8%
3
4 votes, 11.1%
4
28 votes, 77.8%
5

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

About the Author

Paolo Gios


Member
Freelance software ASPNET / C# Software Developer

I live in Torino, Italy

my homepage is: http://www.paologios.com
Occupation: Web Developer
Location: Italy Italy

Other popular String handling articles:

Article Top
You must Sign In to use this message board.
FAQ FAQ 
 
Noise Tolerance  Layout  Per page   
 Msgs 1 to 25 of 93 (Total in Forum: 93) (Refresh)FirstPrevNext
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  
QuestionHow to add checkbox? Pinmembergkee17:42 28 Apr '08  
Generaladding landscape page and portrait page in same document. PinmemberNajeed18:24 12 Dec '07  
Generalhow add animated gif images? Pinmembersuhail kaleem8:19 10 Nov '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 PinmemberMasoud Aghdasi Fam1:03 23 May '09  
QuestionMake Table on New Page PinmemberCatch Anand23:56 31 Jul '07  
AnswerRe: Make Table on New Page Pinmembergraciella8:34 3 Aug '07  
Generalproblem with bigger datatables [modified] Pinmembermayur sharma19:01 8 Jul '07  
AnswerRe: problem with bigger datatables Pinmembergraciella8:41 3 Aug '07  
GeneralExcellent and I got what i was looking for. Kiddoo to Gios Pinmembershinilkp14:26 27 Jun '07  
JokeRe: Excellent and I got what i was looking for. Kiddoo to Gios PinmemberPaolo Gios3:02 3 Jul '08  
QuestionSet Page Number PinmemberCatch Anand4:36 26 Jun '07  
AnswerRe: Set Page Number Pinmembershinilkp13:40 26 Jun '07  

General General    News News    Question Question    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

PermaLink | Privacy | Terms of Use
Last Updated: 8 Aug 2005
Editor: Rinish Biju
Copyright 2005 by Paolo Gios
Everything else Copyright © CodeProject, 1999-2009
Web10 | Advertise on the Code Project