protected void DoWriteText(string text, TextOptions options) { options ??= new TextOptions(); var book = options.Book?.Document ?? Document; book.BeginUpdate(); try { var range = book.AppendText(text); if (options != null) { if (!string.IsNullOrWhiteSpace(options.ParagraphStyle)) { var style = book.ParagraphStyles[options.ParagraphStyle] ?? throw new Exception($"Paragraph style '{options.ParagraphStyle}' does not exist."); var pp = book.BeginUpdateParagraphs(range); try { pp.Style = style; } finally { book.EndUpdateParagraphs(pp); } } var foregroundColor = ColorExtensions.FromHtmlColor(options.ForegroundColor, SystemColors.WindowText); var backgroundColor = ColorExtensions.FromHtmlColor(options.BackgroundColor, SystemColors.Window); var underlineColor = ColorExtensions.FromHtmlColor(options.UnderlineColor, Color.Empty); if (foregroundColor != SystemColors.WindowText || backgroundColor != SystemColors.Window || options.FontName != null || options.FontSize.HasValue || options.Bold.HasValue || options.Italic.HasValue || options.Underline.HasValue || options.Subscript.HasValue || options.Superscript.HasValue || options.UnderlineType.HasValue || underlineColor != Color.Empty || !string.IsNullOrWhiteSpace(options.CharacterStyle)) { var cp = book.BeginUpdateCharacters(range); try { if (!string.IsNullOrWhiteSpace(options.CharacterStyle)) { var style = book.CharacterStyles[options.CharacterStyle] ?? throw new Exception($"Character style '{options.CharacterStyle}' does not exist."); cp.Style = style; } if (foregroundColor != SystemColors.WindowText) { cp.ForeColor = foregroundColor; } if (backgroundColor != SystemColors.Window) { cp.BackColor = backgroundColor; } if (!string.IsNullOrWhiteSpace(options.FontName)) { cp.FontName = options.FontName; } if (options.FontSize.HasValue && options.FontSize.Value >= 4 && options.FontSize.Value <= 500) { cp.FontSize = options.FontSize.Value; } if (options.Bold.HasValue) { cp.Bold = options.Bold.Value; } if (options.Italic.HasValue) { cp.Italic = options.Italic; } if (options.Underline.HasValue) { cp.Underline = (DevExpress.XtraRichEdit.API.Native.UnderlineType)(options.Underline.Value ? UnderlineType.Single : UnderlineType.None); } if (options.UnderlineType.HasValue) { cp.Underline = (DevExpress.XtraRichEdit.API.Native.UnderlineType)options.UnderlineType; } if (underlineColor != Color.Empty) { cp.UnderlineColor = underlineColor; } if (options.Subscript.HasValue) { cp.Subscript = options.Subscript.Value; } if (options.Superscript.HasValue) { cp.Superscript = options.Superscript.Value; } } finally { book.EndUpdateCharacters(cp); } } if (options.ExpandFields && options.Snippets != null) { Script.Book.SCBook.ExpandFieldsInBookRange(range, Host?.Spreadsheet?.Workbook, options.Snippets); } } Script.Book.SCBook.AddComments(book, range, options); if (range?.End != null) { book.CaretPosition = range.End; Script.Book.SCBook.ResetBookFormatting(book, range.End); ScrollToCaret(); } WriteTextToConsole(text); } finally { book.EndUpdate(); } }
public SCBook WriteText(object obj, TextOptions options = null) => WriteText(Convert.ToString(obj), options);
public SCBook WriteText(string text, TextOptions options = null) { ExecuteSynchronized(options, () => DoWriteText(text, options)); return(this); }
public SCBook WriteLine(string text, TextOptions options = null) => WriteText(text + Environment.NewLine, options);