Skip to main content

DevExpress v24.2 Update — Your Feedback Matters

Our What's New in v24.2 webpage includes product-specific surveys. Your response to our survey questions will help us measure product satisfaction for features released in this major update and help us refine our plans for our next major release.

Take the survey Not interested

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.

#Create a .NET Framework Application

  1. Start Visual Studio and create a new Console App (.NET Framework) project.

  2. 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.

  3. 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);
    }
    
  4. Run the project. The generated file appears as follows (the document is opened in Microsoft® Word®).

    RichEditDocServer_GettingStarted_Result

#Create a .NET Application

  1. Start Visual Studio and create a new Console App project.

  2. Install one of the following NuGet Packages:

    • DevExpress.Document.Processor
    • DevExpress.RichEdit.Core

    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.

  3. Paste the code below in the Program.cs file (or the Program.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.Diagnostics;
    using System.Drawing;
    
    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 });
    
  4. Run the project. The generated file appears as follows (the document is opened in Microsoft® Word®).

    RichEditDocServer_GettingStarted_Result