Get Started - Create a Word Document
- 3 minutes to read
This tutorial describes how to get started with the Word Processing Document API for .NET Framework and .NET Core.
Create a .NET Framework Application
Start Visual Studio and create a new Console Application (.NET Framework) project.
Install the DevExpress.RichEdit.Core NuGet package or add references to the following libraries (if you have the DevExpress Unified Component Installer installed on your machine):
- DevExpress.Data.v24.2.dll
- DevExpress.Drawing.v24.2.dll
- DevExpress.Office.v24.2.Core.dll
- DevExpress.RichEdit.v24.2.Core.dll
- DevExpress.Printing.v24.2.Core.dll
- DevExpress.Pdf.v24.2.Core.dll
To follow this example, you should also add a reference to System.Drawing.dll.
Paste the code from below in the Main method of the Program.cs file (or the Main procedure of the Module1.vb file for Visual Basic). This example creates and saves the Test.docx file, and opens it in the default application registered for this file type.
using DevExpress.XtraRichEdit; using DevExpress.XtraRichEdit.API.Native; using System.Drawing; using System.Diagnostics; static void Main(string[] args) { string fileName = "Test.docx"; using (var wordProcessor = new RichEditDocumentServer()) { Document doc = wordProcessor.Document; doc.AppendText("This document is generated by Word Processing Document API"); CharacterProperties cp = doc.BeginUpdateCharacters(doc.Paragraphs[0].Range); cp.ForeColor = Color.FromArgb(0x83, 0x92, 0x96); cp.Italic = true; doc.EndUpdateCharacters(cp); ParagraphProperties pp = doc.BeginUpdateParagraphs(doc.Paragraphs[0].Range); pp.Alignment = ParagraphAlignment.Right; doc.EndUpdateParagraphs(pp); wordProcessor.SaveDocument(fileName, DocumentFormat.OpenXml); } Process.Start(fileName); }
Run the project. The generated file appears as follows (the document is opened in Microsoft® Word®).
Create a .NET Application
Start Visual Studio and create a new Console Application project.
Install the DevExpress.Document.Processor or DevExpress.RichEdit.Core NuGet package.
Important
You need a license for the DevExpress Office File API Subscription or DevExpress Universal Subscription to use the DevExpress.Document.Processor package in production code.
Paste the code listed below in the Main method of the Program.cs file (or the Main procedure of the Module1.vb file for Visual Basic). This example creates and saves the Test.docx file, and opens it in the default application registered for this file type.
using DevExpress.XtraRichEdit; using DevExpress.XtraRichEdit.API.Native; using System.Drawing; using System.Diagnostics; static void Main(string[] args) { string fileName = "Test.docx"; using (var wordProcessor = new RichEditDocumentServer()) { Document doc = wordProcessor.Document; doc.AppendText("This document is generated by Word Processing Document API"); CharacterProperties cp = doc.BeginUpdateCharacters(doc.Paragraphs[0].Range); cp.ForeColor = Color.FromArgb(0x83, 0x92, 0x96); cp.Italic = true; doc.EndUpdateCharacters(cp); ParagraphProperties pp = doc.BeginUpdateParagraphs(doc.Paragraphs[0].Range); pp.Alignment = ParagraphAlignment.Right; doc.EndUpdateParagraphs(pp); wordProcessor.SaveDocument(fileName, DocumentFormat.OpenXml); } Process.Start(new ProcessStartInfo(fileName) { UseShellExecute = true }); }
Run the project. The generated file appears as follows (the document is opened in Microsoft® Word®).