In addition two new features: Table of contents and a way of validate if a document contains bookmarks with specified names. This is useful in applications where users can upload a template that will be populated based on form data. If this form data expects one or more bookmarks present in the document, one can now check this up front and use it to provide feedback to the user.
The following files have changes:
• DocX.cs
o Method: Addlist(string, int, ListItemType, in, bool) (I've added another paramter, bool)
o Method: AddListItem(List, string, level, ListItemType int, bool) (I've added another paramter, bool)
o All overloads of InsertList: removed adding of mainpart to list items (do this in AddListItem instead)
o New Method: InsertDefaultTableOfContents
o New Method: InsertTableOfContents(string, TableOfContentsSwitches, string, int, int?)
o New Method: InsertTableOfContents(Paragraph, string, TableOfContentsSwitches, string, int, int?)
• HelperFunctions.cs
o Method: CreateItemInList(List, string, int, ListItemType, int, bool) (I've added another paramter, bool)
• List.cs
o Method: CreateNewNumberNumId(int, ListItemType) (I've added two more paramteres, int, bool)
• ExtensionHeadings.cs
o New Method: HasFlag(this Enum, Enum)
• New File: TableOfContents.cs
• _Enumerations.cs:
o New Enum: TableOfContentsSwitches
• DocXUnitTests.cs
o Quite a few new tests. Tests for TableOfContents and new bookmark feature as well as hyper link bugfix for list items
• _BaseClasses.cs
o New class: XmlTemplateBases (holds constants)
• Program.cs: new examples, AddToc and AddTocByReference
• Paragraph.cs
o New Method: ValidateBookmark(string)
• Container.cs
o New Method: ValidateBookmarks(params string[])
This patch adds an extension method to Paragraph that allows easy setting of paragraph. It makes setting text as a heading much more intuitive and discoverable.
Covers Heading 1 - Heading 9
Example available in examples under DocumentHeading() method.
Adds the SetLineSpacing method to the Paragraph class. This method can be used to set or remove line spacing from a paragraph.
One method uses two parameters: the type of spacing and the amount of spacing (float). The other method uses one parameter: the type of spacing for which to set the value to auto; can be either before, after or both. The second method can also be used to remove spacing by using the type None.
Patch provided by Annika89. Great work!
Merged from GIT source code. Code provided by Randall Borck and Fainzanj
Changes:
- Fix to allow font family for a paragraph text to be set and read. (faizanj)
- Tightened up how a paragraph is designated as a list item. (faizanj)
- Feature add insert next page section (rgborck)
- Added examples for the section break and the new next page break. (Randall Borck)
- Added Next Page Section break functionality. The new method is called InsertSectionPageBreak(...). (Randall Borck)
- Fix for bug with entering more than one numbering. The system was inserting the abstract in the wrong place. Now the abstract sections are grouped at the beginning and the num section is grouped at the end. This should allow word to find the correct list formatting when a document with multiplelists is created from docx. (Randall Borck)
- Fix for list defaults to help them be more consistant with MS Word. Bullets were indenting twice that of numbers, now they increase the same amount. (Randall Borck)
- Added test for creating text with formatting (fainzanj)
- Added capability to detect underlinestyle (fainzanj)
- Updated the default values to specify Heading styles. (Randall Borck)
- Updated DocX to allow you to create an empty list object. This change is useful for creating a list and then running an iterator or loop to populate it.(Randall Borck)
- Fixed issue with multiple lists in the same document. The second list was overwriting the document numbering instead of appending to it. Also updated the default to be numbering instead of bullet. Added an example of how to create lists.(Randall Borck)
- Updated list items to allow for a start value. (Randall Borck)
- Fixed the Apply Template unit test. (Randall Borck)
- Removed unneeded test. (faizanj)
- Fixed unit tests. (Randall Borck)
- Cleaned up redunant parameters in AddItemList(...) call. (Randall Borck)
- Undid signature changes because of issues. (Randall Borck)
- Fixed a method signature. (Randall Borck)
- Added test for List property (fainzanj)
- Added test for List property(fainzanj)
- Updated documentation comments and default values. (Randall Borck)
- Updates/refactoring changes to list. (Randall Borck)
- Added capability to append list to previous list (fainzanj)
- Updated docx to support adding a list. Added preliminary list support to allow docx to create a list. Currently missing functionality to add elements to the previous list (so each list can only have 1 element in the creation of new lists so far). (faizanj, brendanjerwin)
- Added tests for adding a list (fainzanj)
Known issues:
- Charts related documents doesn't open in Word 2012 (opens up fine in Word 2010)
Additionally:
- Removed StrongNameFile.pfx for easy compile
- Renamed file UnitTests1.cs into DocXUnitTests.cs
- Created Documentation.chm and commited with this release
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();
}
Fixed a bug in Paragraph.AppendHyperlink(h) that caused any custom formatting to be applied to the runs before the Hyperlink instead of the Hyperlink itself. The below is now possible
Paragraph p = document.InsertParagraph();
p.Append("Check out this ").Color(Color.Red).AppendHyperlink(h).Color(Color.Green).Append(", it's really cool").Color(Color.Blue);
----------
Created an abstract class called DocXElement and made every document element such as {Table, Row, Cell, Paragraph, Run, Text, etc} extend it.
Created an abstract class InsertBeforeOrAfter which is derived from DocXElement. This provides functions for inserting, page breaks, Paragraphs and Tables before and after self.
Moved Text and Run inside Paragraph, keep consistancy with Table which contains Row and Cell.
To Do: Investigated why the Picture class had two internal constructors. I removed one.
Added a _ to each .cs file that does not contain instanceable types, {Enumerations.cs, Extensions.cs, etc}
Bugs fixed
----------
Cell had a parameter Paragraph, this was incorrect as paragraphs can contain multiple Paragraphs. Now it returns a List<Paragraph>
InsertDocProperty now returns a DocProperty instead of void.
New features
------------
InsertDocProperty now contains overloads for the parameter track changes.
Cell now contains a Shading property, this can be used to set the background color of a cell.
Cathal: Added overloads to ReplaceText for Format checking and replacement.
Joel: Added Row.MergeCells
Joel: Added Row.Height property
Joel: Added Cell.Width property
A huge thanks to Joel: The first user to submit working & tested functions\properties for inclusion in DocX.