About Me

My photo
Hello, my name is Cathal Coffey. I am best described as a hybrid between a developer and an adventurer. When I am not behind a keyboard coding, I am hiking and climbing the beautiful mountains of my home country Ireland. I am a full time student studying Computer Science & Software Engineering at the National University of Ireland Maynooth. I am finishing the final year of a 4 year degree in September 2009. I am the creator of an open source project on codeplex.com called DocX. At the moment I spend a lot of my free time advancing DocX and I enjoy this very much. My aim is to build a community around DocX and add features based on requests from this community. I really enjoy hearing about how people are using DocX in their work\personal projects. So if you are one of these people, please send me an email. Cathal coffey.cathal@gmail.com

Thursday, March 19, 2009

DocX version released

Note: Code samples have been updated to work with DocX version

I promised that I would release DocX frequently, and with lots of new useful features.

Version which can be downloaded from here, allows a developer to create a document on the fly, add new paragraphs and insert highly formatted text. Just about every font option that is available in Word 2007, is now exposed by DocX. These options include, but are not limited to; font, size, bold, italics, underline, strike through, superscript, subscript, color, highlight color, scale, shadow, outline, emboss, engrave, hidden, spacing, position, kerning.

imageFigure 1.0 – Word 2007 font options, tab 1

Figure 1.1 – Word 2007 font options, tab 2

Here’s an example of how to generate a docx file, which contains custom formatted text, out of thin air, using docx.

// Create a new document.
using (DocX document = DocX.Create(@"Test.docx"))
// Create a formatting called f1
Formatting f1 = new Formatting();
f1.FontFamily = new FontFamily("Agency FB");
f1.Size = 28;
f1.Bold = true;
f1.FontColor = Color.RoyalBlue;
f1.UnderlineStyle = UnderlineStyle.doubleLine;
f1.UnderlineColor = Color.Red;

// Insert a new Paragraph into this document.
Paragraph p = document.InsertParagraph("I've got style!", false, f1);

// Create a formatting called f2
Formatting f2 = new Formatting();
f2.FontFamily = new FontFamily("Colonna MT");
f2.Size = 36.5;
f2.Italic = true;
f2.FontColor = Color.SeaGreen;

// Insert new text at the end of this Paragraph.
p.InsertText("I have a different style.", false, f2);

// Save all changes made to this document.
}// Release this document from memory
The above code will generate the following document.

imageFigure 1.2 – Out of thin air

The coolest thing about this code, is that, you can generate .docx files in the cloud, without a dependency on Microsoft Word.

Please remember that DocX is not a full blown solution for .docx creation and manipulation, not yet anyway. It is a project, that I am working on, in my spare time. If you would like to request a feature for version, please email me or alternatively leave a comment here.

My current aim for version, is to add the ability to create and manipulate images, tables and lists.

happy coding,

No comments:

Post a Comment