Manipulate and generate MSWord documents efficiently. All changes to a document are recorded and only executed when the document is generated.
The library will generate new documents or open and manipulate existing documents.
Note that the underlying library DocX has become free for non-commercial use only in later versions. So to keep this library available to commercial users, the underlying DocX library will not be upgraded. This will restrict what functionality may be available.
Operations include
Only works with .NET backend. Uses the DocX library from Xceed underneath. Does not support Right to Left text.
Provides a library that abstracts MSWord manipulations from the underlying extension so another extension can replace it in future without changing the library interface.
Table of Contents
Scenarios
Scenario 1: Replace Bookmarks (like Mail Merge)
Scenario 2: Create a new document
Scenario 3: Highlight search terms
Actions
The plugin exposes the following actions.
MSWord_AddHeadersAndFooters
Add headers and footers to the document.
ParametersInDocument (MSWord_Document) The document to manipulate.InDifferentFirstPage (Boolean) The headers and footers are different on the first and subsequent pages.InDifferentOddAndEvenPages (Boolean) The headers and footers are different on odd and even pages.
MSWord_CloseDocument
Release the document reference. It may not be used again.
ParametersInDocument (MSWord_Document) The document to close.
MSWord_CreateDocument
Create a new MSWord docx document for editing providing an optional template.
ParametersInTemplate (BinaryData) The MSWord document to use as a template. May be null.OutDocument (MSWord_Document) A reference to the document. Use in other actions to manipulate the document.
MSWord_GenerateDocument
Generate a new MSWord document containing all the edits and return it as binary content.
ParametersInDocument (MSWord_Document) The document to manipulate.InClose (Boolean) If true, closes the documentOutContent (Out, BinaryData) The content of the generated MSWord document.
MSWord_HighlightText
Search for text in a document and highlight matching text in the specified colour.ParametersInDocument (MSWord_Document) The document to manipulate.InSearch (Text) Find text matching InSearchInHighlight (Text) The highlight colour, defaults to "yellow".
MSWord_InsertBulletHierarchy
Helper action to insert a bullet list with items at different levels.
ParametersInDocument (MSWord_Document) The document to manipulate.BulletType (Text) "Bullet" or "Number"Font (Text) The font familyFontSize (Decimal) The font sizeInText1 (Text) A bullet pointInLevel1 (Integer) The hierarchy level of the item. Top level = 0, next item = 1, then 2, 3, ...InText2 (Text) A bullet pointInLevel3 (Integer) The hierarchy level of the item. Top level = 0, next item = 1, then 2, 3, ......InText10 (Text) A bullet pointInLevel10 (Integer) The hierarchy level of the item. Top level = 0, next item = 1, then 2, 3, ...
MSWord_InsertBulletList
Insert a bullet point list.
ParametersInDocument (MSWord_Document) The document to manipulate.InTexts (MSWordListItem List) The bullet pointsBulletType (Text) "Bullet" or "Number"Font (Text) The font familyFontSize (Decimal) The font size
MSWord_InsertBulletText
Helper action to insert a bullet point list with a single item
ParametersInDocument (MSWord_Document) The document to manipulate.InText (Text) A single bullet pointBulletType (Text) "Bullet" or "Number"Font (Text) The font familyFontSize (Decimal) The font size
MSWord_InsertBulletText2 .. 10
Helper actions to insert bullet point lists with different numbers of items
ParametersInDocument (MSWord_Document) The document to manipulate.BulletType (Text) "Bullet" or "Number"Font (Text) The font familyFontSize (Decimal) The font sizeInText1 .. 10 (Text) A single bullet point
MSWord_InsertFormattedTextInsert formatted textParametersInDocument (MSWord_Document) The document to manipulate.InText (MSWordText) The text to insertMSWord_InsertHeadingInsert text as a headingParametersInDocument (MSWordDocument) The document to manipulate.InLevel (Integer) The heading level 1-9InText (Text) Text for the headingMSWord_InsertImageInsert an image into the documentParametersInDocument (MSWordDocument) The document to manipulate.InImage (BinaryData) The image content to insert into the document as binary data.InHeight (Integer) The height of the image Ignored if zero.InWidth (Integer) The width of the image. Ignored if zero.Alignment (Text) Left, Right or Center.MSWord_InsertImageInFooterInsert an image in the footer.ParametersInDocument (MSWordDocument) The document to manipulate.InFooter (Text) The footer, "Odd", "Even" or "First". If empty defaults to "Odd" which is the footer used when there is no separate even/odd or first header/footer.InImage (BinaryData) The image content to insert into the document as binary data.InHeight (Integer) The height of the image Ignored if zero.InWidth (Integer) The width of the image. Ignored if zero.Alignment (Text) Left, Right or Center.MSWord_InsertImageInHeaderInsert an image in the header.ParametersInDocument (MSWordDocument) The document to manipulate.InHeader (Text) The footer, "Odd", "Even" or "First". If empty defaults to "Odd" which is the heading used when there is no separate even/odd or first header/footer.InImage (BinaryData) The image content to insert into the document as binary data.InHeight (Integer) The height of the image Ignored if zero.InWidth (Integer) The width of the image. Ignored if zero.Alignment (Text) Left, Right or Center.MSWord_InsertInFooterInsert a paragraph in the footer.ParametersInDocument (MSWordDocument) The document to manipulate.InFooter (Text) The footer, "Odd", "Even" or "First". If empty defaults to "Odd" which is the footer.InParagraph (MSWordParagraph) The paragraph to insert.MSWord_InsertInHeaderInsert a paragraph in the header.ParametersInDocument (MSWordDocument) The document to manipulate.InHeader (Text) The footer, "Odd", "Even" or "First". If empty defaults to "Odd" which is the header.InParagraph (MSWordParagraph) The paragraph to insert.MSWord_InsertPageBreakInsert a page break.ParametersInDocument (MSWordDocument) The document to manipulate.MSWord_InsertParagraphInsert a paragraph.ParametersInDocument (MSWordDocument) The document to manipulate.InParagraph (MSWordParagraph) The paragraph to insert.MSWord_InsertTableInsert a table.ParametersInDocument (MSWordDocument) The document to manipulate.InTable (MSWordTable) The table to insert.MSWord_InsertTablesInserts multiple tables.ParametersInDocument (MSWordDocument) The document to manipulate.InTables (MSWordTable List) The tables to insert.InParagraphs (MSWordParagraph List) The paragraphs to insert after tables. The first paragraph, if specified, is added after the first table, the second paragraph, if specified, is added after the second table and so on.MSWord_InsertTextInsert a paragraph with the specified text content.ParametersInDocument (MSWordDocument) The document to manipulate.InText (Text) The text to insert.MSWord_InsertText2Insert 2 paragraphs with the specified text content.ParametersInDocument (MSWordDocument) The document to manipulate.InText1 (Text) The text to insert.InText2 (Text) The text to insert.MSWord_InsertText3Insert 3 paragraphs with the specified text content.ParametersInDocument (MSWordDocument) The document to manipulate.InText1 (Text) The text to insert.InText2 (Text) The text to insert.InText3 (Text) The text to insert.MSWord_InsertText4..8Helper action to insert 4 to 8 paragraphs with the specified text content.ParametersInDocument (MSWordDocument) The document to manipulate.InText1 (Text) The text to insert.InText2 (Text) The text to insert.InText3 (Text) The text to insert....InText8 (Text) The text to insert.MSWord_InsertTextFormat1Insert formatted textParametersInDocument (MSWordDocument) The document to manipulate.InText (MSWordText) Text with format options.SpacingAfter (Decimal) Space after the paragraphAlignment (Text) Left, Right, Center or Both. Both aligns the paragraph's text to both the left and right margins, adding extra space between the content as necessary.MSWord_InsertTextFormat2Insert formatted textParametersInDocument (MSWordDocument) The document to manipulate.InText1 (MSWordText) Text with format options.InText2 (MSWordText) Text with format options.SpacingAfter (Decimal) Space after the paragraphAlignment (Text) Left, Right, Center or Both. Both aligns the paragraph's text to both the left and right margins, adding extra space between the content as necessary.MSWord_InsertTextFormat3Insert formatted textParametersInDocument (MSWordDocument) The document to manipulate.InText1 (MSWordText) Text with format options.InText2 (MSWordText) Text with format options.InText3 (MSWordText) Text with format options.SpacingAfter (Decimal) Space after the paragraphAlignment (Text) Left, Right, Center or Both. Both aligns the paragraph's text to both the left and right margins, adding extra space between the content as necessary.MSWord_InsertTextFormat4..6Insert formatted textParametersInDocument (MSWordDocument) The document to manipulate.InText1 (MSWordText) Text with format options.InText2 (MSWordText) Text with format options.InText3 (MSWordText) Text with format options....InText6 (MSWordText) Text with format options.SpacingAfter (Decimal) Space after the paragraphAlignment (Text) Left, Right, Center or Both. Both aligns the paragraph's text to both the left and right margins, adding extra space between the content as necessary.MSWord_MakeDecimalListMake a list of decimals. Useful for creating a list of column width percentages for a table.ParametersDecimal1 (Decimal) A decimal number.Decimal2 (Decimal) A decimal number.Decimal3 (Decimal) A decimal number....Decimal10 (Decimal) A decimal number.Decimals (Out, Decimal List) A list of percentage widths of each column. eg 10%, 20%, 50%, 20%.MSWord_MakeParagraphCombine text attributes into a paragraph structureParametersText1 (Text) Text to insertText2 (Text) Text to insertText3 (Text) Text to insert...Text6 (Text) Text to insertParagraph (Out, MSWordParagraph) A paragraph structure containing the provided textMSWord_MakeTextCreate an MSWordText structureParametersText (Text) The text to insertFont (Text) The font nameFontSize (Decimal) The font sizeColor (Text) The text colorBold (Boolean) Bold textItalic (Boolean) Italic textUnderline (Boolean) Underline textSuperscript (Boolean) Superscript textSubscript (Boolean) Subscript textCaps (Boolean) UPPERCASE textSmallcaps (Boolean) Small UPPERCASE textHighlight (Boolean) Highlight textMSWord_OpenDocumentOpen an MSWord docx document for editing. The binary content will not be changed, to retrieve the edits, a new set of binary content will be generated.ParametersInContent (BinaryData) An MSWord docx document as binary content.OutDocument (Out, MSWordDocument) The reference to the document, to be used with other library actions.MSWord_ReplaceBookmarksWithTextReplace multiple bookmarks with text.ParametersInDocument (MSWordDocument) The document to manipulate.InReplacements (MSWordReplaceWithText List) The replacements to make to the document.MSWord_ReplaceBookmarkWithImageInsert an image into the document at the bookmark.ParametersInDocument (MSWordDocument) The document to manipulate.InBookmark (Text) The bookmark where the image will be inserted.InImage (BinaryData) The image to insert into the document as binary data.InHeight (Integer) The height of the image Ignored if zero.InWidth (Integer) The width of the image. Ignored if zero.MSWord_ReplaceBookmarkWithTableReplace the bookmark with the table. Removes the paragraph where the bookmark is found.ParametersInDocument (MSWordDocument) The document to manipulate.InBookmark (Text) The name of the bookmark where the table will be inserted.InTable (MSWordTable) The table to insertMSWord_ReplaceBookmarkWithTablesReplace the bookmark with multiple tables. Removes the paragraph where the bookmark is found. Optional paragraphs, if specified are added after each table.ParametersInDocument (MSWordDocument) The document to manipulate.InBookmark (Text) The name of the bookmark where the table will be inserted.InTables (MSWordTable List) The tables to insertInParagraphs (MSWordParagraph List) The paragraphs to insert after tables. The first paragraph, if specified, is added after the first table, the second paragraph, if specified, is added after the second table and so on.MSWord_ReplaceBookmarkWithTextReplace a bookmark with textParametersInDocument (MSWordDocument) The document to manipulate.InBookmarkName (Text) The name of the bookmark where the text will be inserted.InReplaceText (Text) The text to insertMSWord_ReplaceTextReplace text in the documentParametersInDocument (MSWordDocument) The document to manipulate.InSearchText (Text) The text to search for.InReplaceText (Text) The text to insert.
Structures
The plugin exposes the following structures.
MSWordDocument
A reference to the MSWord document to manipulate.
AttributesId (Text): The document identifier
MSWordFormat
Text formatting options.
AttributesFont (Text) The font nameFontSize (Decimal) The font sizeColor (Text) The text colorBold (Boolean) Bold textItalic (Boolean) Italic textUnderline (Boolean) Underline textSuperscript (Boolean) Superscript textSubscript (Boolean) Subscript textCaps (Boolean) UPPERCASE textSmallcaps (Boolean) Small UPPERCASE textHighlight (Boolean) Highlight text
MSWordImage
An image to insert
AttributesImage (BinaryData) The image contentHeight (Integer) The height of the image in the documentWidth (Integer) The width of the image in the documentAlignment (Text) Left, Right or Center
MSWordParagraph
A paragraph with a list of text items to insert.
AttributesTexts (List of MSWordText) Text items to insertSpacing After (Decimal) Space after the paragraph.Alignment (Text) Left, Right, Center or Both. Both aligns the paragraph's text to both the left and right margins, adding extra space between the content as necessary.Break (Text) Page break before or after the paragraph. If empty, no break, if "Before", inserts a page break before the paragraph, if "After" inserts a page break after the paragraph.
MSWordReplaceWithPictureAn identifier and image content.AttributesIdentifier (Text) Identifier, either text or a bookmark where the picture is inserted.Picture (BinaryData) Image contentMSWordReplaceWithTextAn identifier and text for the replacement.AttributesIdentifier (Text) Identifier, either text or a bookmark where the picture is inserted.Text (Text) Text to be inserted.MSWordTableA table with rows, cells and formatting.AttributesRows (MSWordTableRow List) Rows of the tableDesign (MSWordTableDesign Identifier) The table design.Alignment (Text) Left, Right, or Center.PercentWidths (Decimal List) A list of percentage widths of each column. eg 10%, 20%, 50%, 20%.Autofit (Text) Auto fit the table width. "Window" expands the table to the width of the page and autofits the columns. "Contents" shrinks the width of the table to just enough to hold the table contents.Width (Decimal) Width of the tableMSWordTableCellA cell in a table, with optional formatting and image.AttributesText (Text) The text for the cellHyperlinkUrl (Text) Turns the text into a hyperlink with the specified URL.Colspan (Integer) If greater than 1, the number of columns this cell spans.Colskip (Integer) If greater than zero, the number of columns to skip before this cell.Width (Decimal) Width of the cell.Format (MSWordFormat) Format of the cell textListType (Text) The type of the bullet point list, either "Bullet" or "Number". Only used if there are ListItemsListItems (MSWordListItem List) A list of bullet points to be displayed in the cell. Inserted after the text.Image (MSWordImage) An image to insert into the cell. Inserted after the text.MSWordTableRowA row in a table.AttributesCells (MSWordTableCell List) the row's contentBreakAcrossPages (Boolean) If False, the row will not break across pages. Default = True.TableHeader (Boolean) True if this is the table header. Default False.Height (Integer) Height of the row.MinHeight (Integer) Minimum height of the row.
MSWordTextText with formatting to insert
AttributesText (Text) The text to insertHyperlinkUrl (Text) If specified, turns the text into a hyperlink with the specified URLFont (Text) The font nameFontSize (Decimal) The font sizeColor (Text) The text colorBold (Boolean) Bold textItalic (Boolean) Italic textUnderline (Boolean) Underline textSuperscript (Boolean) Superscript textSubscript (Boolean) Subscript textCaps (Boolean) UPPERCASE textSmallcaps (Boolean) Small UPPERCASE textHighlight (Boolean) Highlight text
MSWordListItem
A bullet point
AttributesText (Text) The bullet point textLevel (Integer) The hierarchy level of the item. Top level = 0, next item = 1, then 2, 3, ...
Entities
MSWordTableDesignA static entity enumerating MSWord table designs
Roadmap
Next Release
Extract all text from the document in plain text
Add formatting options to individual list items; bold, italic, underline
Fix MSWord_MakeText, the assignment for Highlight is around the wrong way. Also Highlight should accept hex codes as well as "yellow" and other colour names eg "#ff0000"
Future Releases
-
Investigations
(x) Right to Left text. The DocX library appears to have some support for RTL text but when tested it does not work. I tried inserting RTL characters in inserted text as well as setting the paragraph direction to RightToLeft. Neither of these options worked, so unfortunately this module will not support RTL text.
Team Membership Agreement
As a member of this team, I agree to abide by the following rules: