All docs
V21.2
21.2
21.1
20.2
20.1
The page you are viewing does not exist in version 20.1. This link will take you to the root page.
19.2
The page you are viewing does not exist in version 19.2. This link will take you to the root page.
19.1
The page you are viewing does not exist in version 19.1. This link will take you to the root page.
18.2
The page you are viewing does not exist in version 18.2. This link will take you to the root page.

Text

  • 2 minutes to read

Get the whole text of the main sub-document

var mainSubDocumentText = richEdit.document.getText();

Get the selected text

var selectedText = richEdit.selection.activeSubDocument.getText(richEdit.selection.intervals[0]);

Get the main sub-document’s content length

var mainSubDocumentLength = richEdit.document.length;
// or 
var mainSubDocumentLength = richEdit.document.subDocuments.main.length; 

Insert text at the cursor position

var subDocument = richEdit.selection.activeSubDocument;
var position = richEdit.selection.active;
subDocument.insertText(position, 'text');

Insert text at the end of the active sub-document

var subDocument = richEdit.selection.activeSubDocument;
var position = subDocument.length - 1;
subDocument.insertText(position, 'text'); 

Insert text at the end of the main sub-document

var subDocument = richEdit.document.subDocuments.main;
subDocument.insertText(subDocument.length - 1, 'text'); 
// or
richEdit.document.insertText(richEdit.document.length - 1, 'text');

Insert text at the start of a header

var createHeaderIfNotExist = true;
var section = richEdit.document.sections.getByIndex(0);
var subDocument = section.getHeader(DevExpress.RichEdit.HeaderFooterType.Primary, createHeaderIfNotExist);
var position = 0;
subDocument.insertText(position, 'text');

Delete all text in the active sub-document

var subDocument = richEdit.selection.activeSubDocument;
subDocument.deleteText(subDocument.interval);

Apply character properties to inserted text

var subDocument = richEdit.selection.activeSubDocument;
var position = richEdit.selection.active;
var characterProperties = {
    bold: true,
    fontName: richEdit.document.fonts.getByIndex(0).name,
    highlightColor: "ffff00",
};

richEdit.history.beginTransaction();
richEdit.beginUpdate();
var interval = subDocument.insertText(position, "text");
subDocument.setCharacterProperties(interval, characterProperties);
richEdit.endUpdate();
richEdit.history.endTransaction();

Insert mail template

var subDocument = richEdit.selection.activeSubDocument;
var position = richEdit.selection.active;
var templateText = '[Type your text here]';

richEdit.beginUpdate();
richEdit.history.beginTransaction();

position = subDocument.insertParagraph(position).interval.end;
position = subDocument.insertParagraph(position).interval.end;
position = subDocument.insertText(position, 'Dear Mr Stanley,').end;
position = subDocument.insertParagraph(position).interval.end;
var tmpTextInterval = subDocument.insertText(position, templateText);
position = tmpTextInterval.end;
position = subDocument.insertParagraph(position).interval.end;

richEdit.endUpdate();
richEdit.history.endTransaction();

richEdit.selection.setSelection(tmpTextInterval);
richEdit.focus();