The requested page is not available for the requested platform. You are viewing the content for .NET Framework 4.5.2+ platform.

Getting Started

  • 3 min to read

This tutorial describes how to get started with the Word Processing Document API.

  1. Start Visual Studio and create a new Console Application (NET Core) project.

  2. In the Solution Explorer, right-click the References node and select Add Reference... in the context menu.

    RichEditDocServer_GettingStarted_AddReference

  3. Add references to the following libraries.

    • System.Drawing.dll (to follow this example only)
    • DevExpress.Data.v19.1.dll
    • DevExpress.Office.v19.1.Core.dll
    • DevExpress.RichEdit.v19.1.Core.dll
    • DevExpress.Printing.v19.1.Core.dll
    • DevExpress.Pdf.v19.1.Core.dll
  4. 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.
    static void Main(string[] args)
    {
        string fileName = "Test.docx";
        using (DevExpress.XtraRichEdit.RichEditDocumentServer srv = 
            new DevExpress.XtraRichEdit.RichEditDocumentServer())
        {
            DevExpress.XtraRichEdit.API.Native.Document doc = srv.Document;
            doc.AppendText("This document is generated by Word Processing Document API");
            DevExpress.XtraRichEdit.API.Native.CharacterProperties cp = doc.BeginUpdateCharacters(doc.Paragraphs[0].Range);
            cp.ForeColor = System.Drawing.Color.FromArgb(0x83, 0x92, 0x96);
            cp.Italic = true;
            doc.EndUpdateCharacters(cp);
            DevExpress.XtraRichEdit.API.Native.ParagraphProperties pp = doc.BeginUpdateParagraphs(doc.Paragraphs[0].Range);
            pp.Alignment = DevExpress.XtraRichEdit.API.Native.ParagraphAlignment.Right;
            doc.EndUpdateParagraphs(pp);
            srv.SaveDocument(fileName, DevExpress.XtraRichEdit.DocumentFormat.OpenXml);
        }
        System.Diagnostics.Process.Start(fileName);
    }
    
  5. Run the project. The generated file appears as follows (the document is opened in Microsoft® Word®).

    RichEditDocServer_GettingStarted_Result

  1. Start Visual Studio and create a new Console Application (NET Core) project.

  2. Install the DevExpress.Document.Processor or DevExpress.RichEdit.Core NuGet package.

    Important

    You require a license to the DevExpress Office File API or DevExpress Universal Subscription to use the DevExpress.Document.Processor package in production code.

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

    static void Main(string[] args)
    {
        string fileName = "Test.docx";
        using (DevExpress.XtraRichEdit.RichEditDocumentServer srv =
            new DevExpress.XtraRichEdit.RichEditDocumentServer())
        {
            DevExpress.XtraRichEdit.API.Native.Document doc = srv.Document;
            doc.AppendText("This document is generated by Word Processing Document API");
            DevExpress.XtraRichEdit.API.Native.CharacterProperties cp = doc.BeginUpdateCharacters(doc.Paragraphs[0].Range);
            cp.ForeColor = System.Drawing.Color.FromArgb(0x83, 0x92, 0x96);
            cp.Italic = true;
            doc.EndUpdateCharacters(cp);
            DevExpress.XtraRichEdit.API.Native.ParagraphProperties pp = doc.BeginUpdateParagraphs(doc.Paragraphs[0].Range);
            pp.Alignment = DevExpress.XtraRichEdit.API.Native.ParagraphAlignment.Right;
            doc.EndUpdateParagraphs(pp);
            srv.SaveDocument(fileName, DevExpress.XtraRichEdit.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