How to Edit DOCX and Convert Formats with GroupDocs.Editor
Effortlessly manage and transform Word documents within your .NET environment using GroupDocs.Editor .NET. In this tutorial you’ll discover how to edit docx files, convert them to formats such as RTF, DOCM, and plain text, and automate your document workflow for maximum productivity.
Quick Answers
- What library is required? GroupDocs.Editor for .NET (20.10+).
- Can I convert a DOCX to RTF? Yes – use
WordProcessingSaveOptionswithWordProcessingFormats.Rtf. - Is saving as TXT supported? Absolutely, via
TextSaveOptions. - Do I need a license? A trial works for development; a license unlocks all features.
- How to handle many files? Combine the code with async/await or Parallel.ForEach for batch processing.
What is “how to edit docx” with GroupDocs.Editor?
GroupDocs.Editor loads a DOCX, exposes its content as editable HTML, lets you modify that HTML programmatically, and then saves the result back to any supported format. This approach eliminates the need for Office interop and works on any server‑side .NET platform.
Why use GroupDocs.Editor for document workflow automation?
- Server‑side only – no Office installation required.
- Multiple output formats – RTF, DOCM, TXT, HTML, PDF, etc.
- High performance – lightweight API designed for batch scenarios.
- Full control – edit, replace, or inject HTML fragments before saving.
Prerequisites
- GroupDocs.Editor library (Version 20.10 or later)
- .NET Framework 4.7.2 + or .NET 5/6
- Visual Studio (any recent edition)
- Basic C# knowledge and familiarity with file I/O
Installing GroupDocs.Editor
You can add the package via the .NET CLI, the Package Manager Console, or the NuGet UI.
dotnet add package GroupDocs.Editor
Install-Package GroupDocs.Editor
License Acquisition
Start with a free trial or request a temporary license key. For production use, purchase a license to unlock unlimited processing.
How to Load and Edit a DOCX Document
First, point the editor at your source file, then retrieve the editable HTML, make the changes you need, and finally create a new EditableDocument from the modified markup.
using (Editor editor = new Editor("YOUR_DOCUMENT_DIRECTORY/sample.docx", new Options.WordProcessingLoadOptions()))
{
// Your document manipulation code here
}
Step‑by‑Step Code Walkthrough
- Define the input file path
string inputFilePath = "YOUR_DOCUMENT_DIRECTORY/sample.docx";
- Create the
Editorinstance
using GroupDocs.Editor;
using GroupDocs.Editor.Options;
Editor editor = new Editor(inputFilePath, new Options.WordProcessingLoadOptions());
- Edit the document’s HTML
EditableDocument defaultWordProcessingDoc = editor.Edit();
string allEmbeddedInsideString = defaultWordProcessingDoc.GetEmbeddedHtml();
string allEmbeddedInsideStringEdited = allEmbeddedInsideString.Replace("Subtitle", "Edited subtitle");
- Create a new
EditableDocumentfrom the edited HTML
EditableDocument editedDoc = EditableDocument.FromMarkup(allEmbeddedInsideStringEdited, null);
- Dispose of temporary objects
editedDoc.Dispose();
defaultWordProcessingDoc.Dispose();
editor.Dispose();
How to Convert Word to RTF
Saving the edited document as RTF is straightforward with the appropriate save options.
string outputRtfPath = Path.Combine("YOUR_OUTPUT_DIRECTORY", "editedDoc.rtf");
WordProcessingSaveOptions rtfSaveOptions = new WordProcessingSaveOptions(WordProcessingFormats.Rtf);
using (Editor editor = new Editor(inputFilePath, new Options.WordProcessingLoadOptions()))
{
editor.Save(editedDoc, outputRtfPath, rtfSaveOptions);
}
editor.Dispose();
How to Save DOCX as DOCM Using a Stream
When you need the macro‑enabled DOCM format, you can write directly to a FileStream.
string outputDocmPath = Path.Combine("YOUR_OUTPUT_DIRECTORY", "editedDoc.docm");
WordProcessingSaveOptions docmSaveOptions = new WordProcessingSaveOptions(WordProcessingFormats.Docm);
using (Editor editor = new Editor(inputFilePath, new Options.WordProcessingLoadOptions()))
{
using (FileStream outputStream = File.Create(outputDocmPath))
{
editor.Save(editedDoc, outputStream, docmSaveOptions);
}
}
editor.Dispose();
How to Convert DOCX to TXT (Plain Text)
Plain‑text extraction is useful for indexing, search, or email notifications.
string outputTxtPath = Path.Combine("YOUR_OUTPUT_DIRECTORY", "editedDoc.txt");
TextSaveOptions textSaveOptions = new TextSaveOptions()
{
Encoding = Encoding.UTF8,
PreserveTableLayout = true
};
using (Editor editor = new Editor(inputFilePath, new Options.WordProcessingLoadOptions()))
{
editor.Save(editedDoc, outputTxtPath, textSaveOptions);
}
editor.Dispose();
Common Use Cases & Real‑World Scenarios
- Automated Report Generation: Convert analytical Word reports to TXT for email distribution.
- Collaborative Editing Platforms: Let users edit HTML fragments and store the result as DOCM or RTF.
- Document Archiving: Migrate legacy DOCX files to DOCM for macro support while preserving content.
- Web Services: Stream DOCX → PDF/RTF conversions on the fly without temporary files.
Performance Tips for Batch Process Word Docs
- Dispose promptly: Always call
Dispose()onEditorand document objects. - Load wisely: Choose the most specific
LoadOptionsto avoid unnecessary parsing. - Parallelize safely: Use
Parallel.ForEachwith separateEditorinstances per thread. - Avoid large in‑memory strings: When processing huge documents, work with streams instead of full HTML strings.
Frequently Asked Questions
Q: Can I edit a password‑protected DOCX?
A: Yes. Supply the password via WordProcessingLoadOptions.Password when creating the Editor.
Q: Is it possible to convert many files in one run?
A: Absolutely. Wrap the single‑file logic in a loop or use Parallel.ForEach for concurrent processing.
Q: Does GroupDocs.Editor support .NET Core?
A: The library works with .NET 5, .NET 6, and .NET Core 3.1 as well as the full .NET Framework.
Q: What happens to macros when I save as DOCM?
A: Macros are preserved when you use the Docm save format; they are stripped for RTF/TXT.
Q: How can I troubleshoot “OutOfMemoryException” during large batch jobs?
A: Process files in smaller batches, dispose objects immediately, and consider increasing the application’s memory limit.
Conclusion
You now have a complete, production‑ready workflow for how to edit docx files and convert them to RTF, DOCM, or plain text using GroupDocs.Editor .NET. By following the steps above you can automate document workflows, handle batch processing, and integrate seamless format conversion into any .NET application.
Last Updated: 2026-04-07
Tested With: GroupDocs.Editor 20.10 (latest at time of writing)
Author: GroupDocs