- added a whole bookmarks collection so one can access it from DocX and get the bookmark by name
- added a SetText method to the Bookmark so one can set the text from it using something like this: docX.Bookmarks["MyBookmark"].SetText("MyText")
- Added example BookmarksReplaceTextOfBookmarkKeepingFormat
- MergeCellsInRow - allow for merging the rows where the columns don't match (for instance, merge the last column of a row with 6 elements and a row with 3 elements will merge the last column of the row with too few elements)
- this is a specific case that I needed... others may need it as well, but I've got a separate branch with this change so it's up to you
Container.cs (and baseclasses)
- Moved PackagePart to the base class - found an issue where images in a table contained in the header or footer wouldn't display, this keeps track of what part of the doc and passes it to child things, (like inserting a table to a paragraph in the footer will have the correct part)
- Add a deep search for paragraphs.. This is to find a bookmark within a textbox or other art.. since a paragraph will wind up with a child paragraph.. (if you are searching for a bookmark like that the second one is the "right" one)
Few changes were made to allow to set the column widths for a table, on table level instead for each single cell.
The following methods/properties have been added:
- ColumnWidths - Returns a list (Of Double) with the width of all columns
- GetColumnWidth - Returns the width to a given single column index
- SetColumnWidth - Sets the column width to a given index
Property "AutoFit" has been modified to use the fixed table width; AutoFit will be set to "Fixed" if method "SetColumnWidth" is called.
Furthermore the enumeration: "AutoFit" got an addtional value: "Fixed".
Some warnings:
If you apply a width on table level; the cell width value will be removed for all table cells!
This one is a performance boost for cases where docs have lots of paragraphs inserted (through tables or whatever)...
In the case that I found the issue, I was creating a report that added a lot of plain text paragraphs followed by lots of tables.. (creating a 40 page doc)
(the fix is to avoid using the Paragraphs collection to get the one that was just added.. it fixes the reference to the "mainPart" so things like images that are added still work... )
All unit tests pass after this test (did have to fix some case issues with the one that does text replacements though)
Includes:
-fix for default column widths (also works when column widths are not specified) - issue that was breaking tables with more than 14 cols
-New table method to set the widths for variable row tables... you can call Table.SetWidths(float [] yourWidthsInPixels) then for each row added those cols will have that width applied.. can help clean up some code.. also caches the column count for performance..
- Change for DocX that turns on zip compression for the parts of the doc (created docs are as small as re-saved versions from word now)
- "Keep With Next"
- "Keep Lines Together"
Also fixes an issue with:
- SpacingBefore
- SpacingAfter
Also 2 examples for Keep With Next and Keep Lines Together added into Exampels.
Patch provided by someotherdevguy. Thanks!
In certain cases CreatePicture resulted in a corrupted document when opened in Word 2013/2010. The reason was that the docPr id="" attribute was duplicated. A bookmark already had id="7".
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 the ability to access the text of Endnotes and Footnotes defined within a document, otherwise hidden behind an internal XDocument field.
Reason: I was attempting to replicate the functionality of the Interop word-count facility: Document.ComputeStatistics(WdStatistic.wdStatisticWords) which takes IncludeFootnotesAndEndnotes as a boolean parameter. The DocX.Text property does not include endnotes or footnotes (which is fine), but I needed the extra properties to be able to access them when IncludeFootnotesAndEndnotes is true.
Patch provided by Tweet
Previously created TableBorder class has an error in setting table border colors. The generated colors are invalid according to the DOCX specification.
Fixed this by using the _Extensions methods.
Patch provided by lckuiper
A patch to add VML images ( <v:shape> ) to the Pictures list (Paragraph.Pictures). Without this patch, the list will only contain DrawingML images ( <w:drawing> ) by Annika89
- Fixes "This image cannot currently be displayed" errors after using InsertDocument with documents containing images
* Looks for images inside /word/media folder as well as images in the /media folder
* Updates the relationship id in both document.xml and document.xml.rels (in the local document as well)
- Adds the images to the /word/media folder instead of the /media folder
+ Adds the "image/jpg" type to the imageContentTypes list
Patch provided by Annika89
Fixes two issues with ingesting a .docx file. First, a tab exists as a child of a tabs element, not an r element (fix in HelperFunctions.cs at line 146). Second, an rFonts element may not have a cs attribute, but instead may have an ascii, eastAsia or hAnsi attribute (fix in Formatting.cs at line 101).
This patch contains a fix that makes Docx portable to mono. Fix for the exception: absolute path not supported on mono os x, on creating a document. Tested on windows using VS and tested on linux and mac os x using xamarin
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.