About Me

My photo
Ireland
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

Sunday, April 19, 2009

DocX version 1.0.0.4 released

This blog post is to announce the release of DocX version 1.0.0.4. I spend a lot of time re-factoring the library for this release. I have renamed a lot of functions to give a more consistent implementation. I have also created a (.chm) documentation file which contains lots of useful examples.

The .chm documentation
If you open up the documentation file and you see the message Navigation to the webpage was cancelled like the below screenshot.

image

Then you need to right click on the .chm file and select properties.

image

In the properties window, click unblock, then press apply and ok.

image

You should then be able to view the documentation and it should look like this.

image

The documentation contains lots of examples of how to use all of DocX’s features. If you find a mistake in the documentation or if you would like to add a code example that you have written please email me. If I think your example adds value to the documentation then I will gladly add it and mention you in the credits section.

Changes in this release

  1. Added two nwq overloads DocX.Load(System.IO.Stream) and Doc.Create(System.IO.Stream).
  2. DocX.AddParagraph has been renamed to InsertParagraph and now allows a users to insert a new Paragraph at a specified character index in the document, 4 overloads are available.
  3. DocX.Value has been renamed to DocX.Text.
  4. DocX.Save has been renamed to DocX.Close(bool saveChanges).
  5. Paragraph.Insert, Paragraph.Remove and Paragraph.Replace have been renamed to Paragraph.InsertText, Paragraph.RemoveText, Paragraph.ReplaceText, new overloads are also available.
  6. Paragraph.Value has been renamed as Paragraph.Text.

If you would like to send me feedback on DocX, or if you would like to make a suggestion for the next feature I implement, please email me at coffey.cathal@gmail.com.

happy coding,
Cathal

Wednesday, April 8, 2009

DocX version 1.0.0.2 released

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

Lots of people emailed me asking me to add support for Images in DocX. So I did. Version 1.0.0.2 which can be downloaded from here adds basic support for Images and Pictures.

Images and Pictures? Are they not the same thing you might ask? No they are not! You can think of a Picture as a customized view of an Image. Once you have added Images to a docx file.

image

You can then add multiple customized Pictures of those Images into Paragraphs. You can do all sorts of interesting customizations with these Pictures before inserting them into Paragraphs. At the moment docx supports the following Picture customizations;

Rotations and transformations

image image image

Resizing

image image image

Shaping

image image image

image image image

Time for an example using DocX; below is a file entitled Example.docx.

image Figure 1.0 – Example.docx before code execution

The following code adds the Image Donkey.jpg into this file, it then creates two Pictures using this Image and inserts them into the last Paragraph.

// Create a .docx file
using (DocX document = DocX.Create(@"Example.docx"))
{
// Add an Image to the docx file
Novacode.Image img = document.AddImage(@"Donkey.jpg");

// Insert an emptyParagraph into this document.
Paragraph p = document.InsertParagraph("", false);

#region pic1
Picture pic1 = p.InsertPicture(img.Id, "Donkey", "Taken on Omey island");

// Set the Picture pic1’s shape
pic1.SetPictureShape(BasicShapes.cube);

// Rotate the Picture pic1 clockwise by 30 degrees
pic1.Rotation = 30;
#endregion

#region
pic2
// Create a Picture. A Picture is a customized view of an Image
Picture pic2 = p.InsertPicture(img.Id, "Donkey", "Taken on Omey island");

// Set the Picture pic2’s shape
pic2.SetPictureShape(CalloutShapes.cloudCallout);

// Flip the Picture pic2 horizontally
pic2.FlipHorizontal = true;
#endregion

// Save the docx file
document.Save();
}// Release this document from memory.
image

Figure 1.1 – Example.docx after code execution

Another interesting thing that you could do would be to apply an operation to every Picture in a document. The below snippet would rotate every Picture in a document clockwise by 30 degrees.

// Load the document that you want to manipulate
using (DocX document = DocX.Load(@"Test.docx"))
{
// Loop through each Paragraph
foreach (Paragraph p in document.Paragraphs)
{
// Loop through each Picture in this Paragraph
foreach (Picture pi in p.Pictures)
{
// Rotate this picture clockwise by 30 degrees
pi.Rotation = 30;
}
}

// Save the document
document.Save();
}// Release this document from memory
If you would like to send me feedback on DocX, or if you would like to make a suggestion for the next feature I implement, please email me at coffey.cathal@gmail.com.

happy coding,
Cathal