Added a patch provided by ArtFeel. By default the document language use to be English (Ireland). DocX now uses CurrentCulture to infer the correct language. You can know also specify a specific language.
Thank you for this patch ArtFeel. Also thanks to MadBoy for reminding me about it, without you this might have been lost in the discussions section of codeplex. Sorry about the delay Madboy.
Refactor the Table class: RowCount, ColumnCount, Rows properties and Insert/Remove methods. Also refactor CreateTable method - extract the same method CreateTableCell. Add powerfull unit test for this.
Added basic support for PageNumber and PageCount place holders.
When inserted into a Header or Footer Word will automatically display the correct value foreach page.
Word will not automatically update these place holders if inserted inside a document level Paragraph.
You need to right click and select update field. I therefore suggest that you only use these place holders inside Headers and Footers.
Added
-------
Paragraph.AppendPageNumber(PageNumberFormat)
Paragraph.InsertPageNumber(PageNumberFormat, int index)
Paragraph.AppendPageCount(PageNumberFormat)
Paragraph.InsertPageCount(PageNumberFormat, int index)
Example
-----------
// Create a new document.
using (DocX document = DocX.Create(@"Test.docx"))
{
// Add Headers to the document.
document.AddHeaders();
// Get the default Header.
Header header = document.Headers.odd;
// Insert a Paragraph into the Header.
Paragraph p0 = header.InsertParagraph();
// Append place holders for PageNumber and PageCount into the Header.
// Word will replace these with the correct value foreach Page.
p0.Append("Page (");
p0.AppendPageNumber(PageNumberFormat.normal);
p0.Append(" of ");
p0.AppendPageCount(PageNumberFormat.normal);
p0.Append(")");
// Save the document.
document.Save();
}
AddProtection() now calls RemoveProtection() as its first task. Otherwise a document could contain many protection elements and this is unallowed.
Below is a code example which uses the new Protection familiy of functions.
// Load a document.
using (DocX document = DocX.Load(@"Test.docx"))
{
if (document.isProtected)
{
Console.WriteLine("Document is protected.");
Console.WriteLine("\tProtection type is " + document.GetProtectionType().ToString());
document.RemoveProtection();
Console.WriteLine("\tProtected removed.");
// Save the document.
document.Save();
Console.WriteLine("\tDocument saved as Test.docx");
}
else
{
Console.WriteLine("Document is not protected.");
document.AddProtection(EditRestrictions.readOnly);
Console.WriteLine("\tProtected added.");
Console.WriteLine("\tProtection type is " + document.GetProtectionType().ToString());
// Save the document.
document.Save();
Console.WriteLine("\tDocument saved as Test.docx");
}
}
// Wait until a user presses a key before exiting.
Console.ReadKey();