How to: Get Started with the Rich Edit Document Server
- 2 minutes to read
This tutorial describes how to get started with the non-visual RichEditDocumentServer component, which implements the complete word-processing functionality available using its API.
Start Visual Studio and create a new project by selecting FILE | New | Project… in the main menu. In the invoked New Project dialog, select Console Application, specify the project name and location, and click OK.
In the Solution Explorer, right-click the References node and select Add Reference… in the context menu.
In the invoked Reference Manager dialog, add references to the following libraries.
- DevExpress.Data.v17.2.dll
- DevExpress.Office.v17.2.Core.dll
- DevExpress.RichEdit.v17.2.Core.dll
Note
To follow this example, you should also include a reference to the System.
Drawing. library, since the code example below uses the Color.dll From method to set the font color of the specified text.Argb 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 RichEditDocumentServerTest.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; // ... string fileName = "RichEditDocumentServerTest.docx"; using (RichEditDocumentServer srv = new RichEditDocumentServer()) { Document doc = srv.Document; doc.AppendText("This document is generated by the RichEdit Document Server"); 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); srv.SaveDocument(fileName, DocumentFormat.OpenXml); } System.Diagnostics.Process.Start(fileName);
- Run the project.
The following image demonstrates the file generated after executing the code above (the document is opened in Microsoft® Word®).