5,699,431 members and growing! (24,027 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.1, .NETVisual Studio, VS.NET2003, Dev

Posted: 8 Aug 2005
Updated: 8 Aug 2005
Views: 82,071
Bookmarked: 92 times
Announcements
Loading...



Search    
Advanced Search
Sitemap
34 votes for this Article.
Popularity: 7.05 Rating: 4.60 out of 5
2 votes, 5.9%
1
1 vote, 2.9%
2
1 vote, 2.9%
3
4 votes, 11.8%
4
26 votes, 76.5%
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


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
Sign Up to vote for this article
You must Sign In to use this message board.
FAQ FAQ Noise ToleranceSearch Search Messages 
 Layout  Per page   
 Msgs 1 to 25 of 90 (Total in Forum: 90) (Refresh)FirstPrevNext
GeneralDocument won't show correctly in WordPad (or RichtextBox)memberMember 45269125:54 27 Oct '08  
GeneralRender to imagememberjosepaulino19:36 19 Aug '08  
GeneralChange table size and AligmentmemberTai Fei Pao9:12 18 Aug '08  
GeneralSolution for Table of contentsmembervavavivi5:07 3 Jul '08  
GeneralPage Current Numbermembervavavivi2:56 3 Jul '08  
GeneralRe: Page Current NumbermemberPaolo Gios3:01 3 Jul '08  
GeneralRe: Page Current Numbermembervavavivi3:31 3 Jul '08  
QuestionHow to add checkbox?membergkee17:42 28 Apr '08  
Generaladding landscape page and portrait page in same document.memberNajeed18:24 12 Dec '07  
Generalhow add animated gif images?membersuhail kaleem8:19 10 Nov '07  
GeneralRTF to PDF Converter for .NETmemberflchivu16:19 3 Sep '07  
GeneralUnicode characters bugfixmemberdejandular5:28 12 Aug '07  
GeneralRe: Unicode characters bugfixmemberHamid Reza Mohammadi20:32 23 Sep '07  
GeneralRe: Unicode characters bugfixmemberSimon Pham18:17 1 Jan '08  
QuestionMake Table on New PagememberCatch Anand23:56 31 Jul '07  
AnswerRe: Make Table on New Pagemembergraciella8:34 3 Aug '07  
Generalproblem with bigger datatables [modified]membermayur sharma19:01 8 Jul '07  
AnswerRe: problem with bigger datatablesmembergraciella8:41 3 Aug '07  
GeneralExcellent and I got what i was looking for. Kiddoo to Giosmembershinilkp14:26 27 Jun '07  
JokeRe: Excellent and I got what i was looking for. Kiddoo to GiosmemberPaolo Gios3:02 3 Jul '08  
QuestionSet Page NumbermemberCatch Anand4:36 26 Jun '07  
AnswerRe: Set Page Numbermembershinilkp13:40 26 Jun '07  
GeneralRe: Set Page Numbermemberyirer4:56 30 Jul '07  
AnswerRe: Set Page Numbermemberj-on8:57 22 Aug '08  
QuestionBackground color of Table CellmemberCatch Anand3:38 20 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-2008
Web19 | Advertise on the Code Project