* minimize closure allocations by replacing LINQ with foreach when needed
* use lookups when possible
* reuse filtered items, pre-compute when possible
* use lighter Monitor for isolated storage locking instead of Mutex
* fix DocX references to be real project references instead of DLL references
On mono, the OriginalString of a Uri sometimes is prefixed with file:// leading to issues when combining paths. We strip the prefix if necesary to avoid that.
Fix to prevent deadlocks in multi-threaded applications
See https://support.microsoft.com/en-us/kb/2996566 (Issue 1) for more
details. But in summary if the document is larger than 10Mb, then deadlocks
can occur in multi-threaded applications.
Chnaged 15 to 20 multiplier in margins and page size so that margins and page size are effectively set/retrieved in points (pts). This is a breaking change potentially, but otherwise it is not clear what the units are for page width, height, and margins.
- 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)
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)
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
- 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
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
While using the InsertDocument method, I encountered several (minor) issues/exceptions. The changes I made to get rid of these exceptions are in this patch. It also fixes merging Styles (and footnotes).
Inserting a chart in a template throws exception "Message='rId10' ID conflicts with the ID of an existing relationship for the specified source."
provided by mmirabito.
InsertList(List list, double fontSize)
InsertList(List list, System.Drawing.FontFamily fontFamily, double fontSize)
and a new example of usage: DocumentsWithListsFontChange();
Thanks to those 2 methods you can easily set font family and font size when inserting new lists.
This patch adds support for images inside <v:shape> tags (besides the already supported images inside <w:drawing> tags). InsertDocument method no longer results in a corrupt/invalid document when an inserted document contains an image that is inside <v:shape> rather than <w:drawing> tags.
Code provided by andreasbotsikas from GIT repository:
- If custom property value is null insert empty string (This will avoid crashing the AddProperty. Another way would be to throw an application exception, but it's much more intuitive to set an empty string instead.)
- Check if stream can seek (This will allow devs to save the document directly on a System.Web.HttpResponseStream without the need to create yet another memory stream.)
- Fix duplicate custom properties (Check if property exists ignoring case as it would produce a corrupted docx otherwise.)
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
Reinserting the same document a large number of time > 100 caused the styles table to explode.
This should not have happened because each iteration contributes no new style. This has been fixed and tested with reinsertion as large as 1,000 times.
Word 2007 and 2010 has no problem opening these documents... apart from the fact that they are massive > 100MB uncompressed.
1. override InsertTable(int rowCount, int columnCount) method in Table Cell because of bug.
Cell need paragraph in the end.
2. InsertTableBeforeSelf(Table t) behaviour changed, now it returns completely new table copied from parameter table.
3. InsertParagraphAfterSelf(Paragraph p) behaviour changed, now it returns completely new paragraph copied from parameter paragraph, but only in case for this is Paragraph
4. InsertTableAfterSelf(Table t) the same as for InsertTableBeforeSelf behaviour changed, now it returns completely new table copied from parameter table.
P.S. Look please my //IMPORTANT notes in code.
Sandcastles (The documentation builders) now support Visual Studio 2010 integration. In this light I have added a Documentation project to the DocX solution. This will help to keep the DocX.chm file up to date.
The get and set methods for Paragraph.Hyperlinks where broken.
This changeset fixes that and another issue. I discovered that Word allows Hyperlinks to be defined in two ways, inline and normal. DocX now supports both.
This changeset also contains new unit tests that will hopefully prevent Hyperlink support from braking again.