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

Tuesday, August 4, 2009

DocX version released

Hi again, sorry it has been so long since my last post. My progress in the physical world has slowed my progress in the digital.

This newest version of DocX brings many bug fixes and also two new features. Firstly, I would like to thank the following people for taking the time to email me with bugs and feature requests. Without your interest and feedback, DocX would not progress.

Many thanks to: John Marsh, Francesco, Johan Laagland, Gaspar, Brian (chicken), Jianbang, Christopher W. Steelman, Peter Thompson, Brian Minert.

New features

1) InsertDocProperty(CustomProperty cp)

CustomProperties are displayed in a document using fields of type DocProperty. Until this version, DocX was capable of adding a CustomProperty to a document, but it was not capable of displaying these CustomProperties. As of DocX version, this is now possible, below is an example.

// Load a document
using (DocX document = DocX.Create(@"Test.docx"))
// Create a custom property.
CustomProperty name = new CustomProperty("name", "Cathal Coffey");

// Add this custom property to this document.

// Insert a new paragraph.
Paragraph p = document.InsertParagraph("Author: ", false);

// Insert a field of type document property to display the custom property name

// Save all changes made to this document.
}// Release this document from memory.
The above code example will create the following document. Please note that the text 'Cathal Coffey'
is being displayed by a field, this field's value is controlled by the CustomProperty 'name'.

2) FindAll(string str)
This version of DocX allows you to search a document for a string. The function
FindAll(string str) returns a list containing all of the start indexes of the found string.
Below is an example of this new function.
// Load a document
using (DocX document = DocX.Load(@"Test.docx"))
// Loop through the paragraphs in this document.
foreach (Paragraph p in document.Paragraphs)
// Find all instances of 'go' in this paragraph.
List<int> gos = document.FindAll("go");

* Insert 'don't' in front of every instance of 'go' in this document to produce * 'don't go'. An important trick here is to do the inserting in reverse document * order. If you inserted in document order, every insert would shift the index * of the remaining matches.
foreach (int index in gos)
p.InsertText(index, "don't ", true);

// Save all changes made to this document.
}// Release this document from memory.
If the above code is run on this document (Drawing in red is to illustrate the index's of each instance of 'go').

Then the following document is produced.

As you can see, 'don't' was inserted at the original index of each instance of 'go'.

DocX is completely free, but if you have found it useful and you would like to make a donation you can do so via paypal.

As always, please contact me if you find any bugs, have any feature requests or just want to provide feedback.

happy coding,

1 comment:

  1. Hi, is it possible to calculate also the page number on which the string was found?