public void AddText(string text, OpenXmlRunPropertiesModel style) { if (!string.IsNullOrEmpty(text)) { StringBuilder stringBuilder = new StringBuilder(); bool flag = true; foreach (char c in text) { if (c != '\r') { if (c == '\n') { this.AddRun(stringBuilder, !flag, style); stringBuilder = new StringBuilder(); flag = false; } else if (c < ' ') { stringBuilder.Append(' '); } else { stringBuilder.Append(WordOpenXmlUtils.EscapeChar(c)); } } } this.AddRun(stringBuilder, !flag, style); } }
private static string Escape(string instruction) { StringBuilder stringBuilder = new StringBuilder(instruction.Length); foreach (char c in instruction) { if (c < ' ') { stringBuilder.Append(' '); } else { stringBuilder.Append(WordOpenXmlUtils.EscapeChar(c)); } } return(stringBuilder.ToString()); }
private static StringBuilder EscapeBookmarkText(string text) { StringBuilder stringBuilder = new StringBuilder(text.Length); for (int i = 0; i < text.Length; i++) { switch (text[i]) { case '\r': if (i < text.Length - 1 && text[i + 1] == '\n') { stringBuilder.Append('_'); i++; } else { stringBuilder.Append('_'); } break; case '\u0001': case '\u0002': case '\u0003': case '\u0004': case '\u0005': case '\u0006': case '\a': case '\b': case '\t': case '\n': case '\v': case '\f': case '\u000e': case '\u000f': case '\u0010': case '\u0011': case '\u0012': case '\u0013': case '\u0014': case '\u0015': case '\u0016': case '\u0017': case '\u0018': case '\u0019': case '\u001a': case '\u001b': case '\u001c': case '\u001d': case '\u001e': case '\u001f': case ' ': stringBuilder.Append('_'); break; default: stringBuilder.Append(WordOpenXmlUtils.EscapeChar(text[i])); break; } } return(stringBuilder); }