DocX
Fast and easy to use .NET library that creates or modifies Microsoft Word files without installing Word.
Top Related Projects
A pure PHP library for reading and writing word processing documents
Open XML SDK by Microsoft
JAXB-based Java library for Word docx, Powerpoint pptx, and Excel xlsx files
Quick Overview
DocX is a .NET library for creating and manipulating Word documents without requiring Microsoft Word to be installed. It provides a simple and efficient way to programmatically generate, edit, and analyze Word documents, making it ideal for server-side document processing and automation tasks.
Pros
- Easy to use with a clean and intuitive API
- No dependency on Microsoft Word, making it suitable for server environments
- Supports a wide range of document manipulation tasks, including text insertion, formatting, and image handling
- Actively maintained with regular updates and bug fixes
Cons
- Limited support for complex document structures and advanced Word features
- Performance may be slower compared to native Word automation for very large documents
- Some formatting options might not be as extensive as those available in Microsoft Word
- Learning curve for developers unfamiliar with Word document structure
Code Examples
- Creating a new document and adding text:
using Xceed.Words.NET;
using (var document = DocX.Create("Example.docx"))
{
document.InsertParagraph("Hello, World!");
document.Save();
}
- Adding a table to a document:
using Xceed.Words.NET;
using (var document = DocX.Load("Example.docx"))
{
var table = document.AddTable(3, 2);
table.Rows[0].Cells[0].Paragraphs[0].Append("Header 1");
table.Rows[0].Cells[1].Paragraphs[0].Append("Header 2");
document.InsertTable(table);
document.Save();
}
- Applying formatting to text:
using Xceed.Words.NET;
using (var document = DocX.Load("Example.docx"))
{
var paragraph = document.InsertParagraph("Formatted text");
paragraph.Color(System.Drawing.Color.Red).Bold().Font("Arial");
document.Save();
}
Getting Started
-
Install the DocX NuGet package in your project:
Install-Package DocX
-
Add the following using statement to your C# file:
using Xceed.Words.NET;
-
Create a new document or load an existing one:
var document = DocX.Create("NewDocument.docx"); // or var document = DocX.Load("ExistingDocument.docx");
-
Manipulate the document as needed and save changes:
document.InsertParagraph("Your content here"); document.Save();
Competitor Comparisons
A pure PHP library for reading and writing word processing documents
Pros of PHPWord
- Cross-platform compatibility: Works on various operating systems
- Extensive documentation and community support
- Supports a wide range of document formats (DOC, DOCX, RTF, HTML, PDF)
Cons of PHPWord
- Slower performance compared to DocX
- Steeper learning curve for beginners
- Requires PHP environment, limiting its use in other programming languages
Code Comparison
PHPWord:
$phpWord = new \PhpOffice\PhpWord\PhpWord();
$section = $phpWord->addSection();
$section->addText('Hello World!');
$objWriter = \PhpOffice\PhpWord\IOFactory::createWriter($phpWord, 'Word2007');
$objWriter->save('helloWorld.docx');
DocX:
using (var doc = DocX.Create("Test.docx"))
{
doc.InsertParagraph("Hello World!");
doc.Save();
}
Both libraries offer straightforward ways to create simple documents. PHPWord requires more setup but provides more flexibility, while DocX offers a more concise syntax for basic operations. The choice between them depends on the specific project requirements, programming language preferences, and the complexity of the documents being created.
Open XML SDK by Microsoft
Pros of Open-XML-SDK
- More comprehensive and feature-rich, supporting a wider range of Office document formats
- Better suited for complex document manipulation and generation
- Officially maintained by Microsoft, ensuring long-term support and compatibility
Cons of Open-XML-SDK
- Steeper learning curve due to its complexity and extensive API
- Requires more code to perform simple tasks compared to DocX
- Larger library size, which may impact application size and performance
Code Comparison
DocX example:
using (var doc = DocX.Create("Sample.docx"))
{
doc.InsertParagraph("Hello, World!");
doc.Save();
}
Open-XML-SDK example:
using (var doc = WordprocessingDocument.Create("Sample.docx", WordprocessingDocumentType.Document))
{
var mainPart = doc.AddMainDocumentPart();
mainPart.Document = new Document(new Body(new Paragraph(new Run(new Text("Hello, World!")))));
doc.Save();
}
Both libraries allow for creating and manipulating Word documents, but Open-XML-SDK requires more verbose code for simple tasks. DocX provides a more straightforward API for basic operations, while Open-XML-SDK offers greater flexibility and control over document structure and content.
JAXB-based Java library for Word docx, Powerpoint pptx, and Excel xlsx files
Pros of docx4j
- More comprehensive feature set, including support for OOXML formats beyond .docx (e.g., .pptx, .xlsx)
- Better handling of complex document structures and formatting
- Actively maintained with regular updates and improvements
Cons of docx4j
- Steeper learning curve due to its more extensive API
- Larger library size, which may impact application size and performance
- Requires more setup and configuration compared to DocX
Code Comparison
DocX example:
using (var doc = DocX.Create("Example.docx"))
{
doc.InsertParagraph("Hello, World!");
doc.Save();
}
docx4j example:
WordprocessingMLPackage wordMLPackage = WordprocessingMLPackage.createPackage();
MainDocumentPart mainDocumentPart = wordMLPackage.getMainDocumentPart();
mainDocumentPart.addParagraphOfText("Hello, World!");
wordMLPackage.save(new File("Example.docx"));
Both libraries provide methods for creating and manipulating Word documents, but docx4j offers a more granular approach with its object model, while DocX provides a simpler API for basic operations.
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual CopilotREADME
What is DocX?
DocX is a .NET library that allows developers to manipulate Word 2007/2010/2013 files, in an easy and intuitive manner. DocX is fast, lightweight and best of all it does not require Microsoft Word or Office to be installed.
NOTE: There is a new Master branch as of Oct. 3, 2017. Please read about the Classic branch if you were using this project before the change.
DocX is the free, open source version of Xceed Words for .NET. Originally written by Cathal Coffey, and maintained by Przemyslaw Klys, it is now maintained by Xceed. Starting at v1.5.0, this free and open source product is provided under the Xceed Community License agreement(for non-commercial use).
Currently, the differences between DocX and Xceed Words for .NET, is that Xceed Words for .NET :
- can convert a Word document to PDF
- adds properties to wrap text around Pictures/Tables/Shapes
- adds Picture cropping
- adds Shapes (rectangles for now)
- adds TextBoxes or Shapes containing Text
- gets Shapes from Paragraphs
- gets Charts from Paragraphs and can modify their categories/values
- More properties in Charts configuration like axis Label position and series width
- is at least two versions ahead of the DocX version
- has professional technical support included in the subscription
- can automatically update fields from a document
- Insert html/rtf text (with tags), or html/rtf document, to a Word document
- Clone lists or tables
- Add or modify checkboxes
- Set transparency in pictures
- Create formatted hyperlinks based on a referenced hyperlinks
- Joining 2 documents gives the opportunity to choose the headers/footers of doc1, doc2 or both of them in the resulting document.
- Automatic hyphenations and configurable hyphenations
- Digital signatures can be added to documents in the .NET Framework environment
- Add footnotes and endnotes
- ListOptions for List level configurations
- Modify Chart's Series Marker and DataPoint styles
- Insert a document at a specific point in another document
- Wrap text around Charts
- Format Charts Axis' title
- Replace text with html
What else do I need?
All that you need to install in order to use DocX is the .NET framework 4.0 or .NET5+ and Visual Studio 2010 or later, both of which are free.
What are the main features of DocX?
Edition | DocX | Xceed Words for .NET |
Price | Free | $599.95 |
License | Xceed Community License | Proprietary |
Email support | YES | |
Create new Word documents | YES | YES |
Modify Word documents | YES | YES |
Create new PDF documents | YES | |
Convert Word to PDF | YES | |
Supports .DOCX from Word 2007 and up | YES | YES |
Modify multiple documents in parallel for better performance | YES | YES |
Apply a template to a Word document | YES | YES |
Join documents, recreate portions from one to another | YES | YES |
Supports document protection with or without password | YES | YES |
Set document margins and page size | YES | YES |
Set line spacing, indentation, text direction, text alignment | YES | YES |
Wrap text around pictures | YES | |
Pictures with cropping | YES | |
Manage fonts and font sizes | YES | YES |
Set text color, bold, underline, italic, strikethrough, highlighting | YES | YES |
Set page numbering | YES | YES |
Create sections | YES | YES |
Available on .net for .net 5+ applications | YES | YES |
Update document fields (ex: a table of contents) by calling only one method | YES | |
Wrap text around tables | YES | |
Wrap text around shapes | YES | |
Create shapes (rectangles for now) | YES | |
Create textboxes or shapes containing text | YES | |
Get shapes from paragraphs | YES | |
Get charts from paragraphs and modify their categories/values | YES | |
Update document fields with 1 method call | YES | |
Insert html/rtf text (with tags), or html/rtf document, to a Word document | YES | |
Clone lists or tables | YES | |
Add or modify checkboxes | YES | |
Set transparency in pictures | YES | |
Create formatted hyperlinks based on a referenced hyperlinks | YES | |
Joining 2 documents gives the opportunity to choose which headers/footers to use | YES | |
More properties to configure Charts | YES | |
Automatic Hyphenations and configurable hyphenations | YES | |
Digital signatures in .NET Framework | YES | |
Add footnotes and endnotes | YES | |
ListOptions for List level configurations | YES | |
Modify Chart's Series Marker and DataPoint styles | YES | |
Insert a document at a specific point in another document | YES | |
Wrap text around Charts | YES | |
Format Charts Axis' title | YES | |
Replace text with html | YES | |
Get release ahead | YES |
Supported Word document elements
- Add headers or footers which can be the same on all pages, or unique for the first page, or unique for odd/even pages. Can contain images, hyperlinks and more.
- Insert/Modify paragraphs.
- Insert/Modify numbered or bulleted lists.
- Insert/Modify images. Flip, rotate, copy, modify, resize.
- Insert/Modify tables. Insert/Remove rows, columns, change direction, column width, row height, borders, merge/delete cells.
- Insert/Modify formatted equations or formulas.
- Insert/Modify bookmarks.
- Insert/Modify hyperlinks.
- Insert/Modify horizontal lines.
- Insert/Modify charts (bar, line, pie, 3D chart). Set colors, titles, legend, etc.
- Find, remove or replace text. Supports case sensitivity and regular expressions.
- Insert/Modify core or custom properties, such as author, address, subject, title, etc.
- Insert a Table Of Contents. Set title, change formatting.
Why would I use DocX?
DocX makes creating and manipulating documents a simple task. It does not use COM libraries nor does it require Microsoft Office to be installed.
The following blog post from Cathal Coffey compares the code used to create a HelloWorld document using:
- Office Interop libraries,
- OOXML SDK,
- DocX
Advanced Examples
- Step by step guide to create an invoice for a company. http://cathalscorner.blogspot.com/2009/08/docx-v1007-released.html
- Replace text across many documents in Parallel. http://cathalscorner.blogspot.com/2010/12/replace-text-across-many-documents-in.html
- Programmatically manipulate an Image imbedded inside a document. http://cathalscorner.blogspot.com/2010/12/programmatically-manipulate-image.html
- Converting DocX into (.doc, .pdf, .html) http://cathalscorner.blogspot.com/2009/10/converting-docx-into-doc-pdf-html.html
Do you have an interesting or informative example that you would like to share? If you do, please email me.
License Information
DocX is provided under the Xceed Software, Inc. Community License.
More information can be found in the License page.
A commercial license can be purchased at Xceed.
Release history
- July 5, 2024, released DocX v3.0.1 with 6 bug fixes and improvements.
- March 4, 2024, released Xceed Words for .NET v3.0.1 with 17 bug fixes and improvements.
- January 22, 2024, released DocX v3.0.0 with 14 bug fixes and improvements.
- October 23, 2023, released Xceed Words for .NET v3.0.0 with 21 bug fixes and improvements.
- August 11, 2023, released DocX v2.5.0 with 11 bug fixes and improvements.
- April 3, 2023, released Xceed Words for .NET v2.5.0 with 31 bug fixes and improvements.
- November 28, 2022, released DocX v2.4.0 with 14 bug fixes and improvements.
- October 5, 2022, released Xceed Words for .NET v2.4.0 with 32 bug fixes and improvements.
- September 15, 2022, released DocX v2.3.0 with 7 bug fixes and improvements.
- June 1, 2022, released DocX v2.2.0 with 5 bug fixes and improvements.
- May 14, 2022, released Xceed Words for .NET v2.3.0 with 15 bug fixes and improvements.
- March 22, 2022, released DocX v2.1.0 with 22 bug fixes and improvements.
- February 4, 2022, released Xceed Words for .NET v2.2.0 with 17 bug fixes and improvements.
- December 2, 2021, released DocX v2.0.0 with 10 bug fixes and improvements.
- November 15, 2021, released Xceed Words for .NET v2.1.0 with 44 bug fixes and improvements.
- July 19, 2021, released Xceed Words for .NET v2.0.0 with 49 bug fixes and improvements.
- May 18, 2021, released DocX v1.8.0 with 11 bug fixes and improvements.
- January 25, 2021, released Xceed Words for .NET v1.8.0 with 30 bug fixes and improvements.
- September 22, 2020, released DocX v1.7.1 with 19 bug fixes and improvements.
- August 17, 2020, released Xceed Words for .NET v1.7.1 with 28 bug fixes and improvements.
- June 29, 2020, released DocX v1.7.0 with 27 bug fixes and improvements.
- January 30, 2020, released DocX v1.6.0 with 24 bug fixes and improvements.
- January 30, 2020, released Xceed Words for .NET v1.7.0 with 62 bug fixes and improvements.
- November 26, 2019, released DocX v1.5.0 with 19 bug fixes and improvements.
- October 4, 2019, released DocX v1.4.1 with 12 bug fixes and improvements.
- February 21, 2019, released DocX v1.3.0 with 12 bug fixes and improvements.
- January 28, 2019, released Xceed Words for .NET v1.6.0 with 71 bug fixes and improvements.
- June 27, 2018, released DocX v1.2.0 with 13 bug fixes and improvements.
- June 18, 2018, released Xceed Words for .NET v1.5.0 with 71 bug fixes and improvements.
- April 12, 2018, released Xceed Words for .NET v1.4.1 with 22 bug fixes and improvements.
- January 15, 2018, released Xceed Words for .NET v1.4.0 with 19 bug fixes and improvements.
- September 12, 2017, released Xceed Words for .NET v1.3.0 with 13 bug fixes and improvements.
- June 5, 2017, released Xceed Words for .NET v1.2.0 with 13 bug fixes and improvements.
- October 3, 2017, released DocX v1.1.0 with 6 bug fixes and improvements.
- March 1, 2017, released Xceed Words for .NET v1.1.0 with 6 bug fixes and improvements.
Top Related Projects
A pure PHP library for reading and writing word processing documents
Open XML SDK by Microsoft
JAXB-based Java library for Word docx, Powerpoint pptx, and Excel xlsx files
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual Copilot